diff --git a/crates/komorebi-core/src/monitor.rs b/crates/komorebi-core/src/monitor.rs
index 27644982..9e279de7 100644
--- a/crates/komorebi-core/src/monitor.rs
+++ b/crates/komorebi-core/src/monitor.rs
@@ -23,6 +23,9 @@ use serde::de::DeserializeOwned;
use std::collections::VecDeque;
use std::fmt::Debug;
+/// What names a monitor of platform `P`, as [`PlatformWindowId`] does for a window
+pub type PlatformMonitorId
=
::Id;
+
/// What the shared [`Monitor`] needs of a platform, besides what its workspaces need.
pub trait MonitorPlatform: WorkspacePlatform {
/// What names a monitor: `isize` on Windows (a monitor handle), `u32` on KDE.
diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs
index 1d825d0b..278f908f 100644
--- a/komorebi/src/window.rs
+++ b/komorebi/src/window.rs
@@ -74,6 +74,17 @@ pub fn foreground_window_id() -> Option {
WindowsApi::foreground_window().ok()
}
+/// What names a monitor: the type the shared monitor and window manager code compares ids as
+pub type PlatformMonitorId = komorebi_core::PlatformMonitorId;
+
+/// The monitor the pointer is on, if the system says (the nearest one when it is on none)
+pub fn monitor_id_at_cursor() -> Option {
+ let point = WindowsApi::cursor_pos().ok()?;
+ Some(PlatformMonitorId::from_hmonitor(
+ WindowsApi::monitor_from_point(point),
+ ))
+}
+
/// Where the pointer is, if the system says
pub fn cursor_position() -> Option<(i32, i32)> {
WindowsApi::cursor_pos()
diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs
index 2abcb4f4..e3d66a57 100644
--- a/komorebi/src/window_manager.rs
+++ b/komorebi/src/window_manager.rs
@@ -74,6 +74,7 @@ use crate::static_config::StaticConfig;
use crate::static_config::StaticConfigExt;
use crate::transparency_manager;
use crate::window::Window;
+use crate::window::monitor_id_at_cursor;
use crate::window_manager_event::WindowManagerEvent;
use crate::windows_api::WindowsApi;
use crate::winevent_listener;
@@ -3786,17 +3787,17 @@ impl WindowManager {
}
pub fn monitor_idx_from_current_pos(&mut self) -> Option {
- let hmonitor = WindowsApi::monitor_from_point(WindowsApi::cursor_pos().ok()?);
+ let monitor_id = monitor_id_at_cursor()?;
for (i, monitor) in self.monitors().iter().enumerate() {
- if monitor.id.to_hmonitor() == hmonitor {
+ if monitor.id == monitor_id {
return Option::from(i);
}
}
// our hmonitor might be stale, so if we didn't return above, try querying via the latest
// info taken from win32_display_data and update our hmonitor while we're at it
- if let Ok(latest) = WindowsApi::monitor(hmonitor) {
+ if let Ok(latest) = WindowsApi::monitor(monitor_id.to_hmonitor()) {
for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {
if monitor.extra.device_id == latest.extra.device_id {
monitor.id = latest.id;