surface: Introduce WeakCosmicSurface

This commit is contained in:
Victoria Brekenfeld 2026-03-19 13:41:35 +01:00 committed by Victoria Brekenfeld
parent 9ad5c916f3
commit 615789cb14

View file

@ -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<ToplevelSurface> for CosmicSurface {
fn from(s: ToplevelSurface) -> Self {
CosmicSurface(Window::new_wayland_window(s))
@ -103,6 +106,12 @@ impl PartialEq<X11Surface> for CosmicSurface {
}
}
impl PartialEq<WeakCosmicSurface> 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<CosmicSurface> {
self.0.upgrade().map(CosmicSurface)
}
}
impl IsAlive for CosmicSurface {