From 595e9c46a1afae1384dc5a4b8837505d3a95a9ff Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 15:44:21 -0700 Subject: [PATCH] refactor(kde,mac): monitor_idx_from_current_pos asks window::monitor_id_at_cursor() Both daemons' window.rs have monitor_id_at_cursor() (KDE: the backend's pointer position resolved to the monitor under it; macOS: MacosApi's monitor_from_point of its cursor position), and monitor_idx_from_current_pos in both window_manager.rs files is now the same text up to its macOS-only comment block. No behaviour change. Verified: KDE cargo test -p komorebi-linux (lite env): 664 passed, 0 failed; fake-CC cargo clippy -p komorebi-macos ... --all-targets -D warnings: PASS; Windows cargo clippy -p komorebi-windows --locked --all-targets -D warnings: PASS (the whole-workspace Windows clippy fails in komorebi-bar, E0046 missing release_page_url, which is not in this change and fails at the base). Not run: the macOS tests (the Mac Mini). --- komorebi-for-kde/komorebi/src/window.rs | 6 ++++++ komorebi-for-kde/komorebi/src/window_manager.rs | 4 ++-- komorebi-for-mac/komorebi/src/window.rs | 5 +++++ komorebi-for-mac/komorebi/src/window_manager.rs | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/komorebi-for-kde/komorebi/src/window.rs b/komorebi-for-kde/komorebi/src/window.rs index 6d400e4d..578aaf7f 100644 --- a/komorebi-for-kde/komorebi/src/window.rs +++ b/komorebi-for-kde/komorebi/src/window.rs @@ -92,6 +92,12 @@ pub fn foreground_window_id() -> Option { backend().foreground_window().and_then(WindowId::to_u32) } +/// The id of the monitor the pointer is on, if the compositor says where it is +pub fn monitor_id_at_cursor() -> Option { + let (x, y) = backend().cursor_pos()?; + backend().monitor_from_point(x, y)?.to_u32() +} + /// Where the pointer is, if the compositor says pub fn cursor_position() -> Option<(i32, i32)> { backend().cursor_pos() diff --git a/komorebi-for-kde/komorebi/src/window_manager.rs b/komorebi-for-kde/komorebi/src/window_manager.rs index 2d952b57..8ac80635 100644 --- a/komorebi-for-kde/komorebi/src/window_manager.rs +++ b/komorebi-for-kde/komorebi/src/window_manager.rs @@ -84,6 +84,7 @@ use crate::static_config::StaticConfig; use crate::static_config::StaticConfigExt; use crate::window::Window; use crate::window::foreground_window_id; +use crate::window::monitor_id_at_cursor; use crate::window::should_act_individual; use crate::window_manager_event::WindowManagerEvent; use crate::window_manager_event_listener; @@ -2355,8 +2356,7 @@ impl WindowManager { } pub fn monitor_idx_from_current_pos(&mut self) -> Option { - let (x, y) = backend().cursor_pos()?; - let monitor_id = backend().monitor_from_point(x, y)?.to_u32()?; + let monitor_id = monitor_id_at_cursor()?; for (i, monitor) in self.monitors().iter().enumerate() { if monitor.id == monitor_id { diff --git a/komorebi-for-mac/komorebi/src/window.rs b/komorebi-for-mac/komorebi/src/window.rs index 0684803c..895b6673 100644 --- a/komorebi-for-mac/komorebi/src/window.rs +++ b/komorebi-for-mac/komorebi/src/window.rs @@ -556,6 +556,11 @@ pub fn foreground_window_id() -> Option { MacosApi::foreground_window_id() } +/// The id of the monitor the pointer is on +pub fn monitor_id_at_cursor() -> Option { + MacosApi::monitor_from_point(MacosApi::cursor_pos()) +} + impl Window { pub fn new( element: CFRetained, diff --git a/komorebi-for-mac/komorebi/src/window_manager.rs b/komorebi-for-mac/komorebi/src/window_manager.rs index a1aba496..40f91cef 100644 --- a/komorebi-for-mac/komorebi/src/window_manager.rs +++ b/komorebi-for-mac/komorebi/src/window_manager.rs @@ -55,6 +55,7 @@ use crate::window::dragged_window; use crate::window::foreground_window_id; use crate::window::live_resize_begins; use crate::window::live_resize_ends; +use crate::window::monitor_id_at_cursor; use crate::window::should_act_individual; use crate::window_manager_event::ManualNotification; use crate::window_manager_event::SystemNotification; @@ -2467,7 +2468,7 @@ impl WindowManager { } pub fn monitor_idx_from_current_pos(&mut self) -> Option { - let monitor_id = MacosApi::monitor_from_point(MacosApi::cursor_pos())?; + let monitor_id = monitor_id_at_cursor()?; for (i, monitor) in self.monitors().iter().enumerate() { if monitor.id == monitor_id {