refactor(windows): PlatformMonitorId next to PlatformWindowId; monitor_idx_from_current_pos has KDE's text

komorebi-core gets pub type PlatformMonitorId<P> = <P as MonitorPlatform>::Id,
the monitor counterpart of PlatformWindowId (blocker 5 of core-model.md
section 18). The Windows daemon aliases it (window::PlatformMonitorId, the
shared MonitorId) and gets window::monitor_id_at_cursor() like KDE's, so
monitor_idx_from_current_pos reads: ask the monitor id at the cursor, compare
monitor.id == monitor_id, and only then the Windows-only stale-handle fallback
(WindowsApi::monitor(monitor_id.to_hmonitor())). Same calls as before
(cursor_pos, monitor_from_point), in the same order.

Not a behaviour change. kfde: the alias is generic over MonitorPlatform; KDE and
macOS can alias it the same way. Verified: tools/fast-check native (core
tests), bare Windows clippy -D warnings, KDE check + lib tests, macOS fake-CC
type-check PASS; e2e: commands (monitor-from-cursor commands), hotplug scenarios
if any.
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent 176dc0a8ba
commit 96332b2578
3 files changed
+18 -3

No files matched your search

+3
View File
@@ -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<P> = <P as MonitorPlatform>::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.
+11
View File
@@ -74,6 +74,17 @@ pub fn foreground_window_id() -> Option<PlatformWindowId> {
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<crate::workspace::WindowsPlatform>;
/// 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<PlatformMonitorId> {
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()
+4 -3
View File
@@ -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<usize> {
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;