From 9a28bb4b49c905afa900ff4b51c7d7636d0bd5aa Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Fri, 22 Dec 2023 19:56:52 +0400 Subject: [PATCH] On Wayland, fix WindowEvent::Destroyed delivery --- CHANGELOG.md | 1 + .../linux/wayland/event_loop/mod.rs | 56 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2220943..7e9f8ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Unreleased` header. - **Breaking:** On Web, return `RawWindowHandle::WebCanvas` instead of `RawWindowHandle::Web`. - **Breaking:** On Web, macOS and iOS, return `HandleError::Unavailable` when a window handle is not available. - **Breaking:** Bump MSRV from `1.65` to `1.70`. +- On Wayland, fix `WindowEvent::Destroyed` not being delivered after destroying window. # 0.29.5 diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index e0d6a36d..4b33cfa4 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -467,44 +467,44 @@ impl EventLoop { }); for window_id in window_ids.drain(..) { - let request_redraw = self.with_state(|state| { + let event = self.with_state(|state| { let window_requests = state.window_requests.get_mut(); if window_requests.get(&window_id).unwrap().take_closed() { mem::drop(window_requests.remove(&window_id)); mem::drop(state.windows.get_mut().remove(&window_id)); - false - } else { - let mut window = state - .windows - .get_mut() - .get_mut(&window_id) - .unwrap() - .lock() - .unwrap(); - - if window.frame_callback_state() == FrameCallbackState::Requested { - false - } else { - // Reset the frame callbacks state. - window.frame_callback_reset(); - let mut redraw_requested = window_requests - .get(&window_id) - .unwrap() - .take_redraw_requested(); - - // Redraw the frame while at it. - redraw_requested |= window.refresh_frame(); - - redraw_requested - } + return Some(WindowEvent::Destroyed); } + + let mut window = state + .windows + .get_mut() + .get_mut(&window_id) + .unwrap() + .lock() + .unwrap(); + + if window.frame_callback_state() == FrameCallbackState::Requested { + return None; + } + + // Reset the frame callbacks state. + window.frame_callback_reset(); + let mut redraw_requested = window_requests + .get(&window_id) + .unwrap() + .take_redraw_requested(); + + // Redraw the frame while at it. + redraw_requested |= window.refresh_frame(); + + redraw_requested.then_some(WindowEvent::RedrawRequested) }); - if request_redraw { + if let Some(event) = event { callback( Event::WindowEvent { window_id: crate::window::WindowId(window_id), - event: WindowEvent::RedrawRequested, + event, }, &self.window_target, );