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 {