From f31beb26d4bf677406f2957a60d6688ea3d27681 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:52:04 +0100 Subject: [PATCH 1/2] Place overlays using the actual monitor and dim the full modal region (cherry picked from commit 18059c80fa830233780b0981be512e407e818ae4) --- .../ui-contract/src/contract/overlay/host.rs | 5 +++- crates/ui-contract/src/runtime/egui/areas.rs | 18 ++++++++++-- crates/window/src/desktop.rs | 2 +- crates/window/src/desktop/work_area.rs | 29 +++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/contract/overlay/host.rs b/crates/ui-contract/src/contract/overlay/host.rs index 95e1cc563c..bdb31662d8 100644 --- a/crates/ui-contract/src/contract/overlay/host.rs +++ b/crates/ui-contract/src/contract/overlay/host.rs @@ -174,7 +174,10 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U Backdrop::None => egui::Color32::TRANSPARENT, }; let through = crate::runtime::sampler::through(ctx, crate::runtime::egui::pass::current_viewport(ctx), layer.id); - areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen: bounds, scrim, through, absorbs: !layer.exiting }); + // Work-area constraints place the dialog. Its modal cover spans the whole + // client region, including the part on a neighbouring monitor. + let screen = layer.region.map_or_else(|| ctx.content_rect(), |region| region.intersect(ctx.content_rect())); + areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen, scrim, through, absorbs: !layer.exiting }); Some(areas::layer_of(tier, cover_id)) } _ => None, diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index 4b3140e179..4027be3253 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -402,10 +402,22 @@ pub(crate) fn safe_rect(ctx: &Context) -> Rect { /// `safe_rect` without noting the read: for the root env, which moves `Input::Shell` by it. pub(crate) fn safe_rect_raw(ctx: &Context) -> Rect { let content = ctx.content_rect(); - ctx.input(|input| { + let (size, inner, state) = ctx.input(|input| { let viewport = input.viewport(); - craft_window::desktop::visible_part(content, viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) - }) + (viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) + }); + if state != craft_window::desktop::WindowState::FullScreen + && let Some(window) = inner + && let Some(visible) = craft_window::desktop::visible_part_on_monitors( + content, + window, + ctx.pixels_per_point(), + &crate::runtime::windows::WindowHost::of(ctx).monitors(), + ) + { + return visible; + } + craft_window::desktop::visible_part(content, size, inner, state) } /// Hands egui the whole layer order of the running pass, bottom first. egui consumes it by the end of the pass. diff --git a/crates/window/src/desktop.rs b/crates/window/src/desktop.rs index f49fc6d453..ff18f02de6 100644 --- a/crates/window/src/desktop.rs +++ b/crates/window/src/desktop.rs @@ -6,7 +6,7 @@ mod work_area; #[cfg(feature = "ui")] -pub use work_area::{TASKBAR, WindowState, fits, visible_part}; +pub use work_area::{TASKBAR, WindowState, fits, visible_part, visible_part_on_monitors}; #[cfg(target_os = "linux")] mod icon_theme; diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index cd10048e39..79d5e41bb1 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -6,6 +6,7 @@ //! window's content rect then run under the taskbar: [`visible_part`] is the content rect cut to //! the monitor less that room. +use craft_behavior::{Monitor, placement::monitor_of}; use egui::{Rect, Vec2, ViewportInfo, pos2, vec2}; /// Room kept free at the monitor's bottom edge for a taskbar or Dock egui can't see (the Windows @@ -84,6 +85,23 @@ pub fn visible_part(content: Rect, monitor: Option, inner: Option, s trusted(content, usable.translate(shift)) } +/// The visible part when the host knows the actual desktop layout. Monitor positions +/// are in physical pixels, while the window rectangle uses the current UI scale. +pub fn visible_part_on_monitors(content: Rect, inner: Rect, pixels_per_point: f32, monitors: &[Monitor]) -> Option { + if !inner.is_finite() || !pixels_per_point.is_finite() || pixels_per_point <= 0.0 { + return None; + } + let window_px = Rect::from_min_max(inner.min * pixels_per_point, inner.max * pixels_per_point); + let monitor = monitor_of(monitors, window_px)?; + let mut work = monitor.points_at(pixels_per_point); + if let Some(([x, y], [w, h])) = monitor.work_px { + work = Rect::from_min_size(pos2(x as f32, y as f32) / pixels_per_point, vec2(w as f32, h as f32) / pixels_per_point); + } else { + work.max.y -= TASKBAR; + } + Some(trusted(content, work.translate(content.min - inner.min))) +} + /// `content` cut to `usable`, unless that leaves too little to be a sensible guess. fn trusted(content: Rect, usable: Rect) -> Rect { let visible = content.intersect(usable); @@ -120,6 +138,17 @@ mod tests { assert_eq!(visible_part(content, Some(MONITOR), Some(inner), Normal).bottom(), 768.0 - TASKBAR); } + #[test] + fn a_staggered_monitors_window_keeps_its_visible_top_left_corner() { + let m = Monitor::new(craft_behavior::MonitorKey::new("secondary", [1920, 1200]), [1200, 770], [1920, 1200], 1.0) + .with_work_px([1200, 770], [1920, 1156]); + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1920.0, 1156.0) / scale); + let inner = content.translate(vec2(1200.0, 770.0) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, std::slice::from_ref(&m)), Some(content)); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0); From 8aa1d255d92941130e2b83967df9480f44323ac5 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 14:26:30 +0100 Subject: [PATCH 2/2] window: cover an offset portrait display at mixed DPI --- crates/window/src/desktop/work_area.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index 79d5e41bb1..18aafe9af6 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -149,6 +149,20 @@ mod tests { } } + #[test] + fn a_menu_keeps_its_client_anchor_on_an_offset_portrait_monitor() { + let laptop = Monitor::new(craft_behavior::MonitorKey::new("laptop", [1920, 1080]), [0, 0], [1920, 1080], 1.0); + let portrait = Monitor::new(craft_behavior::MonitorKey::new("portrait", [1080, 1920]), [1920, -240], [1080, 1920], 1.5) + .with_work_px([1920, -240], [1080, 1872]); + let monitors = [laptop, portrait]; + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1040.0, 1100.0) / scale); + let inner = content.translate(vec2(1920., -240.) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, &monitors), Some(content)); + assert!(visible_part(content, Some(vec2(1080., 1920.) / scale), Some(inner), Normal).left() > 0.); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0);