From 7766054dfe9046b8acbbb3f23ce72b1129af0b6d Mon Sep 17 00:00:00 2001 From: Benjamin Arnaud Date: Tue, 19 May 2026 16:40:44 +0200 Subject: [PATCH] window: Fix top border overlap --- src/core/contexts/win32windowcontext.cpp | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index b86ecca..d747e8b 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -1193,7 +1193,7 @@ namespace QWK { effectBugWorkaround(); return true; } - + if (key == QStringLiteral("dwm-border-color")) { if (!isWin11OrGreater()) { return false; @@ -2198,6 +2198,10 @@ namespace QWK { DynamicApis::instance().pDwmFlush(); } }); + + bool max; + bool full; + if (isSystemBorderEnabled()) { // Store the original top margin before the default window procedure applies the // default frame. @@ -2215,6 +2219,7 @@ namespace QWK { *result = originalResult; return true; } + // Re-apply the original top from before the size of the default frame was // applied, and the whole top frame (the title bar and the top border) is gone // now. For the top frame, we only has 2 choices: (1) remove the top frame @@ -2224,10 +2229,27 @@ namespace QWK { // set, so here we can only remove the top frame entirely and use some special // technique to bring the top border back. clientRect->top = originalTop; + + max = isMaximized(hWnd); + full = isFullScreen(hWnd); + + // On Windows 11, DWM draws a visible frame border at the top of every thick-frame + // window (DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, typically 1 physical pixel). That + // border ends up painted on top of the client area, covering the top of the content. + // So we shift the clientRect accordingly. This only applies when the window is not + // maximized or full-screen. + if (isWin11OrGreater() && max == false && full == false) { + int size = getWindowFrameBorderThickness(hWnd); + + clientRect->top += size; + clientRect->bottom += size; + } + } + else { + max = isMaximized(hWnd); + full = isFullScreen(hWnd); } - const bool max = isMaximized(hWnd); - const bool full = isFullScreen(hWnd); // We don't need this correction when we're fullscreen. We will // have the WS_POPUP size, so we don't have to worry about // borders, and the default frame will be fine.