From 6fa081960536c407044835ce1d82af2ac90e95f7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:34:23 -0700 Subject: [PATCH] refactor(core): a ContainerWindow is Clone, not Copy Step 11(iii) prerequisite. The macOS Window holds retained Accessibility references and cannot be Copy, so the bound of ContainerWindow is Clone. KDE and Windows windows are still Copy; they satisfy it unchanged. The seven places in komorebi-core/src/workspace.rs that copied a window out of a borrowed Option (if let Some(window) = self.maximized_window) borrow it instead (&self.maximized_window), and two places clone where the old text used the value twice (new_maximized_window, new_maximized_window's unmaximize hook). No behaviour change on KDE or Windows: a clone of a Copy type is the copy. Verified: native cargo test -p komorebi-core, fast-check: Windows clippy --all-targets -D warnings PASS, KDE check + lib tests PASS (291 passed), macOS fake-CC type-check PASS. Not run: Windows e2e (needed only if you want a second look: no Windows window type changed). --- crates/komorebi-core/src/container.rs | 5 +++-- crates/komorebi-core/src/workspace.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/komorebi-core/src/container.rs b/crates/komorebi-core/src/container.rs index 73bba815..0b6b9d90 100644 --- a/crates/komorebi-core/src/container.rs +++ b/crates/komorebi-core/src/container.rs @@ -19,10 +19,11 @@ use std::collections::VecDeque; /// What a container needs of a platform's window. /// -/// The window is a small `Copy` handle (Windows: an `HWND`; KDE: the compositor's id). Showing and +/// The window is a handle that is cheap to clone (Windows: an `HWND`; KDE: the compositor's id; macOS: an +/// Accessibility element). Showing and /// hiding it is the platform's business, so the container calls these four operations and nothing /// else; none of them reports a failure, because a window that cannot be hidden is left where it is. -pub trait ContainerWindow: Copy + PartialEq + std::fmt::Debug { +pub trait ContainerWindow: Clone + PartialEq + std::fmt::Debug { /// What names a window to the rest of the daemon: `isize` on Windows, `u32` on KDE. type Id: Copy + PartialEq; diff --git a/crates/komorebi-core/src/workspace.rs b/crates/komorebi-core/src/workspace.rs index d6bd9703..88bc906a 100644 --- a/crates/komorebi-core/src/workspace.rs +++ b/crates/komorebi-core/src/workspace.rs @@ -654,7 +654,7 @@ impl Workspace

{ /// The compositor reports no focused window. pub fn is_focused_window_monocle_or_maximized(&self) -> eyre::Result { let window_id = P::foreground_window_id().ok_or_eyre("no foreground window")?; - if let Some(window) = self.maximized_window + if let Some(window) = &self.maximized_window && window_id == window.id() { return Ok(true); @@ -683,7 +683,7 @@ impl Workspace

{ } } - if let Some(window) = self.maximized_window + if let Some(window) = &self.maximized_window && window_id == window.id() { return true; @@ -716,7 +716,7 @@ impl Workspace

{ } } - if let Some(window) = self.maximized_window + if let Some(window) = &self.maximized_window && let Some(window_exe) = window.exe() && exe == window_exe { @@ -750,7 +750,7 @@ impl Workspace

{ } } - if let Some(window) = self.maximized_window + if let Some(window) = &self.maximized_window && window_id == window.id() { return true; @@ -839,7 +839,7 @@ impl Workspace

{ container.load_focused_window(); } - self.new_container_for_window(window); + self.new_container_for_window(window.clone()); let mut container = Container::default(); container.add_window(window); @@ -1392,7 +1392,7 @@ impl Workspace

{ /// Takes the focused window of the workspace (the maximized one, the monocle's or the focused /// container's) out of its place and makes it a floating window. pub fn new_floating_window(&mut self) -> eyre::Result<()> { - let window = if let Some(maximized_window) = self.maximized_window { + let window = if let Some(maximized_window) = self.maximized_window.clone() { P::unmaximize_window(&maximized_window)?; self.maximized_window = None; self.maximized_window_restore_idx = None; @@ -1467,7 +1467,7 @@ impl Workspace

{ self.resize_dimensions = resize_dimensions; } - if let Some(window) = self.maximized_window { + if let Some(window) = &self.maximized_window { window.hide_window(); }