fix: ensure X window focus on unmap/map

This commit is contained in:
RipleyTom 2026-07-23 19:28:32 +02:00 • committed by Victoria Brekenfeld
parent 44de3063ee
commit 5ce21fb4f3
3 changed files with 25 additions and 2 deletions

View file

@ -212,6 +212,29 @@ impl Shell {
state.common.shell.write().update_active();
}
// We suppress Element(X) to Fullscreen(X) transition to avoid
// loss of focus by the X window when having a transition to fullscreen
// but in the case of X11 unmap/map the leave/enter needs to happen for the X11
// internal state to be focused on the window
pub fn set_focus_on_x11_map(
state: &mut State,
target: &KeyboardFocusTarget,
seat: &Seat<State>,
update_cursor: bool,
) {
let need_reset = seat
.get_keyboard()
.and_then(|keyboard| keyboard.current_focus())
.and_then(|current| current.x11_surface())
.is_some_and(|current| Some(current) == target.x11_surface());
if need_reset {
update_focus_state(seat, None, state, None, false);
}
Shell::set_focus(state, Some(target), seat, None, update_cursor);
}
pub fn append_focus_stack(&mut self, target: impl Into<FocusTarget>, seat: &Seat<State>) {
let target = target.into();
if target.is_minimized() {

View file

@ -326,7 +326,7 @@ impl KeyboardFocusTarget {
}
}
fn x11_surface(&self) -> Option<X11Surface> {
pub fn x11_surface(&self) -> Option<X11Surface> {
match self {
KeyboardFocusTarget::Element(mapped) => mapped.active_window().x11_surface().cloned(),
KeyboardFocusTarget::Fullscreen(surface) => surface.x11_surface().cloned(),

View file

@ -858,7 +858,7 @@ impl XwmHandler for State {
if let Some(target) = res {
let seat = shell.seats.last_active().clone();
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), &seat, None, false);
Shell::set_focus_on_x11_map(self, &target, &seat, false);
}
}
}