On Wayland, drop wl_surface on window close

This commit is contained in:
Kirill Chibisov 2022-07-09 21:41:18 +03:00 committed by GitHub
parent 78f1d1df38
commit 2d2ce70edc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<WinitFrame>,
pub window: ManuallyDrop<Window<WinitFrame>>,
/// The current size of the window.
pub size: Arc<Mutex<LogicalSize<u32>>>,
@ -206,7 +207,7 @@ impl WindowHandle {
let compositor = env.get_global::<WlCompositor>().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();
}
}
}