From 3e5475e7efb39689fc832d53cf6047256c1c5e8b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 19:27:24 -0700 Subject: [PATCH] refactor(core,kde,windows,mac): remove CommandHost::POINTER_PICKS_THE_MONITOR_FOR_ALL All three daemons now let the pointer pick the monitor for every shared command that has the preamble, so the const has no reason left. The shared functions always call focus_the_monitor_under_the_pointer; the three CommandHost impls lose the const (Windows had it true already, so nothing changes there). The core test of the switch becomes the_pointer_picks_the_monitor_..._on_all_platforms. known-issues item 1 is marked resolved and core-model.md section 18 text is updated. No behaviour change in this revision beyond the previous two. Verified: komorebi-core tests all pass (command tests 18); KDE cargo test -p komorebi-linux 670 passed, 0 failed; fake-CC clippy for the four macOS packages passes; cargo clippy -p komorebi-windows --all-targets -D warnings passes. Not verified: Windows tests or e2e (cannot run on Linux). --- crates/komorebi-core/src/command.rs | 26 +---- crates/komorebi-core/tests/commands.rs | 100 ++---------------- docs/dev/core-model.md | 4 +- docs/dev/known-issues.md | 4 +- .../komorebi/src/process_command.rs | 3 - .../komorebi/src/process_command.rs | 3 - komorebi/src/process_command.rs | 3 - 7 files changed, 19 insertions(+), 124 deletions(-) diff --git a/crates/komorebi-core/src/command.rs b/crates/komorebi-core/src/command.rs index e328b6ef..c5383cab 100644 --- a/crates/komorebi-core/src/command.rs +++ b/crates/komorebi-core/src/command.rs @@ -22,12 +22,6 @@ pub trait CommandHost { /// The platform whose monitors the host has. type P: MonitorPlatform; - /// Whether the commands that act on the focused monitor first focus the monitor the pointer is - /// on when the workspace shown there is empty, for `cycle_focus_empty_workspace`, - /// `close_workspace` and `focus_last_workspace` (the other commands always do). Windows does it - /// for all of them; KDE and macOS do not. - const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = false; - /// The monitors. fn monitors(&self) -> &VecDeque>; @@ -104,9 +98,7 @@ pub fn cycle_focus_empty_workspace( host: &mut H, direction: CycleDirection, ) -> eyre::Result<()> { - if H::POINTER_PICKS_THE_MONITOR_FOR_ALL { - focus_the_monitor_under_the_pointer(host)?; - } + focus_the_monitor_under_the_pointer(host)?; let focused_monitor = host.focused_monitor().ok_or_eyre("there is no monitor")?; @@ -142,9 +134,7 @@ pub fn cycle_focus_empty_workspace( /// Removes the focused workspace when it is empty, unnamed and not the monitor's only one, and /// focuses the one before it pub fn close_workspace(host: &mut H) -> eyre::Result<()> { - if H::POINTER_PICKS_THE_MONITOR_FOR_ALL { - focus_the_monitor_under_the_pointer(host)?; - } + focus_the_monitor_under_the_pointer(host)?; let mut can_close = false; @@ -177,9 +167,7 @@ pub fn close_workspace(host: &mut H) -> eyre::Result<()> { /// Focuses the workspace that was focused before this one pub fn focus_last_workspace(host: &mut H) -> eyre::Result<()> { - if H::POINTER_PICKS_THE_MONITOR_FOR_ALL { - focus_the_monitor_under_the_pointer(host)?; - } + focus_the_monitor_under_the_pointer(host)?; let idx = host .focused_monitor() @@ -378,9 +366,7 @@ pub fn focus_workspace_number( host: &mut H, workspace_idx: usize, ) -> eyre::Result<()> { - if H::POINTER_PICKS_THE_MONITOR_FOR_ALL { - focus_the_monitor_under_the_pointer(host)?; - } + focus_the_monitor_under_the_pointer(host)?; if host.focused_workspace_idx().unwrap_or_default() != workspace_idx { host.focus_workspace(workspace_idx)?; @@ -394,9 +380,7 @@ pub fn focus_workspace_numbers( host: &mut H, workspace_idx: usize, ) -> eyre::Result<()> { - if H::POINTER_PICKS_THE_MONITOR_FOR_ALL { - focus_the_monitor_under_the_pointer(host)?; - } + focus_the_monitor_under_the_pointer(host)?; let focused_monitor_idx = host.focused_monitor_idx(); diff --git a/crates/komorebi-core/tests/commands.rs b/crates/komorebi-core/tests/commands.rs index faa8507e..ab914aad 100644 --- a/crates/komorebi-core/tests/commands.rs +++ b/crates/komorebi-core/tests/commands.rs @@ -385,108 +385,26 @@ fn locking_a_container_that_is_not_there_is_ignored_but_a_missing_monitor_or_wor assert!(komorebi_core::set_container_locked(&mut host, 0, 9, 0, true).is_err()); } -/// A host that says whether the pointer picks the monitor first, and does what `Host` does -struct Pointer(Host); - -impl CommandHost for Pointer { - type P = StubPlatform; - const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = ALL; - - fn monitors(&self) -> &VecDeque> { - self.0.monitors() - } - fn focused_monitor(&self) -> Option<&Monitor> { - self.0.focused_monitor() - } - fn focused_monitor_mut(&mut self) -> Option<&mut Monitor> { - self.0.focused_monitor_mut() - } - fn focused_monitor_idx(&self) -> usize { - self.0.focused_monitor_idx() - } - fn monitor_idx_from_current_pos(&mut self) -> Option { - self.0.monitor_idx_from_current_pos() - } - fn focus_monitor(&mut self, idx: usize) -> eyre::Result<()> { - self.0.focus_monitor(idx) - } - fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()> { - self.0.focus_workspace(idx) - } - fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> { - self.0.show_workspace_on(monitor_idx, workspace_idx) - } - fn move_container_to_workspace( - &mut self, - idx: usize, - follow: bool, - direction: Option, - ) -> eyre::Result<()> { - self.0.move_container_to_workspace(idx, follow, direction) - } -} - -impl komorebi_core::MonitorCommandHost for Pointer { - fn mouse_follows_focus(&self) -> bool { - self.0.mouse_follows_focus() - } - fn update_focused_workspace(&mut self, a: bool, b: bool) -> eyre::Result<()> { - self.0.update_focused_workspace(a, b) - } - fn direction_from_monitor_idx(&self, idx: usize) -> Option { - self.0.direction_from_monitor_idx(idx) - } - fn move_container_to_monitor( - &mut self, - idx: usize, - workspace_idx: Option, - follow: bool, - direction: Option, - ) -> eyre::Result<()> { - self.0 - .move_container_to_monitor(idx, workspace_idx, follow, direction) - } - fn focused_workspace_idx(&self) -> eyre::Result { - self.0.focused_workspace_idx() - } -} - fn pointer_on_the_second_monitor() -> Host { let mut host = two_monitors(); host.pointer_on = Some(1); host } -fn focused_monitor_calls(host: &Host) -> usize { - host.calls - .iter() - .filter(|call| call.starts_with("focus_monitor")) - .count() -} - #[test] -fn the_pointer_switch_gives_the_empty_close_last_and_number_commands_the_preamble() { +fn the_pointer_picks_the_monitor_for_the_empty_close_last_cycle_and_number_commands_on_all_platforms() { // commands.py: close-workspace, cycle-empty-workspace, focus-last-workspace, focus-workspace, - // focus-workspaces; with the switch off nothing looks at the pointer, with it on the monitor - // under the pointer is focused first when its workspace is empty - let mut off = Pointer::(pointer_on_the_second_monitor()); - komorebi_core::close_workspace(&mut off).unwrap(); - komorebi_core::focus_last_workspace(&mut off).unwrap(); - komorebi_core::cycle_focus_empty_workspace(&mut off, CycleDirection::Next).unwrap(); - komorebi_core::focus_workspace_number(&mut off, 1).unwrap(); - komorebi_core::focus_workspace_numbers(&mut off, 1).unwrap(); - assert_eq!(focused_monitor_calls(&off.0), 0); - + // focus-workspaces; the monitor under the pointer is focused first when its workspace is empty for command in 0..5 { - let mut on = Pointer::(pointer_on_the_second_monitor()); + let mut host = pointer_on_the_second_monitor(); match command { - 0 => komorebi_core::close_workspace(&mut on).unwrap(), - 1 => komorebi_core::focus_last_workspace(&mut on).unwrap(), - 2 => komorebi_core::cycle_focus_empty_workspace(&mut on, CycleDirection::Next).unwrap(), - 3 => komorebi_core::focus_workspace_number(&mut on, 1).unwrap(), - _ => komorebi_core::focus_workspace_numbers(&mut on, 1).unwrap(), + 0 => komorebi_core::close_workspace(&mut host).unwrap(), + 1 => komorebi_core::focus_last_workspace(&mut host).unwrap(), + 2 => komorebi_core::cycle_focus_empty_workspace(&mut host, CycleDirection::Next).unwrap(), + 3 => komorebi_core::focus_workspace_number(&mut host, 1).unwrap(), + _ => komorebi_core::focus_workspace_numbers(&mut host, 1).unwrap(), } - assert_eq!(on.0.calls[0], "focus_monitor 1", "command {command}"); + assert_eq!(host.calls[0], "focus_monitor 1", "command {command}"); } } diff --git a/docs/dev/core-model.md b/docs/dev/core-model.md index a26aa3d9..10974f03 100644 --- a/docs/dev/core-model.md +++ b/docs/dev/core-model.md @@ -1390,8 +1390,8 @@ monitors (`CycleMoveContainerToWorkspace`, `CycleSendContainerToWorkspace`, `Cyc `CycleMoveContainerToMonitor`, `CycleSendContainerToMonitor`, `FocusMonitorWorkspaceNumber`, `MoveContainerToMonitorWorkspaceNumber`, `SendContainerToMonitorWorkspaceNumber`) and the lock and unlock of a container by index. The one platform difference found, that Windows lets the pointer pick the -monitor first for the empty, close and last-workspace commands (a probable omission on KDE and macOS, -section 18), is the const `CommandHost::POINTER_PICKS_THE_MONITOR_FOR_ALL`, true only for Windows. +monitor first for the empty, close, last-workspace and workspace-number commands (an omission on KDE and macOS, +section 18), is gone: all three do it now (wip-u-ptr), so the const that held the difference was removed. **What stays, and why** (identical across the three unless noted; each needs a `WindowManager` method or field, so moving them means moving `WindowManager`, the blockers of section 18): diff --git a/docs/dev/known-issues.md b/docs/dev/known-issues.md index f0ba8ea6..1b073c7f 100644 --- a/docs/dev/known-issues.md +++ b/docs/dev/known-issues.md @@ -2,7 +2,9 @@ Findings of the consolidation reviews and tests that are NOT fixed because whether they are bugs, or how to fix them, is a decision for the owner. Each has the evidence, why it may or may not be a bug, the platforms, and a proposed fix. Paths are relative to the repository root at the time of writing and may have moved. -## 1. KDE FocusWorkspaceNumber, FocusWorkspaceNumbers and FocusLastWorkspace skip the pointer-monitor preamble +## 1. RESOLVED (wip-u-ptr): KDE FocusWorkspaceNumber, FocusWorkspaceNumbers and FocusLastWorkspace skipped the pointer-monitor preamble + +- **Resolution**: the owner approved Windows behaviour for all platforms. The preamble now runs for all three daemons in the shared `komorebi_core::command` functions (`focus_workspace_number`, `focus_workspace_numbers`, `focus_last_workspace`, and the others). KDE is covered by `komorebi-for-kde/komorebi/tests/pointer_monitor.rs`, core by `crates/komorebi-core/tests/commands.rs`. Owed: KDE VM commands and workspace-switch, macOS hand check H1 (docs/dev/macos-handcheck.md). The text below is the original finding. - **Evidence**: komorebi-for-kde/komorebi/src/process_command.rs lines 1245-1277: the arms for the three messages call `focus_workspace` on the focused monitor directly. The Windows daemon (komorebi/src/process_command.rs:972-987 for `FocusWorkspaceNumber`, and lines about 2185 and 2215 for the helpers behind `FocusLastWorkspace` and `FocusWorkspaceNumbers`) first checks `monitor_idx_from_current_pos()`: when the pointer is on another monitor whose focused workspace is empty, that monitor becomes the focused one. KDE has the same preamble only in `cycle_focus_workspace` (line 897-909). - **Why it may be a bug**: on a secondary monitor with an empty workspace and the pointer on it, `focus-workspace 2` switches the workspace of the monitor that was focused before, not the one the user is pointing at, unlike on Windows and unlike KDE's own `cycle-focus-workspace`. **Why not**: KWin may not report an empty monitor as pointed at the same way; the KDE tests do not cover it, so it may have been left out on purpose. diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index 3cedffa7..60b5b3f0 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -2041,9 +2041,6 @@ impl komorebi_core::CommandHost for WindowManager { WindowManager::focus_workspace(self, idx) } - // the pointer picks the monitor, as on Windows (docs/dev/known-issues.md item 1) - const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = true; - fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> { let monitor = self .monitors_mut() diff --git a/komorebi-for-mac/komorebi/src/process_command.rs b/komorebi-for-mac/komorebi/src/process_command.rs index 09e3fb33..7dda17a0 100644 --- a/komorebi-for-mac/komorebi/src/process_command.rs +++ b/komorebi-for-mac/komorebi/src/process_command.rs @@ -1732,9 +1732,6 @@ impl komorebi_core::CommandHost for WindowManager { WindowManager::focus_workspace(self, idx) } - // the pointer picks the monitor, as on Windows (docs/dev/known-issues.md item 1) - const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = true; - fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> { let monitor = self .monitors_mut() diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 6eefbe18..157260c7 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -2257,9 +2257,6 @@ impl WindowManager { impl komorebi_core::CommandHost for WindowManager { type P = crate::workspace::WindowsPlatform; - // Windows lets the pointer pick the monitor first for these commands too - const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = true; - fn monitors(&self) -> &std::collections::VecDeque { WindowManager::monitors(self) }