Skip to content

Commit 9d91014

Browse files
committed
shell: Focus window after unfullscreening
1 parent 261134d commit 9d91014

File tree

6 files changed

+55
-25
lines changed

6 files changed

+55
-25
lines changed

src/input/actions.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,12 @@ impl State {
889889
}
890890
}
891891
Some(FocusTarget::Fullscreen(surface)) => {
892-
shell.unfullscreen_request(&surface, &self.common.event_loop_handle);
892+
if let Some(target) =
893+
shell.unfullscreen_request(&surface, &self.common.event_loop_handle)
894+
{
895+
std::mem::drop(shell);
896+
Shell::set_focus(self, Some(&target), seat, Some(serial), true);
897+
}
893898
}
894899
_ => {}
895900
}

src/shell/grabs/menu/default.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,16 @@ pub fn fullscreen_items(window: &CosmicSurface, config: &Config) -> impl Iterato
589589
let window = fullscreen_clone.clone();
590590
let _ = handle.insert_idle(move |state| {
591591
let mut shell = state.common.shell.write();
592-
shell.unfullscreen_request(&window, &state.common.event_loop_handle);
592+
if let Some(target) =
593+
shell.unfullscreen_request(&window, &state.common.event_loop_handle)
594+
{
595+
let seat = shell.seats.last_active().clone();
596+
std::mem::drop(shell);
597+
Shell::set_focus(state, Some(&target), &seat, None, true);
598+
}
593599
});
594600
})
595-
//.shortcut(config.shortcut_for_action(&Action::Fullscreen))
601+
.shortcut(config.shortcut_for_action(&Action::Fullscreen))
596602
.toggled(true),
597603
),
598604
Some(Item::Separator),

src/shell/mod.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ impl Shell {
24202420
surface: CosmicSurface,
24212421
state: Option<FullscreenRestoreState>,
24222422
loop_handle: &LoopHandle<'static, State>,
2423-
) {
2423+
) -> CosmicMapped {
24242424
let window = CosmicMapped::from(CosmicWindow::new(
24252425
surface,
24262426
loop_handle.clone(),
@@ -2439,12 +2439,12 @@ impl Shell {
24392439
.or_else(|| self.workspaces.backup_set.as_mut())
24402440
.unwrap();
24412441
set.sticky_layer.map_internal(
2442-
window,
2442+
window.clone(),
24432443
Some(state.geometry.loc),
24442444
Some(state.geometry.size.as_logical()),
24452445
Some(set.output.geometry().to_local(&set.output)),
24462446
);
2447-
return;
2447+
return window;
24482448
}
24492449

24502450
let seat = self.seats.last_active();
@@ -2473,14 +2473,14 @@ impl Shell {
24732473

24742474
if workspace.tiling_enabled {
24752475
workspace.tiling_layer.remap(
2476-
window,
2476+
window.clone(),
24772477
Some(fullscreen_geometry),
24782478
None,
24792479
Some(workspace.focus_stack.get(seat).iter()),
24802480
);
24812481
} else {
24822482
workspace.floating_layer.map_internal(
2483-
window,
2483+
window.clone(),
24842484
None,
24852485
None,
24862486
Some(fullscreen_geometry),
@@ -2509,9 +2509,11 @@ impl Shell {
25092509
original_layer: ManagedLayer::Floating,
25102510
});
25112511
std::mem::drop(state);
2512-
workspace
2513-
.floating_layer
2514-
.map_maximized(window, fullscreen_geometry, true);
2512+
workspace.floating_layer.map_maximized(
2513+
window.clone(),
2514+
fullscreen_geometry,
2515+
true,
2516+
);
25152517
}
25162518
}
25172519
Some(FullscreenRestoreState::Tiling {
@@ -2539,9 +2541,11 @@ impl Shell {
25392541
original_layer: ManagedLayer::Tiling,
25402542
});
25412543
std::mem::drop(state);
2542-
workspace
2543-
.floating_layer
2544-
.map_maximized(window, fullscreen_geometry, true);
2544+
workspace.floating_layer.map_maximized(
2545+
window.clone(),
2546+
fullscreen_geometry,
2547+
true,
2548+
);
25452549
}
25462550
} else {
25472551
workspace.floating_layer.map_internal(
@@ -2559,14 +2563,18 @@ impl Shell {
25592563
original_layer: ManagedLayer::Floating,
25602564
});
25612565
std::mem::drop(state);
2562-
workspace
2563-
.floating_layer
2564-
.map_maximized(window, fullscreen_geometry, true);
2566+
workspace.floating_layer.map_maximized(
2567+
window.clone(),
2568+
fullscreen_geometry,
2569+
true,
2570+
);
25652571
}
25662572
}
25672573
}
25682574
Some(FullscreenRestoreState::Sticky { .. }) => unreachable!(),
25692575
}
2576+
2577+
window
25702578
}
25712579

25722580
#[must_use]
@@ -4596,7 +4604,7 @@ impl Shell {
45964604
&mut self,
45974605
surface: &S,
45984606
loop_handle: &LoopHandle<'static, State>,
4599-
) -> bool
4607+
) -> Option<KeyboardFocusTarget>
46004608
where
46014609
CosmicSurface: PartialEq<S>,
46024610
{
@@ -4611,11 +4619,10 @@ impl Shell {
46114619
toplevel_leave_output(&old_fullscreen, &workspace.output);
46124620
toplevel_leave_workspace(&old_fullscreen, &workspace.handle);
46134621

4614-
self.remap_unfullscreened_window(old_fullscreen, restore, loop_handle);
4615-
4616-
true
4622+
let window = self.remap_unfullscreened_window(old_fullscreen, restore, loop_handle);
4623+
Some(KeyboardFocusTarget::Element(window))
46174624
} else {
4618-
false
4625+
None
46194626
}
46204627
}
46214628

src/wayland/handlers/toplevel_management.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ impl ToplevelManagementHandler for State {
184184
window: &<Self as ToplevelInfoHandler>::Window,
185185
) {
186186
let mut shell = self.common.shell.write();
187-
shell.unfullscreen_request(window, &self.common.event_loop_handle);
187+
if let Some(target) = shell.unfullscreen_request(window, &self.common.event_loop_handle) {
188+
let seat = shell.seats.last_active().clone();
189+
std::mem::drop(shell);
190+
Shell::set_focus(self, Some(&target), &seat, None, true);
191+
}
188192
}
189193

190194
fn maximize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {

src/wayland/handlers/xdg_shell/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ impl XdgShellHandler for State {
261261
fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
262262
let mut shell = self.common.shell.write();
263263

264-
if !shell.unfullscreen_request(&surface, &self.common.event_loop_handle) {
264+
if let Some(target) = shell.unfullscreen_request(&surface, &self.common.event_loop_handle) {
265+
let seat = shell.seats.last_active().clone();
266+
std::mem::drop(shell);
267+
Shell::set_focus(self, Some(&target), &seat, None, true);
268+
} else {
265269
if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
266270
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())
267271
}) {

src/xwayland.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,11 @@ impl XwmHandler for State {
10821082

10831083
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
10841084
let mut shell = self.common.shell.write();
1085-
if !shell.unfullscreen_request(&window, &self.common.event_loop_handle) {
1085+
if let Some(target) = shell.unfullscreen_request(&window, &self.common.event_loop_handle) {
1086+
let seat = shell.seats.last_active().clone();
1087+
std::mem::drop(shell);
1088+
Shell::set_focus(self, Some(&target), &seat, None, true);
1089+
} else {
10861090
if let Some(pending) = shell
10871091
.pending_windows
10881092
.iter_mut()

0 commit comments

Comments
 (0)