Skip to content

fix: Inset maximized client area to work area on Win32 - #23562

Merged
MartinZikmund merged 3 commits into
masterfrom
dev/mazi/fakechromepadding
Jun 29, 2026
Merged

MartinZikmund merged 3 commits into
masterfrom
dev/mazi/fakechromepadding

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #21745

PR Type:

🐞 Bugfix

What changed? 🚀

On Win32 (Skia), custom-chrome windows (ExtendsContentIntoTitleBar = true, or no presenter title bar) strip the system frame by returning 0 from WM_NCCALCSIZE, making the client area equal to the window rect. When such a window is maximized, Windows positions it so its resize frame overhangs the monitor on every edge (~8px/side at 100% DPI, more when scaled). The previous behaviour therefore let the content and caption buttons spill off-screen, and AppWindow.ClientSize / Window.Bounds / XamlRoot.Bounds over-reported. The only compensation was a hard-coded, DPI-unaware WindowChrome.Padding = 4 fudge.

This moves the correction to the native level, so WindowChrome fills the full screen and the reported sizes match a maximized WinUI app on the same screen:

  • WM_NCCALCSIZE: when the window is maximized (and not full-screen), clamp the proposed client rect to the monitor work area (client = window ∩ rcWork). This makes the client exactly the visible, non-taskbar region — identical to a standard maximized window and to WinUI — with no frame-thickness/DPI math (which is off by a pixel and caption-sensitive). The monitor is taken from the proposed rect, so it is correct on a secondary monitor and during restore-from-minimized.
  • Auto-hide taskbar: an auto-hide taskbar reserves no work area, so a maximized window flush with its edge is treated as full-screen and the bar stops revealing. 1px is reserved on any edge hosting one (SHAppBarMessage / ABM_GETAUTOHIDEBAREX), matching the native WinUI windowing layer.
  • Removed the WindowChrome.Padding = 4 hack and the now-dead _offScreenMargins / _extendedMargins.
  • Caption/drag-region hit-testing now maps region rects through the real client origin (ClientToScreen) instead of the window origin. The two coincided only while full-bleed; once the client is inset they diverged by the frame thickness, which would have misplaced the caption-button hit zones.

FullScreenPresenter (which also reports a maximized window via SW_MAXIMIZE) is explicitly excluded so it keeps owning the whole monitor. Standard windows (with a system title bar + border) are untouched — they fall through to DefWindowProc as before.

Validation (Skia Win32, AppWindowPositionAndSize sample, 150% DPI): with the title bar extended and the window maximized, the client area is now exactly the monitor work area (dW=0, dH=0) while the window rect overhangs by 2×frame; the caption buttons render at the true top-right corner and clicking the maximize/restore button correctly restores the window (confirming hit-test alignment). A runtime regression test (Given_AppWindow.When_Maximized_With_Extended_TitleBar_Client_Is_Inset_From_Window) asserts the client is inset from the overhanging window rect.

The approach was cross-checked against WPF (SetWindowRgn to rcWork), WinUI (client == work-area contract) and Avalonia (NCCALCSIZE inset).

PR Checklist ✅

MartinZikmund and others added 2 commits June 26, 2026 12:11
Custom-chrome (extend-into-titlebar) windows remove the system frame in
WM_NCCALCSIZE, but a maximized resizable window is positioned so its resize
frame overhangs the monitor on every edge. The client area (and the caption
buttons) therefore spilled off-screen, and AppWindow.ClientSize / Window.Bounds
/ XamlRoot.Bounds over-reported. The previous compensation was a hard-coded,
DPI-unaware WindowChrome.Padding = 4 fudge.

Correct it natively: when maximized (and not full-screen), clamp the proposed
client rect to the monitor work area in WM_NCCALCSIZE so the client becomes
exactly the visible, non-taskbar region - matching a standard maximized window
and WinUI - with no frame/DPI math. An auto-hide taskbar reserves no work area,
so reserve 1px on any edge hosting one (via SHAppBarMessage) so it can still be
revealed. The WindowChrome.Padding hack and the dead _offScreenMargins /
_extendedMargins are removed.

Also fix non-client caption/drag-region hit-testing to map region rects through
the real client origin (ClientToScreen) instead of the window origin, which only
coincided while full-bleed; once the client is inset they diverged by the frame
thickness.

closes #21745

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AYJwArDyoGhNWJ6Zy79Z3e
Regression test for #21745: a maximized window with an extended title bar must
have its client area inset from the (overhanging) window rect. Before the fix
the client equalled the window (off-screen bleed); after, it is strictly smaller
by the resize-frame thickness per side.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AYJwArDyoGhNWJ6Zy79Z3e
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 5m 39s —— View job


PR Review: fix: Inset maximized client area to work area on Win32

  • Gather context and read changed files
  • Review each changed file
  • Post inline comments for findings
  • Write summary

Overall verdict: ✅ Approved with minor fixes

The approach is correct and well-motivated. Moving the maximized-overhang correction to the native WM_NCCALCSIZE level is architecturally right — it makes the client rect authoritative and eliminates the DPI-unaware WindowChrome.Padding = 4 fudge. The companion fix to hit-testing (ClientToScreen instead of windowRectangle.top + titleBarHeightForDraggingRects) is a necessary and correct follow-on: once the client is inset from the window rect, GetWindowRect can no longer serve as the client origin.

3 findings — 2 minor, 1 nit:

Severity File Finding
Minor Win32AutoHideTaskbar.cs:1 Missing #nullable enable — new files must opt in per code-style rule
Minor Win32WindowWrapper.OverlappedPresenter.cs:183 borderCaptionThickness.left *= -1; is dead code after removing _offScreenMargins; the field is never read again
Nit Given_AppWindow.cs:192 AssertPositioningAndSizingSupport() call is redundant — the test is already scoped to SkiaWin32 via [PlatformCondition]

Specific notes

WM_NCCALCSIZE inset logic (Win32WindowWrapper.cs:386–403): Correct. Casting lParam directly to RECT* (reading rgrc[0], which is at offset 0 of NCCALCSIZE_PARAMS) is the standard Win32 technique. Using MonitorFromRect on the proposed (pre-clamped) window rect with MONITOR_DEFAULTTONEAREST is correct for secondary monitors and restore-from-minimized.

ApplyMaximizedClientInset: The clamp-to-work-area logic (Math.Max/Math.Min) is correct and handles all four edges without frame-thickness math.

ReserveAutoHideTaskbarEdges: The 1px reservation matches the native WinUI windowing behavior for auto-hide taskbars. The four SHAppBarMessage calls per WM_NCCALCSIZE are acceptable given the message only fires on size/position/maximize operations, not on every frame.

NonClientPointer hit-test fix: The switch from windowRectangle.top + titleBarHeightForDraggingRects to ClientToScreen(hWnd, {0,0}) is semantically equivalent for non-maximized windows and correct for maximized windows where the client origin is now inset from the window origin. This is a necessary companion to the WM_NCCALCSIZE change.

Test: The [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.SkiaWin32)] guard is the right attribute. The range check (1, 120) for the inset is appropriately generous across DPI scales.

Validation: Code-review assessment only (no local Win32 build environment). The PR description documents manual validation at 150% DPI with dW=0, dH=0.

@MartinZikmund
MartinZikmund enabled auto-merge June 26, 2026 12:35
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 219929 has failed on Uno.UI - CI.

- Add #nullable enable to Win32AutoHideTaskbar.cs (new file)
- Remove dead borderCaptionThickness.left negation

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01WngCVWr7iSBMzbjMjvKRQz
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 4m 53s —— View job


PR Review: fix: Inset maximized client area to work area on Win32

  • Gather context and read changed files
  • Review each changed file
  • Post inline comments for findings
  • Write summary

Overall verdict: ✅ Approved

All three findings from the previous review pass have been correctly addressed in e54d22bf. No new issues found.

Previous findings — status

Finding Status
Win32AutoHideTaskbar.cs missing #nullable enable ✅ Fixed — added at line 1
Dead borderCaptionThickness.left *= -1; ✅ Removed
Redundant AssertPositioningAndSizingSupport() ✅ Intentionally kept — guards XamlIsland/SkiaFrameBuffer sub-cases that [PlatformCondition] doesn't filter, consistent with the whole file's pattern

Code inspection notes

WM_NCCALCSIZE inset logic is correct. The guard wParam.Value == 1 && (!_hasBorder || !_hasTitleBar) correctly targets custom-chrome windows. The secondary OverlappedPresenter && IsZoomed check correctly excludes FullScreenPresenter and non-maximized states. Casting lParam to RECT* to read rgrc[0] is the correct Win32 technique.

ApplyMaximizedClientInset — MonitorFromRect on the proposed (pre-clamped) rect with MONITOR_DEFAULTTONEAREST handles secondary monitors and restore-from-minimized correctly. The Math.Max/Math.Min clamp is correct across all four edges.

ReserveAutoHideTaskbarEdges — 1px reserve matches native WinUI behavior. Four SHAppBarMessage calls per WM_NCCALCSIZE is acceptable given this message doesn't fire on every render frame.

ClientToScreen hit-test fix — the switch from windowRectangle.top to ClientToScreen is semantically equivalent for non-maximized windows and correct for maximized windows where the client origin is inset from the window origin.

Win32AutoHideTaskbar.cs — [DllImport] is consistent with all other hand-written interop in this directory (Win32UIAutomationInterop.cs, etc.). No new issues.

Test — [RunsOnUIThread] is inherited from the class-level annotation. async Task with proper awaits. Range check (1, 120) is appropriately generous across DPI scales. try/finally cleanup is correct.

WindowChrome.cs — The Padding = 4 hack and _offScreenMargins/_extendedMargins are cleanly removed. The comment at line 495–497 correctly documents why the padding is gone.

Validation: Code-review only (no local Win32 build environment). Current CI shows no failures on this commit.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit e6e00ae into master Jun 29, 2026
46 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/fakechromepadding branch June 29, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Win32] Adjust sizing when maximized and titlebar is extended

3 participants