Merge pull request #4506 from storytold/fix/pdfcraft-portrait-work-area-provenance

Cover offset portrait monitors and preserve the PdfCraft maintenance pin
This commit is contained in:
FredApps authored and GitHub committed 2026-11-30 15:00:35 +01:00
commit 901999c6d4
4 files changed
+63 -5

No files matched your search

@@ -185,7 +185,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,
+15 -3
View File
@@ -433,10 +433,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.
+1 -1
View File
@@ -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;
+43
View File
@@ -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<Vec2>, inner: Option<Rect>, 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<Rect> {
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,31 @@ 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 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);