diff --git a/src/platform_impl/linux/wayland/window/shim.rs b/src/platform_impl/linux/wayland/window/shim.rs index 08e2a316..13ff2dcd 100644 --- a/src/platform_impl/linux/wayland/window/shim.rs +++ b/src/platform_impl/linux/wayland/window/shim.rs @@ -1,4 +1,5 @@ use std::cell::Cell; +use std::mem::ManuallyDrop; use std::sync::{Arc, Mutex}; use sctk::reexports::client::protocol::wl_compositor::WlCompositor; @@ -154,7 +155,7 @@ impl WindowUpdate { /// and react to events. pub struct WindowHandle { /// An actual window. - pub window: Window, + pub window: ManuallyDrop>, /// The current size of the window. pub size: Arc>>, @@ -206,7 +207,7 @@ impl WindowHandle { let compositor = env.get_global::().unwrap(); Self { - window, + window: ManuallyDrop::new(window), size, pending_window_requests, cursor_icon: Cell::new(CursorIcon::Default), @@ -563,3 +564,14 @@ pub fn handle_window_requests(winit_state: &mut WinitState) { let _ = window_updates.remove(&window); } } + +impl Drop for WindowHandle { + fn drop(&mut self) { + unsafe { + let surface = self.window.surface().clone(); + // The window must be destroyed before wl_surface. + ManuallyDrop::drop(&mut self.window); + surface.destroy(); + } + } +}