From 102c20d2b40973bcebd7347c184d4711289df981 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:29:22 +0000 Subject: [PATCH] fix(shells): release the rendering context and window before the display goes away The software rendering path (softbuffer) and the EGL path keep their own Wayland objects on winit's display, so dropping the rendering context after the event loop could destroy proxies on a disconnected display just like the shell client did. Both hosts now release the rendering context and the window in winit's exiting handler as well. The compositor records the keys whose press a shortcut took and takes only those releases, so no client sees a release without its press or keeps a key pressed. check_activation.py watches the panel for six seconds after Alt+F4 instead of sampling it once. --- crates/weft-app-shell/src/embedder.rs | 11 ++++++++--- crates/weft-compositor/src/input.rs | 22 +++++++++++++++------- crates/weft-compositor/src/state.rs | 4 ++++ crates/weft-servo-shell/src/embedder.rs | 11 ++++++++--- tests/frame/check_activation.py | 8 +++++--- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/crates/weft-app-shell/src/embedder.rs b/crates/weft-app-shell/src/embedder.rs index 1cffa8d..74e72ab 100644 --- a/crates/weft-app-shell/src/embedder.rs +++ b/crates/weft-app-shell/src/embedder.rs @@ -431,12 +431,17 @@ impl App { } impl ApplicationHandler for App { - /// Releases Servo and the shell protocol objects while winit's Wayland - /// display is still connected; dropped later, the shell client's - /// proxies would be destroyed on a display that is gone. + /// Releases everything that holds Wayland objects of winit's display + /// (Servo, the rendering context, whose software and EGL paths keep + /// their own proxies on it, the shell protocol client and the window) + /// while that display is still connected; dropped after the event loop, + /// they would be destroyed on a display that is gone. A panic unwinding + /// out of a handler skips this. fn exiting(&mut self, _event_loop: &ActiveEventLoop) { self.shut_down(); + self.rendering_context = None; self.shell_client = None; + self.window = None; } fn resumed(&mut self, event_loop: &ActiveEventLoop) { diff --git a/crates/weft-compositor/src/input.rs b/crates/weft-compositor/src/input.rs index bf64e6d..e5e1721 100644 --- a/crates/weft-compositor/src/input.rs +++ b/crates/weft-compositor/src/input.rs @@ -56,14 +56,22 @@ fn handle_keyboard(state: &mut WeftCompositorState, event: B::K key_state, serial, time, - |_state, mods, keysym| { - if mods.alt - && keysym.modified_sym() == smithay::input::keyboard::keysyms::KEY_F4.into() - { - FilterResult::Intercept(key_state == smithay::backend::input::KeyState::Pressed) - } else { - FilterResult::Forward + |state, mods, keysym| { + // A release is taken only when its press was, so no client + // sees half of a key. + let code = keysym.raw_code().raw(); + if key_state == smithay::backend::input::KeyState::Pressed { + if mods.alt + && keysym.modified_sym() == smithay::input::keyboard::keysyms::KEY_F4.into() + { + state.suppressed_keys.push(code); + return FilterResult::Intercept(true); + } + } else if let Some(i) = state.suppressed_keys.iter().position(|&k| k == code) { + state.suppressed_keys.remove(i); + return FilterResult::Intercept(false); } + FilterResult::Forward }, ); if close == Some(true) { diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index cdd8445..79b701c 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -98,6 +98,9 @@ pub struct WeftCompositorState { pub loop_signal: LoopSignal, pub loop_handle: LoopHandle<'static, WeftCompositorState>, pub gesture_state: GestureState, + /// Keycodes whose press a compositor shortcut took, so their release is + /// taken as well and no client sees half of a key. + pub suppressed_keys: Vec, pub compositor_state: CompositorState, pub xdg_shell_state: XdgShellState, @@ -196,6 +199,7 @@ impl WeftCompositorState { dmabuf_global: None, running: true, gesture_state: GestureState::default(), + suppressed_keys: Vec::new(), #[cfg(unix)] appd_ipc: None, #[cfg(target_os = "linux")] diff --git a/crates/weft-servo-shell/src/embedder.rs b/crates/weft-servo-shell/src/embedder.rs index 1c22d03..ffc5ab1 100644 --- a/crates/weft-servo-shell/src/embedder.rs +++ b/crates/weft-servo-shell/src/embedder.rs @@ -346,12 +346,17 @@ impl App { } impl ApplicationHandler for App { - /// Releases Servo and the shell protocol objects while winit's Wayland - /// display is still connected; dropped later, the shell client's - /// proxies would be destroyed on a display that is gone. + /// Releases everything that holds Wayland objects of winit's display + /// (Servo, the rendering context, whose software and EGL paths keep + /// their own proxies on it, the shell protocol client and the window) + /// while that display is still connected; dropped after the event loop, + /// they would be destroyed on a display that is gone. A panic unwinding + /// out of a handler skips this. fn exiting(&mut self, _event_loop: &ActiveEventLoop) { self.shut_down(); + self.rendering_context = None; self.shell_client = None; + self.window = None; } fn resumed(&mut self, event_loop: &ActiveEventLoop) { diff --git a/tests/frame/check_activation.py b/tests/frame/check_activation.py index f1ba160..f011aba 100755 --- a/tests/frame/check_activation.py +++ b/tests/frame/check_activation.py @@ -230,9 +230,11 @@ def run(args, desktop, store, home): raise AssertionError("the closed application is still shown") time.sleep(0.3) key("alt+F4") - time.sleep(2) - if area(desktop.capture(), GREEN)[0] != panel: - raise AssertionError("Alt+F4 closed or moved the shell's panel") + deadline = time.monotonic() + 6 + while time.monotonic() < deadline: + if area(desktop.capture(), GREEN)[0] != panel: + raise AssertionError("Alt+F4 closed or moved the shell's panel") + time.sleep(0.5) appd.send({"type": "ACTIVATE_APP", "session_id": 999}) reply = appd.wait_for(lambda m: m.get("type") == "ERROR", 10)