Skip to content

Commit

Permalink
On Wayland, fix wl_surface being dropped first
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kchibisov authored Nov 11, 2023
1 parent eab982c commit 1414060
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 7 additions & 14 deletions src/platform_impl/linux/wayland/window/state.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -55,9 +54,6 @@ pub struct WindowState {
/// The connection to Wayland server.
pub connection: Connection,

/// The underlying SCTK window.
pub window: ManuallyDrop<Window>,

/// The window frame, which is created from the configure request.
frame: Option<WinitFrame>,

Expand Down Expand Up @@ -149,6 +145,9 @@ pub struct WindowState {
///
/// The value is the serial of the event triggered moved.
has_pending_move: Option<u32>,

/// The underlying SCTK window.
pub window: Window,
}

impl WindowState {
Expand Down Expand Up @@ -206,7 +205,7 @@ impl WindowState {
title: String::default(),
transparent: false,
viewport,
window: ManuallyDrop::new(window),
window,
}
}

Expand Down Expand Up @@ -271,7 +270,7 @@ impl WindowState {
&& !self.csd_fails
{
match WinitFrame::new(
&*self.window,
&self.window,
shm,
subcompositor.clone(),
self.queue_handle.clone(),
Expand Down Expand Up @@ -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();
}
Expand All @@ -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`.
}
}

Expand Down

0 comments on commit 1414060

Please sign in to comment.