diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index 570dd946..b8b7cf94 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -22,7 +22,7 @@ use smithay::{ }, }, desktop::{ - PopupManager, Window, WindowSurface, WindowSurfaceType, space::SpaceElement, + PopupManager, WeakWindow, Window, WindowSurface, WindowSurfaceType, space::SpaceElement, utils::OutputPresentationFeedback, }, input::{ @@ -67,6 +67,9 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Hash, Eq)] pub struct CosmicSurface(pub Window); +#[derive(Debug, Clone)] +pub struct WeakCosmicSurface(pub WeakWindow); + impl From for CosmicSurface { fn from(s: ToplevelSurface) -> Self { CosmicSurface(Window::new_wayland_window(s)) @@ -103,6 +106,12 @@ impl PartialEq for CosmicSurface { } } +impl PartialEq for CosmicSurface { + fn eq(&self, other: &WeakCosmicSurface) -> bool { + other.upgrade().is_some_and(|other| other == *self) + } +} + #[derive(Default)] struct Minimized(AtomicBool); @@ -849,6 +858,16 @@ impl CosmicSurface { pub fn x11_surface(&self) -> Option<&X11Surface> { self.0.x11_surface() } + + pub fn downgrade(&self) -> WeakCosmicSurface { + WeakCosmicSurface(self.0.downgrade()) + } +} + +impl WeakCosmicSurface { + pub fn upgrade(&self) -> Option { + self.0.upgrade().map(CosmicSurface) + } } impl IsAlive for CosmicSurface {