3
3
4
4
use cosmic:: app:: ContextDrawer ;
5
5
use cosmic:: iced:: event:: listen_with;
6
+ use cosmic:: iced:: keyboard:: key:: Named ;
6
7
use cosmic:: iced:: keyboard:: { Key , Location , Modifiers } ;
7
8
use cosmic:: iced:: { self , Alignment , Length } ;
8
9
use cosmic:: widget:: { self , button, icon, settings, text} ;
@@ -32,7 +33,7 @@ pub enum ShortcutMessage {
32
33
ProtocolUnavailable ,
33
34
ModifiersChanged ( Modifiers ) ,
34
35
KeyReleased ( u32 , Key , Location ) ,
35
- KeyPressed ( u32 , Key , Location ) ,
36
+ KeyPressed ( u32 , Key , Location , Modifiers ) ,
36
37
}
37
38
38
39
#[ derive( Debug ) ]
@@ -421,6 +422,20 @@ impl Model {
421
422
}
422
423
}
423
424
ShortcutMessage :: EditBinding ( id, enable) => {
425
+ if !enable && self . editing == Some ( id) {
426
+ self . editing = None ;
427
+ if let Some ( short_id) = self . shortcut_context {
428
+ if let Some ( model) = self . shortcut_models . get_mut ( short_id) {
429
+ if let Some ( shortcut) = model. bindings . get_mut ( id) {
430
+ shortcut. pending = shortcut. binding . clone ( ) ;
431
+ }
432
+ }
433
+ }
434
+ return Task :: batch ( vec ! [
435
+ cosmic:: widget:: text_input:: focus( self . add_keybindings_button_id. clone( ) ) ,
436
+ iced_winit:: platform_specific:: commands:: keyboard_shortcuts_inhibit:: inhibit_shortcuts( false ) . discard( )
437
+ ] ) ;
438
+ }
424
439
if let Some ( short_id) = self . shortcut_context {
425
440
if let Some ( model) = self . shortcut_models . get_mut ( short_id) {
426
441
if let Some ( shortcut) = model. bindings . get_mut ( id) {
@@ -479,7 +494,7 @@ impl Model {
479
494
480
495
return Task :: batch ( tasks) ;
481
496
}
482
- ShortcutMessage :: SubmitBinding ( id ) => { }
497
+ ShortcutMessage :: SubmitBinding ( _ ) => { }
483
498
ShortcutMessage :: ProtocolUnavailable => {
484
499
tracing:: error!( "shortcut inhibit protocol is unavailable" ) ;
485
500
}
@@ -514,6 +529,7 @@ impl Model {
514
529
iced_winit:: platform_specific:: commands:: keyboard_shortcuts_inhibit:: inhibit_shortcuts( false ) . discard( )
515
530
] ) ;
516
531
}
532
+ shortcut. input = shortcut. pending . to_string ( ) ;
517
533
}
518
534
}
519
535
}
@@ -547,7 +563,22 @@ impl Model {
547
563
}
548
564
}
549
565
}
550
- ShortcutMessage :: KeyPressed ( keycode, unmodified_keysym, location) => {
566
+ ShortcutMessage :: KeyPressed ( keycode, unmodified_keysym, location, modifiers) => {
567
+ if unmodified_keysym == Key :: Named ( Named :: Escape ) && modifiers. is_empty ( ) {
568
+ if let Some ( ( short_id, id) ) = self . shortcut_context . zip ( self . editing ) {
569
+ if let Some ( model) = self . shortcut_models . get_mut ( short_id) {
570
+ if let Some ( binding) = model. bindings . get_mut ( id) {
571
+ binding. reset ( ) ;
572
+ self . editing = None ;
573
+ return Task :: batch ( vec ! [
574
+ cosmic:: widget:: text_input:: focus( self . add_keybindings_button_id. clone( ) ) ,
575
+ iced_winit:: platform_specific:: commands:: keyboard_shortcuts_inhibit:: inhibit_shortcuts( false ) . discard( )
576
+ ] ) ;
577
+ }
578
+ }
579
+ }
580
+ return Task :: none ( ) ;
581
+ }
551
582
if let Some ( ( short_id, id) ) = self . shortcut_context . zip ( self . editing ) {
552
583
if let Some ( model) = self . shortcut_models . get_mut ( short_id) {
553
584
if let Some ( shortcut) = model. bindings . get_mut ( id) {
@@ -577,6 +608,7 @@ impl Model {
577
608
key,
578
609
physical_key,
579
610
location,
611
+ modifiers,
580
612
..
581
613
} ) => {
582
614
use cosmic:: iced:: keyboard:: { Key , key:: Named } ;
@@ -588,7 +620,7 @@ impl Model {
588
620
return None ;
589
621
}
590
622
cosmic:: iced_winit:: conversion:: physical_to_scancode ( physical_key)
591
- . map ( |code| ShortcutMessage :: KeyPressed ( code, key, location) )
623
+ . map ( |code| ShortcutMessage :: KeyPressed ( code, key, location, modifiers ) )
592
624
}
593
625
iced:: event:: Event :: Keyboard ( iced:: keyboard:: Event :: KeyReleased {
594
626
key,
0 commit comments