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)