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.
This commit is contained in:
Marco Allegretti 2026-10-09 16:29:22 +00:00
parent 828984be4b
commit 102c20d2b4
No known key found for this signature in database
5 changed files with 40 additions and 16 deletions

View file

@ -431,12 +431,17 @@ impl App {
}
impl ApplicationHandler<ServoWake> 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) {

View file

@ -56,14 +56,22 @@ fn handle_keyboard<B: InputBackend>(state: &mut WeftCompositorState, event: B::K
key_state,
serial,
time,
|_state, mods, keysym| {
|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()
{
FilterResult::Intercept(key_state == smithay::backend::input::KeyState::Pressed)
} else {
FilterResult::Forward
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) {

View file

@ -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<u32>,
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")]

View file

@ -346,12 +346,17 @@ impl App {
}
impl ApplicationHandler<ServoWake> 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) {

View file

@ -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)
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)