// SPDX-License-Identifier: GPL-3.0-only use smithay::reexports::wayland_server::{Global, Interface, Resource}; use std::{ convert::{AsRef, From}, sync::{ atomic::{AtomicBool, Ordering}, Arc, }, }; pub struct GlobalDrop> + From>>(Option>); impl> + From>> From> for GlobalDrop { fn from(g: Global) -> GlobalDrop { GlobalDrop(Some(g)) } } impl> + From>> Drop for GlobalDrop { fn drop(&mut self) { if let Some(global) = self.0.take() { global.destroy(); } } } // This hack will hopefully will be superseeded by a better solution, when smithay transitions to wayland-rs 0.30. // But until then there is not really a better way to schedule a repaint on surface destruction #[derive(Debug)] pub struct SurfaceDropNotifier(Arc); impl From<&crate::state::Common> for SurfaceDropNotifier { fn from(state: &crate::state::Common) -> Self { SurfaceDropNotifier(state.dirty_flag.clone()) } } impl Drop for SurfaceDropNotifier { fn drop(&mut self) { self.0.store(true, Ordering::SeqCst); } }