Windows: full screen from a maximised window covers the taskbar's strip (#2943)

* Windows: full screen from a maximised window covers the taskbar's strip (#2941)

* Run CI again
This commit is contained in:
BFlat
2026-12-03 01:56:46 +07:00
committed by GitHub
parent 83100f906c
commit a751a4045f
+35 -8
View File
@@ -12,7 +12,9 @@
//! whenever it changes the window flags (maximize, restore, ...), so the step runs every frame; it
//! reads each style and writes only when it differs, so it costs next to nothing. Without the
//! caption Windows maximizes a window over the whole monitor, taskbar included, so the step also
//! moves a maximized window back into the monitor's work area (#2782).
//! moves a maximized window back into the monitor's work area (#2782). A window that goes full
//! screen while maximized stays maximized, and winit then keeps its client area inside the work
//! area, leaving a black band where the taskbar was; the step un-maximizes it (#2941).
//!
//! The same fix is in DesignCraft (#2139) and PhotoCraft (#2401). The long-term fix is in winit
//! (storytold/winit#17); this module goes when the pinned winit has it.
@@ -29,13 +31,23 @@ const WS_BORDER: u32 = 0x0080_0000;
/// `WS_CAPTION`, which already includes `WS_BORDER`.
#[cfg(any(windows, test))]
const WS_CAPTION: u32 = 0x00C0_0000;
/// `WS_SYSMENU`, which winit gives every window but a full-screen one.
#[cfg(any(windows, test))]
const WS_SYSMENU: u32 = 0x0008_0000;
/// `WS_MAXIMIZE`.
#[cfg(any(windows, test))]
const WS_MAXIMIZE: u32 = 0x0100_0000;
/// `style` without the OS title bar and frame (`WS_CAPTION`, `WS_BORDER`). The sizing border
/// (`WS_THICKFRAME`) and the window buttons stay, so edge resizing, Aero snap and the system menu
/// keep working, as they did with winit 0.27's undecorated windows.
/// keep working, as they did with winit 0.27's undecorated windows. A full-screen window (no
/// `WS_SYSMENU`) also loses `WS_MAXIMIZE`: winit fits a maximized window's client area to the
/// monitor's work area, so one that went full screen while maximized left the taskbar's strip
/// black (#2941). Leaving full screen restores the placement winit saved, maximized again.
#[cfg(any(windows, test))]
pub fn borderless_style(style: u32) -> u32 {
style & !(WS_CAPTION | WS_BORDER)
let full_screen = style & WS_SYSMENU == 0;
style & !(WS_CAPTION | WS_BORDER | if full_screen { WS_MAXIMIZE } else { 0 })
}
/// Where a maximized borderless window goes on a monitor, as `[left, top, right, bottom]`: its
@@ -99,8 +111,8 @@ mod platform {
}))
}
/// Removes `WS_CAPTION`/`WS_BORDER` and has Windows recalculate the frame; a no-op once they
/// are gone.
/// Removes the styles [`super::borderless_style`] drops and has Windows recalculate the frame;
/// a no-op once they are gone.
fn strip(hwnd: &HWND) {
fit_maximized(hwnd);
let style = hwnd.style();
@@ -108,7 +120,11 @@ mod platform {
if super::borderless_style(style.raw()) == style.raw() {
return;
}
hwnd.set_style(style & !(co::WS::CAPTION | co::WS::BORDER));
let mut drop = co::WS::CAPTION | co::WS::BORDER;
if !style.has(co::WS::SYSMENU) {
drop |= co::WS::MAXIMIZE;
}
hwnd.set_style(style & !drop);
let _ = hwnd.SetWindowPos(
HwndPlace::None,
POINT::new(),
@@ -148,7 +164,7 @@ mod window_frame_tests {
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use super::{WS_BORDER, WS_CAPTION, WindowFrame, borderless_style, maximized_rect};
use super::{WS_BORDER, WS_CAPTION, WS_MAXIMIZE, WS_SYSMENU, WindowFrame, borderless_style, maximized_rect};
#[cfg(windows)]
#[test]
@@ -156,9 +172,10 @@ mod window_frame_tests {
use winsafe::co;
assert_eq!(co::WS::CAPTION.raw(), WS_CAPTION);
assert_eq!(co::WS::BORDER.raw(), WS_BORDER);
assert_eq!(co::WS::SYSMENU.raw(), WS_SYSMENU);
assert_eq!(co::WS::MAXIMIZE.raw(), WS_MAXIMIZE);
}
const WS_SYSMENU: u32 = 0x0008_0000;
const WS_THICKFRAME: u32 = 0x0004_0000;
const WS_MINIMIZEBOX: u32 = 0x0002_0000;
const WS_MAXIMIZEBOX: u32 = 0x0001_0000;
@@ -182,6 +199,16 @@ mod window_frame_tests {
assert_eq!(borderless_style(borderless_style(bare | WS_CAPTION)), bare);
}
#[test]
fn a_full_screen_window_is_not_kept_maximized() {
let windowed = WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE | WS_MAXIMIZE;
assert_eq!(borderless_style(windowed) & WS_MAXIMIZE, WS_MAXIMIZE, "a maximized window stays maximized");
// winit's full-screen styles: the overlapped-window bits (system menu included) are gone.
let full = WS_CAPTION | WS_BORDER | WS_VISIBLE | WS_MAXIMIZE;
assert_eq!(borderless_style(full) & WS_MAXIMIZE, 0, "full screen from maximized: client fills the monitor");
assert_eq!(borderless_style(full) & WS_VISIBLE, WS_VISIBLE, "unrelated bits kept");
}
#[test]
fn a_maximized_window_leaves_the_taskbar_uncovered() {
// A 1440-pixel-high monitor with a 48-pixel taskbar along the bottom.