From 4fe7cbfbf6d4ec55cc7f2e588fe9af12c5d8af2e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 14:09:57 -0800 Subject: [PATCH] Windows: list no monitors when their scales differ The framework finds the monitor a palette window is on by testing the window's top-left corner, in the window's own points, at each listed monitor's scale. With a scale-1 primary listed before a scale-2 secondary, a palette on the secondary matched the primary, and its popups were kept in the primary's work area, away from their opener. The desktop window system now lists monitors only when they all share one scale. On a desktop with mixed scales, popups stay within the span of the app's windows and dialogs reopen where they were saved, as before this branch. --- apps/vectorcraft/src/window_system.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/vectorcraft/src/window_system.rs b/apps/vectorcraft/src/window_system.rs index d05bb80d65..7e87d5dca8 100644 --- a/apps/vectorcraft/src/window_system.rs +++ b/apps/vectorcraft/src/window_system.rs @@ -69,7 +69,8 @@ fn from_edges(left: i32, top: i32, right: i32, bottom: i32) -> Option<([i32; 2], /// The platform's window services, with the monitors listed through winit. On macOS no monitors are listed: winit /// gives each display's position in that display's own scale, so the pixel areas of displays with different scales -/// overlap and placement could pick the wrong one. +/// overlap and placement could pick the wrong one. Elsewhere monitors with different scales are not listed either +/// ([`one_scale`]). pub(super) struct DesktopWindows { list: Box Option> + Send + Sync>, now: Box Instant + Send + Sync>, @@ -121,7 +122,7 @@ impl WindowSystem for DesktopWindows { { return monitors.clone(); } - match (self.list)() { + match (self.list)().map(one_scale) { Some(monitors) => { *listed = Some((now, monitors.clone())); monitors @@ -131,6 +132,15 @@ impl WindowSystem for DesktopWindows { } } +/// `monitors` when they all have one scale, else none. The framework finds the monitor a palette window is on by +/// testing the window's corner, in the window's own points, at each monitor's scale, so with mixed scales a palette +/// on one monitor can be matched to another and its popups kept in that monitor's work area. Without a listing, +/// popups stay within the span of the app's windows and dialogs reopen where they were saved. +fn one_scale(monitors: Vec) -> Vec { + let mixed = monitors.windows(2).any(|pair| pair[0].scale != pair[1].scale); + if mixed { Vec::new() } else { monitors } +} + #[cfg(test)] mod tests { use super::*; @@ -214,6 +224,18 @@ mod tests { assert!(work.contains_rect(frame), "{frame:?} is inside {work:?}"); } + /// Monitors with different scales are not listed, so a palette's popups on a scale-2 monitor beside a scale-1 one + /// are not kept in the other monitor's work area; monitors that share a scale are listed. + #[test] + fn monitors_with_mixed_scales_are_not_listed() { + let (_, now) = clock(); + let mixed = DesktopWindows::with(|| Some(vec![monitor("A", [0, 0], [1920, 1080], 1.0), monitor("B", [1920, 0], [3840, 2160], 2.0)]), now); + assert!(mixed.monitors().is_empty(), "mixed scales list no monitors"); + let (_, now) = clock(); + let shared = DesktopWindows::with(|| Some(vec![monitor("A", [0, 0], [3840, 2160], 1.5), monitor("B", [3840, 0], [3840, 2160], 1.5)]), now); + assert_eq!(shared.monitors().len(), 2, "one scale lists every monitor"); + } + #[test] fn work_area_edges_give_corner_and_size() { assert_eq!(from_edges(-1920, -200, 0, 840), Some(([-1920, -200], [1920, 1040])));