Skip to content

Commit a973096

Browse files
committed
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: neovide/neovide#2109
1 parent dec45ce commit a973096

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Unreleased` header.
1515
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
1616
- On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account.
1717
- On macOS, send a `Resized` event after each `ScaleFactorChanged` event.
18+
- On Wayland, fix `wl_surface` being destroyed before associated objects.
1819

1920
# 0.29.3
2021

src/platform_impl/linux/wayland/window/state.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! The state of the window, which is shared with the event-loop.
22
3-
use std::mem::ManuallyDrop;
43
use std::num::NonZeroU32;
54
use std::sync::{Arc, Weak};
65
use std::time::Duration;
@@ -55,9 +54,6 @@ pub struct WindowState {
5554
/// The connection to Wayland server.
5655
pub connection: Connection,
5756

58-
/// The underlying SCTK window.
59-
pub window: ManuallyDrop<Window>,
60-
6157
/// The window frame, which is created from the configure request.
6258
frame: Option<WinitFrame>,
6359

@@ -149,6 +145,9 @@ pub struct WindowState {
149145
///
150146
/// The value is the serial of the event triggered moved.
151147
has_pending_move: Option<u32>,
148+
149+
/// The underlying SCTK window.
150+
pub window: Window,
152151
}
153152

154153
impl WindowState {
@@ -206,7 +205,7 @@ impl WindowState {
206205
title: String::default(),
207206
transparent: false,
208207
viewport,
209-
window: ManuallyDrop::new(window),
208+
window,
210209
}
211210
}
212211

@@ -271,7 +270,7 @@ impl WindowState {
271270
&& !self.csd_fails
272271
{
273272
match WinitFrame::new(
274-
&*self.window,
273+
&self.window,
275274
shm,
276275
subcompositor.clone(),
277276
self.queue_handle.clone(),
@@ -1026,13 +1025,6 @@ impl WindowState {
10261025

10271026
impl Drop for WindowState {
10281027
fn drop(&mut self) {
1029-
let surface = self.window.wl_surface().clone();
1030-
unsafe {
1031-
ManuallyDrop::drop(&mut self.window);
1032-
}
1033-
1034-
// Cleanup objects.
1035-
10361028
if let Some(blur) = self.blur.take() {
10371029
blur.release();
10381030
}
@@ -1045,7 +1037,8 @@ impl Drop for WindowState {
10451037
viewport.destroy();
10461038
}
10471039

1048-
surface.destroy();
1040+
// NOTE: the wl_surface used by the window is being cleaned up when
1041+
// dropping SCTK `Window`.
10491042
}
10501043
}
10511044

0 commit comments

Comments
 (0)