1
1
use crate :: shell:: focus:: target:: KeyboardFocusTarget ;
2
+ use crate :: shell:: WorkspaceDelta ;
2
3
use crate :: { shell:: ActivationKey , state:: ClientState , utils:: prelude:: * } ;
3
4
use crate :: {
4
5
state:: State ,
@@ -12,7 +13,7 @@ use smithay::{
12
13
XdgActivationHandler , XdgActivationState , XdgActivationToken , XdgActivationTokenData ,
13
14
} ,
14
15
} ;
15
- use tracing:: debug;
16
+ use tracing:: { debug, warn } ;
16
17
17
18
#[ derive( Debug , Clone , Copy ) ]
18
19
pub enum ActivationContext {
@@ -123,21 +124,39 @@ impl XdgActivationHandler for State {
123
124
shell. unminimize_request ( & surface, & seat, & self . common . event_loop_handle ) ;
124
125
}
125
126
126
- let element_workspace = shell. space_for ( & element) . map ( |w| w. handle . clone ( ) ) ;
127
- let current_workspace = shell. active_space_mut ( & current_output) . unwrap ( ) ;
128
-
129
- let in_current_workspace = element_workspace
130
- . as_ref ( )
131
- . map ( |w| * w == current_workspace. handle )
132
- . unwrap_or ( false ) ;
127
+ let Some ( ( element_output, element_workspace) ) = shell
128
+ . space_for ( & element)
129
+ . map ( |w| ( w. output . clone ( ) , w. handle . clone ( ) ) )
130
+ else {
131
+ return ;
132
+ } ;
133
+ let in_current_workspace =
134
+ element_workspace == shell. active_space ( & current_output) . unwrap ( ) . handle ;
135
+
136
+ if !in_current_workspace {
137
+ let Some ( idx) = shell
138
+ . workspaces
139
+ . idx_for_handle ( & element_output, & element_workspace)
140
+ else {
141
+ warn ! ( "Couldn't determine idx for elements workspace?" ) ;
142
+ return ;
143
+ } ;
133
144
134
- if in_current_workspace {
135
- current_workspace
136
- . floating_layer
137
- . space
138
- . raise_element ( & element, true ) ;
145
+ if let Err ( err) = shell. activate (
146
+ & element_output,
147
+ idx,
148
+ WorkspaceDelta :: new_shortcut ( ) ,
149
+ & mut self . common . workspace_state . update ( ) ,
150
+ ) {
151
+ warn ! ( "Failed to activate the workspace: {err:?}" ) ;
152
+ }
139
153
}
140
154
155
+ let current_workspace = shell. active_space_mut ( & current_output) . unwrap ( ) ;
156
+ current_workspace
157
+ . floating_layer
158
+ . space
159
+ . raise_element ( & element, true ) ;
141
160
if element. is_stack ( ) {
142
161
if let Some ( ( window, _) ) = element. windows ( ) . find ( |( window, _) | {
143
162
let mut found = false ;
@@ -149,38 +168,34 @@ impl XdgActivationHandler for State {
149
168
found
150
169
} ) {
151
170
element. set_active ( & window) ;
171
+ } else {
172
+ warn ! ( "Failed to find activated window in the stack" ) ;
173
+ return ;
152
174
}
153
175
}
154
176
155
- if in_current_workspace {
156
- if seat. get_keyboard ( ) . unwrap ( ) . current_focus ( )
157
- != Some ( element. clone ( ) . into ( ) )
158
- && current_workspace. is_tiled ( & surface)
177
+ if seat. get_keyboard ( ) . unwrap ( ) . current_focus ( ) != Some ( element. clone ( ) . into ( ) )
178
+ && current_workspace. is_tiled ( & surface)
179
+ {
180
+ for mapped in current_workspace
181
+ . mapped ( )
182
+ . filter ( |m| m. maximized_state . lock ( ) . unwrap ( ) . is_some ( ) )
183
+ . cloned ( )
184
+ . collect :: < Vec < _ > > ( )
185
+ . into_iter ( )
159
186
{
160
- for mapped in current_workspace
161
- . mapped ( )
162
- . filter ( |m| m. maximized_state . lock ( ) . unwrap ( ) . is_some ( ) )
163
- . cloned ( )
164
- . collect :: < Vec < _ > > ( )
165
- . into_iter ( )
166
- {
167
- current_workspace. unmaximize_request ( & mapped) ;
168
- }
187
+ current_workspace. unmaximize_request ( & mapped) ;
169
188
}
170
-
171
- std:: mem:: drop ( shell) ;
172
- Shell :: set_focus (
173
- self ,
174
- Some ( & KeyboardFocusTarget :: Element ( element. clone ( ) ) ) ,
175
- & seat,
176
- None ,
177
- false ,
178
- ) ;
179
- } else if let Some ( w) = element_workspace {
180
- shell. append_focus_stack ( element, & seat) ;
181
- let mut workspace_guard = self . common . workspace_state . update ( ) ;
182
- workspace_guard. add_workspace_state ( & w, WState :: Urgent ) ;
183
189
}
190
+
191
+ std:: mem:: drop ( shell) ;
192
+ Shell :: set_focus (
193
+ self ,
194
+ Some ( & KeyboardFocusTarget :: Element ( element. clone ( ) ) ) ,
195
+ & seat,
196
+ None ,
197
+ false ,
198
+ ) ;
184
199
} else if let Some ( ( workspace, _) ) = shell. workspace_for_surface ( & surface) {
185
200
let current_workspace = shell. active_space ( & current_output) . unwrap ( ) ;
186
201
if workspace == current_workspace. handle {
0 commit comments