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).
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent 4836a39b1c
commit 595e9c46a1
4 files changed
+15 -3

No files matched your search

+6
View File
@@ -92,6 +92,12 @@ pub fn foreground_window_id() -> Option<PlatformWindowId> {
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<u32> {
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()
@@ -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<usize> {
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 {
+5
View File
@@ -556,6 +556,11 @@ pub fn foreground_window_id() -> Option<u32> {
MacosApi::foreground_window_id()
}
/// The id of the monitor the pointer is on
pub fn monitor_id_at_cursor() -> Option<u32> {
MacosApi::monitor_from_point(MacosApi::cursor_pos())
}
impl Window {
pub fn new(
element: CFRetained<AXUIElement>,
@@ -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<usize> {
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 {