Skip to content

Commit

Permalink
bug fix: make sure wprsc destroys subsurfaces before surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed Jan 16, 2025
1 parent 1c8e955 commit 879b4d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ pub enum Role {
impl WaylandSurface for RemoteSurface {
fn wl_surface(&self) -> &WlSurface {
match &self.role {
None | Some(Role::Cursor(_) | Role::SubSurface(_)) => {
self.local_surface.as_ref().unwrap().wl_surface()
None | Some(Role::Cursor(_)) => self.local_surface.as_ref().unwrap().wl_surface(),
Some(Role::SubSurface(remote_subsurface)) => {
remote_subsurface.local_surface.wl_surface()
},
Some(Role::XdgToplevel(remote_xdg_toplevel)) => {
remote_xdg_toplevel.local_window.wl_surface()
Expand Down
41 changes: 25 additions & 16 deletions src/client/subsurface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::collections::HashMap;

use smithay_client_toolkit::compositor::CompositorState;
use smithay_client_toolkit::compositor::Surface;
use smithay_client_toolkit::reexports::client::protocol::wl_subcompositor::WlSubcompositor;
use smithay_client_toolkit::reexports::client::protocol::wl_subsurface::WlSubsurface;
use smithay_client_toolkit::reexports::client::protocol::wl_surface::WlSurface;
Expand Down Expand Up @@ -187,6 +188,14 @@ pub struct RemoteSubSurface {
pub(crate) parent: WlSurfaceId,
pub(crate) sync: bool,
local_subsurface: WlSubsurface,
pub(crate) local_surface: Surface,
}

impl Drop for RemoteSubSurface {
fn drop(&mut self) {
// subsurface needs to be destroyed before local_surface is dropped
self.local_subsurface.destroy();
}
}

impl RemoteSubSurface {
Expand Down Expand Up @@ -237,23 +246,23 @@ impl RemoteSubSurface {
return Ok(());
}

let local_subsurface = subcompositor.get_subsurface(
surface
.local_surface
.as_ref()
.location(loc!())?
.wl_surface(),
&parent,
qh,
SubSurfaceData,
);
if let Some(local_surface) = surface.local_surface.take() {
let local_subsurface = subcompositor.get_subsurface(
local_surface.wl_surface(),
&parent,
qh,
SubSurfaceData,
);

let remote_subsurface = Self {
parent: parent_id,
sync: true,
local_subsurface,
local_surface,
};
surface.role = Some(Role::SubSurface(remote_subsurface));
}

let remote_subsurface = Self {
parent: parent_id,
sync: true,
local_subsurface,
};
surface.role = Some(Role::SubSurface(remote_subsurface));
Ok(())
}

Expand Down

0 comments on commit 879b4d7

Please sign in to comment.