@@ -36,7 +36,7 @@ use cosmic::widget::space::{horizontal as horizontal_space, vertical as vertical
3636use cosmic:: widget:: text_input:: { self , StyleSheet as TextInputStyleSheet } ;
3737use cosmic:: widget:: { autosize, button, divider, icon, id_container, mouse_area, scrollable, text} ;
3838use cosmic:: { Element , keyboard_nav, surface} ;
39- use iced:: keyboard:: Key ;
39+ use iced:: keyboard:: { Key , Modifiers } ;
4040use iced:: { Alignment , Color } ;
4141use pop_launcher:: { ContextOption , GpuPreference , IconSource , SearchResult } ;
4242use serde:: { Deserialize , Serialize } ;
@@ -151,6 +151,7 @@ pub struct CosmicLauncher {
151151 focused : usize ,
152152 last_hide : Instant ,
153153 alt_tab : bool ,
154+ alt_tab_released : bool ,
154155 window_id : window:: Id ,
155156 queue : VecDeque < Message > ,
156157 result_ids : Vec < Id > ,
@@ -175,7 +176,7 @@ pub enum Message {
175176 CursorMoved ( Point < f32 > ) ,
176177 Hide ,
177178 LauncherEvent ( launcher:: Event ) ,
178- Layer ( LayerEvent ) ,
179+ Layer ( LayerEvent , window :: Id ) ,
179180 KeyboardNav ( keyboard_nav:: Action ) ,
180181 ActivationToken ( Option < String > , String , String , GpuPreference , bool ) ,
181182 AltTab ,
@@ -221,6 +222,7 @@ impl CosmicLauncher {
221222 self . input_value . clear ( ) ;
222223 self . focused = 0 ;
223224 self . alt_tab = false ;
225+ self . alt_tab_released = false ;
224226 self . queue . clear ( ) ;
225227 self . hand_over . clear ( ) ;
226228
@@ -273,6 +275,10 @@ impl CosmicLauncher {
273275 }
274276}
275277
278+ fn alt_tab_modifier_is_released ( modifiers : Modifiers ) -> bool {
279+ !modifiers. alt ( ) && !modifiers. logo ( )
280+ }
281+
276282async fn launch (
277283 token : Option < String > ,
278284 app_id : String ,
@@ -330,6 +336,7 @@ impl cosmic::Application for CosmicLauncher {
330336 focused : 0 ,
331337 last_hide : Instant :: now ( ) ,
332338 alt_tab : false ,
339+ alt_tab_released : false ,
333340 window_id : SurfaceId :: unique ( ) ,
334341 queue : VecDeque :: new ( ) ,
335342 result_ids : ( 0 ..10 )
@@ -398,8 +405,12 @@ impl cosmic::Application for CosmicLauncher {
398405 }
399406 }
400407 Message :: Activate ( i) => {
408+ let alt_tab = self . alt_tab ;
401409 if let Some ( item) = self . launcher_items . get ( i. unwrap_or ( self . focused ) ) {
402410 self . request ( launcher:: Request :: Activate ( item. id ) ) ;
411+ if alt_tab {
412+ return self . hide ( ) ;
413+ }
403414 } else {
404415 return self . hide ( ) ;
405416 }
@@ -588,7 +599,9 @@ impl cosmic::Application for CosmicLauncher {
588599 cmds. push ( updated) ;
589600 }
590601
591- if self . surface_state == SurfaceState :: WaitingToBeShown {
602+ if self . alt_tab_released {
603+ cmds. push ( self . update ( Message :: Activate ( None ) ) ) ;
604+ } else if self . surface_state == SurfaceState :: WaitingToBeShown {
592605 cmds. push ( self . show ( ) ) ;
593606 }
594607 return Task :: batch ( cmds) ;
@@ -599,7 +612,8 @@ impl cosmic::Application for CosmicLauncher {
599612 }
600613 } ,
601614 } ,
602- Message :: Layer ( e) => match e {
615+ Message :: Layer ( _, id) if id != self . window_id => { }
616+ Message :: Layer ( e, _) => match e {
603617 LayerEvent :: Focused | LayerEvent :: Done => { }
604618 LayerEvent :: Unfocused => {
605619 self . last_hide = Instant :: now ( ) ;
@@ -711,7 +725,15 @@ impl cosmic::Application for CosmicLauncher {
711725 }
712726 Message :: AltRelease => {
713727 if self . alt_tab {
714- return self . update ( Message :: Activate ( None ) ) ;
728+ if self . surface_state == SurfaceState :: Visible {
729+ debug ! ( "alt-tab modifier released; activating focused item" ) ;
730+ return self . update ( Message :: Activate ( None ) ) ;
731+ }
732+
733+ debug ! (
734+ "alt-tab modifier released before launcher was visible; deferring activation"
735+ ) ;
736+ self . alt_tab_released = true ;
715737 }
716738 }
717739 Message :: Surface ( a) => {
@@ -754,19 +776,33 @@ impl cosmic::Application for CosmicLauncher {
754776 match cmd {
755777 LauncherTasks :: AltTab => {
756778 if self . alt_tab {
779+ if self . surface_state == SurfaceState :: WaitingToBeShown
780+ || self . launcher_items . is_empty ( )
781+ {
782+ self . queue . push_back ( Message :: AltTab ) ;
783+ return Task :: none ( ) ;
784+ }
757785 return self . update ( Message :: AltTab ) ;
758786 }
759787
760788 self . alt_tab = true ;
789+ self . alt_tab_released = false ;
761790 self . request ( launcher:: Request :: Search ( String :: new ( ) ) ) ;
762791 self . queue . push_back ( Message :: AltTab ) ;
763792 }
764793 LauncherTasks :: ShiftAltTab => {
765794 if self . alt_tab {
795+ if self . surface_state == SurfaceState :: WaitingToBeShown
796+ || self . launcher_items . is_empty ( )
797+ {
798+ self . queue . push_back ( Message :: ShiftAltTab ) ;
799+ return Task :: none ( ) ;
800+ }
766801 return self . update ( Message :: ShiftAltTab ) ;
767802 }
768803
769804 self . alt_tab = true ;
805+ self . alt_tab_released = false ;
770806 self . request ( launcher:: Request :: Search ( String :: new ( ) ) ) ;
771807 self . queue . push_back ( Message :: ShiftAltTab ) ;
772808 }
@@ -1098,15 +1134,22 @@ impl cosmic::Application for CosmicLauncher {
10981134 launcher:: subscription( 0 ) . map( Message :: LauncherEvent ) ,
10991135 listen_raw( |e, status, id| match e {
11001136 cosmic:: iced:: Event :: PlatformSpecific ( PlatformSpecific :: Wayland (
1101- wayland:: Event :: Layer ( e, .. ) ,
1102- ) ) => Some ( Message :: Layer ( e) ) ,
1137+ wayland:: Event :: Layer ( e, _ , layer_id ) ,
1138+ ) ) => Some ( Message :: Layer ( e, layer_id ) ) ,
11031139 cosmic:: iced:: Event :: PlatformSpecific ( PlatformSpecific :: Wayland (
11041140 wayland:: Event :: OverlapNotify ( event, ..) ,
11051141 ) ) => Some ( Message :: Overlap ( event) ) ,
11061142 cosmic:: iced:: Event :: Keyboard ( iced:: keyboard:: Event :: KeyReleased {
11071143 key: Key :: Named ( Named :: Alt | Named :: Super ) ,
11081144 ..
11091145 } ) => Some ( Message :: AltRelease ) ,
1146+ cosmic:: iced:: Event :: Keyboard ( iced:: keyboard:: Event :: KeyReleased {
1147+ modifiers,
1148+ ..
1149+ } ) if alt_tab_modifier_is_released( modifiers) => Some ( Message :: AltRelease ) ,
1150+ cosmic:: iced:: Event :: Keyboard ( iced:: keyboard:: Event :: ModifiersChanged (
1151+ modifiers,
1152+ ) ) if alt_tab_modifier_is_released( modifiers) => Some ( Message :: AltRelease ) ,
11101153 cosmic:: iced:: Event :: Keyboard ( iced:: keyboard:: Event :: KeyPressed {
11111154 key,
11121155 text: _,
0 commit comments