Skip to content

Commit 0ef372f

Browse files
committed
shell: Don't unconditionally focus on unfullscreen
1 parent a74c90f commit 0ef372f

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/wayland/handlers/toplevel_management.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,9 @@ impl ToplevelManagementHandler for State {
181181
window: &<Self as ToplevelInfoHandler>::Window,
182182
) {
183183
let mut shell = self.common.shell.write();
184-
if let Some(target) = shell.unfullscreen_request(window, &self.common.event_loop_handle) {
185-
let seat = shell.seats.last_active().clone();
186-
std::mem::drop(shell);
187-
Shell::set_focus(self, Some(&target), &seat, None, true);
188-
}
184+
let _ = shell.unfullscreen_request(window, &self.common.event_loop_handle);
185+
// don't switch focus because of a programmatic action.
186+
// If the toplevel-management client intends to focus the now unfullscreened toplevel, it can send an `activate`-request.
189187
}
190188

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

src/wayland/handlers/xdg_shell/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22

33
use crate::{
4-
shell::{grabs::ReleaseMode, CosmicSurface, PendingWindow},
4+
shell::{focus::target::KeyboardFocusTarget, grabs::ReleaseMode, CosmicSurface, PendingWindow},
55
utils::prelude::*,
66
};
77
use smithay::{
@@ -260,11 +260,24 @@ impl XdgShellHandler for State {
260260

261261
fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
262262
let mut shell = self.common.shell.write();
263+
let seat = shell.seats.last_active().clone();
264+
let should_focus = seat
265+
.get_keyboard()
266+
.unwrap()
267+
.current_focus()
268+
.is_some_and(|target| {
269+
if let KeyboardFocusTarget::Fullscreen(s) = target {
270+
s == surface
271+
} else {
272+
false
273+
}
274+
});
263275

264276
if let Some(target) = shell.unfullscreen_request(&surface, &self.common.event_loop_handle) {
265-
let seat = shell.seats.last_active().clone();
266277
std::mem::drop(shell);
267-
Shell::set_focus(self, Some(&target), &seat, None, true);
278+
if should_focus {
279+
Shell::set_focus(self, Some(&target), &seat, None, true);
280+
}
268281
} else {
269282
if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
270283
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())

src/xwayland.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,24 @@ impl XwmHandler for State {
10821082

10831083
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
10841084
let mut shell = self.common.shell.write();
1085+
let seat = shell.seats.last_active().clone();
1086+
let should_focus = seat
1087+
.get_keyboard()
1088+
.unwrap()
1089+
.current_focus()
1090+
.is_some_and(|target| {
1091+
if let KeyboardFocusTarget::Fullscreen(s) = target {
1092+
s == window
1093+
} else {
1094+
false
1095+
}
1096+
});
1097+
10851098
if let Some(target) = shell.unfullscreen_request(&window, &self.common.event_loop_handle) {
1086-
let seat = shell.seats.last_active().clone();
10871099
std::mem::drop(shell);
1088-
Shell::set_focus(self, Some(&target), &seat, None, true);
1100+
if should_focus {
1101+
Shell::set_focus(self, Some(&target), &seat, None, true);
1102+
}
10891103
} else {
10901104
if let Some(pending) = shell
10911105
.pending_windows

0 commit comments

Comments
 (0)