diff --git a/src/wayland/output/handlers.rs b/src/wayland/output/handlers.rs index a02a71abf355..7cc18b0186c1 100644 --- a/src/wayland/output/handlers.rs +++ b/src/wayland/output/handlers.rs @@ -41,7 +41,7 @@ where let output = data_init.init( resource, OutputUserData { - output: global_data.output.clone(), + output: global_data.output.downgrade(), last_client_scale: AtomicU32::new(client_scale.load(Ordering::Acquire)), client_scale, }, @@ -124,13 +124,14 @@ where output: &WlOutput, data: &OutputUserData, ) { - data.output - .inner - .0 - .lock() - .unwrap() - .instances - .retain(|o| o.id() != output.id()); + if let Some(o) = data.output.upgrade() { + o.inner + .0 + .lock() + .unwrap() + .instances + .retain(|o| o.id() != output.id()); + } } } diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 3db97d059a74..fd260453a6de 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -78,7 +78,7 @@ use std::sync::{ Arc, }; -use crate::output::{Inner, Mode, Output, Scale, Subpixel}; +use crate::output::{Inner, Mode, Output, Scale, Subpixel, WeakOutput}; use tracing::info; use wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_manager_v1::ZxdgOutputManagerV1; @@ -144,7 +144,7 @@ impl OutputManagerState { /// User data for WlOutput #[derive(Debug)] pub struct OutputUserData { - pub(crate) output: Output, + pub(crate) output: WeakOutput, last_client_scale: AtomicU32, client_scale: Arc, } @@ -209,7 +209,7 @@ impl Output { /// Attempt to retrieve a [`Output`] from an existing resource pub fn from_resource(output: &WlOutput) -> Option { - output.data::().map(|ud| ud.output.clone()) + output.data::().and_then(|ud| ud.output.upgrade()) } pub(crate) fn wl_change_current_state(