From 505e36dcdab6fa9c750653afeba806c1446caba7 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 30 Oct 2025 14:54:32 -0700 Subject: [PATCH] Make `CosmicWindowInternal`/`CosmicStackInternal` not `Clone` `IcedElement` uses `Arc` internally (and compares with `Arc::ptr_eq`). So these structs are never cloned, and probably shouldn't be. --- src/shell/element/stack.rs | 56 ++++++++++++++++++------------------- src/shell/element/window.rs | 15 +++++----- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 6ddb3458..2d1513c5 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -64,7 +64,7 @@ use std::{ fmt, hash::Hash, sync::{ - Arc, LazyLock, Mutex, + LazyLock, Mutex, atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering}, }, }; @@ -91,21 +91,21 @@ impl fmt::Debug for CosmicStack { } } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct CosmicStackInternal { - windows: Arc>>, - active: Arc, - activated: Arc, - group_focused: Arc, - previous_index: Arc>>, - scroll_to_focus: Arc, - previous_keyboard: Arc, - pointer_entered: Arc, - reenter: Arc, - potential_drag: Arc>>, - override_alive: Arc, - geometry: Arc>>>, - mask: Arc>>, + windows: Mutex>, + active: AtomicUsize, + activated: AtomicBool, + group_focused: AtomicBool, + previous_index: Mutex>, + scroll_to_focus: AtomicBool, + previous_keyboard: AtomicUsize, + pointer_entered: AtomicU8, + reenter: AtomicBool, + potential_drag: Mutex>, + override_alive: AtomicBool, + geometry: Mutex>>, + mask: Mutex>, } impl CosmicStackInternal { @@ -146,19 +146,19 @@ impl CosmicStack { let width = windows[0].geometry().size.w; CosmicStack(IcedElement::new( CosmicStackInternal { - windows: Arc::new(Mutex::new(windows)), - active: Arc::new(AtomicUsize::new(0)), - activated: Arc::new(AtomicBool::new(false)), - group_focused: Arc::new(AtomicBool::new(false)), - previous_index: Arc::new(Mutex::new(None)), - scroll_to_focus: Arc::new(AtomicBool::new(false)), - previous_keyboard: Arc::new(AtomicUsize::new(0)), - pointer_entered: Arc::new(AtomicU8::new(0)), - reenter: Arc::new(AtomicBool::new(false)), - potential_drag: Arc::new(Mutex::new(None)), - override_alive: Arc::new(AtomicBool::new(true)), - geometry: Arc::new(Mutex::new(None)), - mask: Arc::new(Mutex::new(None)), + windows: Mutex::new(windows), + active: AtomicUsize::new(0), + activated: AtomicBool::new(false), + group_focused: AtomicBool::new(false), + previous_index: Mutex::new(None), + scroll_to_focus: AtomicBool::new(false), + previous_keyboard: AtomicUsize::new(0), + pointer_entered: AtomicU8::new(0), + reenter: AtomicBool::new(false), + potential_drag: Mutex::new(None), + override_alive: AtomicBool::new(true), + geometry: Mutex::new(None), + mask: Mutex::new(None), }, (width, TAB_HEIGHT), handle, diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 43b9c816..0dc480b2 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -50,7 +50,7 @@ use std::{ fmt, hash::Hash, sync::{ - Arc, Mutex, + Mutex, atomic::{AtomicBool, AtomicU8, Ordering}, }, }; @@ -72,13 +72,12 @@ impl fmt::Debug for CosmicWindow { } } -#[derive(Clone)] pub struct CosmicWindowInternal { pub(super) window: CosmicSurface, - activated: Arc, + activated: AtomicBool, /// TODO: This needs to be per seat - pointer_entered: Arc, - last_title: Arc>, + pointer_entered: AtomicU8, + last_title: Mutex, } impl fmt::Debug for CosmicWindowInternal { @@ -192,9 +191,9 @@ impl CosmicWindow { CosmicWindow(IcedElement::new( CosmicWindowInternal { window, - activated: Arc::new(AtomicBool::new(false)), - pointer_entered: Arc::new(AtomicU8::new(0)), - last_title: Arc::new(Mutex::new(last_title)), + activated: AtomicBool::new(false), + pointer_entered: AtomicU8::new(0), + last_title: Mutex::new(last_title), }, (width, SSD_HEIGHT), handle,