From 7ac204ee799224de389ed988ee96a79411adc695 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 16 Dec 2024 20:14:37 +0100 Subject: [PATCH] focus: Fix active/focused output on `refresh_focus` Previously removing the last output could have left seats with an invalid active output. We already have logic to check this in `refresh_focus` but failed to apply it before `update_pointer_focus`. Let's fix that. --- src/shell/focus/mod.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index 638ac4ec..f4a6ca17 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -344,19 +344,27 @@ impl Common { .cloned() .collect::>(); for seat in &seats { - update_pointer_focus(state, &seat); - - let mut shell = state.common.shell.write().unwrap(); - let output = seat.focused_or_active_output(); + { + let shell = state.common.shell.read().unwrap(); + let focused_output = seat.focused_output(); + let active_output = seat.active_output(); - // If the focused or active output is not in the list of outputs, switch to the first output - if !shell.outputs().any(|o| o == &output) { - if let Some(other) = shell.outputs().next() { - seat.set_active_output(other); + // If the focused or active output is not in the list of outputs, switch to the first output + if focused_output.is_some_and(|f| !shell.outputs().any(|o| &f == o)) { + seat.set_focused_output(None); + } + if !shell.outputs().any(|o| o == &active_output) { + if let Some(other) = shell.outputs().next() { + seat.set_active_output(other); + } + continue; } - continue; } + update_pointer_focus(state, &seat); + + let output = seat.focused_or_active_output(); + let mut shell = state.common.shell.write().unwrap(); let last_known_focus = ActiveFocus::get(&seat); if let Some(target) = last_known_focus {