PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Fix/3144 taskbar maximized (#3308)
Axlef92f13490b24
diff --git a/apps/photocraft/src/window_frame.rs b/apps/photocraft/src/window_frame.rsindex cb6ea91d2..1b814746b 100644--- a/apps/photocraft/src/window_frame.rs+++ b/apps/photocraft/src/window_frame.rs@@ -12,6 +12,14 @@//! `WS_BORDER` and forces Windows to recalculate the frame. winit puts them back whenever it//! changes the window flags (maximize, restore, …), so the returned guard checks every frame.//!+//! Windows sizes a maximize by the frame its styles describe, so a window maximized while its+//! caption is gone is sized without one: its rect covers the whole monitor, taskbar included.+//! The shell reads a caption-less window covering its monitor as a full-screen app and drops the+//! taskbar's backdrop behind it — a black band on stock Windows 11, a glitched unresponsive one+//! under ExplorerPatcher (#3144). The guard therefore also trims a parked maximize's rect back to+//! the work area plus its own frame, clear of the taskbar. winit pins the client area to the work+//! area either way (`WM_NCCALCSIZE`), so the app's pixels do not move.+//!//! The Windows calls go through safe `winsafe` wrappers; the workspace forbids `unsafe`, and//! winsafe can't wrap a raw handle without it, so the window is found by its handle instead.@@ -34,8 +42,8 @@ mod platform {_ => return None,};let hwnd = find_window(target)?;- strip(&hwnd);- Some(Box::new(move || strip(&hwnd)))+ reapply(&hwnd);+ Some(Box::new(move || reapply(&hwnd)))}/// The top-level window with the given raw handle. `EnumWindows` hands out real `HWND`s, so@@ -53,6 +61,13 @@ mod platform {found}+ /// One pass of the per-frame guard: the styles winit put back come off again, and a parked+ /// maximize stays clear of the taskbar.+ fn reapply(hwnd: &HWND) {+ strip(hwnd);+ keep_clear_of_the_taskbar(hwnd);+ }+/// Removes `WS_CAPTION`/`WS_BORDER` and has Windows recalculate the frame. A no-op once they/// are gone, so it is cheap to call every frame.fn strip(hwnd: &HWND) {@@ -70,6 +85,51 @@ mod platform {);}+ /// How far a parked maximize reaches past its monitor on the left, top and right: the resize+ /// border (about 8 pt at 100 %, more with DPI). Past that, a maximized window's rect is not+ /// parked but being dragged or snapped, and is left alone.+ const FRAME: i32 = 32;++ /// [`clamped_height`] for this frame's window: trim a maximized window whose rect runs under+ /// the taskbar back to the work area plus its frame (#3144). No-op otherwise.+ fn keep_clear_of_the_taskbar(hwnd: &HWND) {+ if !hwnd.IsZoomed() {+ return;+ }+ let (Ok(r), Ok(mi)) = (hwnd.GetWindowRect(), hwnd.MonitorFromWindow(co::MONITOR::DEFAULTTONEAREST).GetMonitorInfo()) else {+ return;+ };+ let (m, w) = (mi.rcMonitor, mi.rcWork);+ let Some(height) = clamped_height((r.left, r.top, r.right, r.bottom), (m.left, m.top, m.right, m.bottom), (w.left, w.top, w.right, w.bottom)) else {+ return;+ };+ let _ = hwnd.SetWindowPos(+ HwndPlace::None,+ POINT::new(),+ SIZE { cx: r.right - r.left, cy: height },+ co::SWP::NOMOVE | co::SWP::NOZORDER | co::SWP::NOACTIVATE,+ );+ }++ /// The height to trim a maximize to so its rect stops at the taskbar, or `None` when it+ /// already does or `rect` (`left, top, right, bottom`, desktop coordinates) is not parked at+ /// its maximize place. `monitor` is the monitor's full rect and `work` its work area (the+ /// monitor less the taskbar) in the same coordinates. The parked check is against the full+ /// monitor, because that is where Windows puts a maximize; the trim is against the work area.+ fn clamped_height(rect: (i32, i32, i32, i32), monitor: (i32, i32, i32, i32), work: (i32, i32, i32, i32)) -> Option<i32> {+ let (l, t, r, b) = rect;+ let (ml, mt, mr, _) = monitor;+ let (_, _, _, wb) = work;+ let side = ml - l;+ if !(0..=FRAME).contains(&side) || !(0..=FRAME).contains(&(mt - t)) || !(0..=FRAME).contains(&(r - mr)) {+ return None;+ }+ if b <= wb + side {+ return None;+ }+ Some(wb + side - t)+ }+/// `style` without the OS title bar and frame (`WS_CAPTION`, which already includes/// `WS_BORDER`). The sizing border (`WS_THICKFRAME`) stays, so edge resizing and Aero snap/// keep working, as they did with winit 0.27's undecorated windows.@@ -79,7 +139,7 @@ mod platform {#[cfg(test)]mod tests {- use super::borderless;+ use super::{borderless, clamped_height};use winsafe::co;#[test]@@ -94,6 +154,37 @@ mod platform {// Already borderless: unchanged, so the per-frame call does nothing.assert_eq!(bare.raw(), borderless(bare).raw());}++ #[test]+ fn a_maximize_covering_the_taskbar_is_trimmed_to_the_work_area() {+ // 1920 × 1080 with a 34 pt taskbar: a caption-less maximize covers the whole+ // monitor, taskbar included (#3144). Trimmed so the rect ends at the work area+ // plus the frame the window was parked with.+ let monitor = (0, 0, 1920, 1080);+ let work = (0, 0, 1920, 1046);+ assert_eq!(clamped_height((-7, -7, 1927, 1087), monitor, work), Some(1046 + 7 - (-7)));+ }++ #[test]+ fn a_maximize_already_clear_of_the_taskbar_is_left_alone() {+ // What Windows sizes a framed maximize to: the work area plus the frame.+ assert_eq!(clamped_height((-8, -8, 1928, 1054), (0, 0, 1920, 1080), (0, 0, 1920, 1046)), None);+ }++ #[test]+ fn a_maximize_beside_a_side_taskbar_is_left_alone() {+ // Taskbar on the left: the work area starts further right, but the monitor's bottom+ // is still clear, so the rect reaches nothing.+ assert_eq!(clamped_height((-8, -8, 1928, 1088), (0, 0, 1920, 1080), (48, 0, 1920, 1080)), None);+ }++ #[test]+ fn a_maximize_being_dragged_away_is_left_alone() {+ let monitor = (0, 0, 1920, 1080);+ let work = (0, 0, 1920, 1046);+ assert_eq!(clamped_height((100, 200, 1100, 900), monitor, work), None, "moved");+ assert_eq!(clamped_height((-500, -7, 1427, 1087), monitor, work), None, "resized");+ }}}diff --git a/contributors/people.toml b/contributors/people.tomlindex aa072cbf9..0c8aa6fb0 100644--- a/contributors/people.toml+++ b/contributors/people.toml@@ -103,3 +103,6 @@ sync_github_name = true[people.timothydaly1]display_name = "SyntaxError"++[people.axlecoffee]+sync_github_name = true