diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index de0af99e..312d9eba 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -178,6 +178,15 @@ impl State { // little annoying. self.niri.layer_shell_on_demand_focus = Some(layer.clone()); } + + // If a mapped surface switches from on-demand to none, drop its focus immediately, + // because otherwise when a surface switches back and forth in a single event loop + // cycle, the focus will never get dropped. + let none = layer.cached_state().keyboard_interactivity + == wlr_layer::KeyboardInteractivity::None; + if none && self.niri.layer_shell_on_demand_focus.as_ref() == Some(layer) { + self.niri.layer_shell_on_demand_focus = None; + } } else { // The surface is unmapped. if self.niri.mapped_layer_surfaces.remove(layer).is_some() { diff --git a/src/tests/layer_shell.rs b/src/tests/layer_shell.rs index 5c1f3472..7ee7aec8 100644 --- a/src/tests/layer_shell.rs +++ b/src/tests/layer_shell.rs @@ -331,7 +331,7 @@ fn keyboard_interactivity_on_demand_to_none_then_on_demand() { layer.commit(); f.double_roundtrip(id); - assert_snapshot!(f.client(id).state.format_recent_keyboard_events(&surface), @""); + assert_snapshot!(f.client(id).state.format_recent_keyboard_events(&surface), @"leave"); } #[test]