From a97309690e8e93fe88855287a09cb275e5e6825d Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sat, 11 Nov 2023 20:35:30 +0400 Subject: [PATCH] On Wayland, fix wl_surface being dropped first The surface was automatically dropped due to new RAII type in SCTK when dropping the Window, which was not the case at some point with SCTK. Thus destroying objects associated with it where causing issues with some window managers. Links: https://github.com/neovide/neovide/issues/2109 --- CHANGELOG.md | 1 + .../linux/wayland/window/state.rs | 21 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c8775bbf..541d954efe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Unreleased` header. - On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread. - On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account. - On macOS, send a `Resized` event after each `ScaleFactorChanged` event. +- On Wayland, fix `wl_surface` being destroyed before associated objects. # 0.29.3 diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index f9f3187efe..0b04ce932e 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -1,6 +1,5 @@ //! The state of the window, which is shared with the event-loop. -use std::mem::ManuallyDrop; use std::num::NonZeroU32; use std::sync::{Arc, Weak}; use std::time::Duration; @@ -55,9 +54,6 @@ pub struct WindowState { /// The connection to Wayland server. pub connection: Connection, - /// The underlying SCTK window. - pub window: ManuallyDrop, - /// The window frame, which is created from the configure request. frame: Option, @@ -149,6 +145,9 @@ pub struct WindowState { /// /// The value is the serial of the event triggered moved. has_pending_move: Option, + + /// The underlying SCTK window. + pub window: Window, } impl WindowState { @@ -206,7 +205,7 @@ impl WindowState { title: String::default(), transparent: false, viewport, - window: ManuallyDrop::new(window), + window, } } @@ -271,7 +270,7 @@ impl WindowState { && !self.csd_fails { match WinitFrame::new( - &*self.window, + &self.window, shm, subcompositor.clone(), self.queue_handle.clone(), @@ -1026,13 +1025,6 @@ impl WindowState { impl Drop for WindowState { fn drop(&mut self) { - let surface = self.window.wl_surface().clone(); - unsafe { - ManuallyDrop::drop(&mut self.window); - } - - // Cleanup objects. - if let Some(blur) = self.blur.take() { blur.release(); } @@ -1045,7 +1037,8 @@ impl Drop for WindowState { viewport.destroy(); } - surface.destroy(); + // NOTE: the wl_surface used by the window is being cleaned up when + // dropping SCTK `Window`. } }