From d2881ae09b0a5e06b9c223e51a61a99655b4036f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Keller?= Date: Wed, 4 Oct 2023 10:59:45 +0200 Subject: [PATCH] Windows QPA: don't override user-removed margins When calculating margins, added a check to see if the window rect and the client rect are the same size. If they are, we return early, to avoid overwriting user-defined specific margins. Fixes: QTBUG-117704 Pick-to: 6.6 6.5 Change-Id: I9947feab4cb900293fb6be6cf09c56268f38d64a Reviewed-by: Oliver Wolff (cherry picked from commit 03a4164206d64151da7e0b0f850063e501bdea57) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/qwindowswindow.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 8dea0a01213..5e488b1ca46 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2775,11 +2775,6 @@ void QWindowsWindow::calculateFullFrameMargins() { if (m_data.flags & Qt::FramelessWindowHint) return; - // Normally obtained from WM_NCCALCSIZE. This calculation only works - // when no native menu is present. - const auto systemMargins = testFlag(DisableNonClientScaling) - ? QWindowsGeometryHint::frameOnPrimaryScreen(window(), m_data.hwnd) - : frameMargins_sys(); // QTBUG-113736: systemMargins depends on AdjustWindowRectExForDpi. This doesn't take into // account possible external modifications to the titlebar, as with ExtendsContentIntoTitleBar() @@ -2793,6 +2788,20 @@ void QWindowsWindow::calculateFullFrameMargins() RECT clientRect{}; GetWindowRect(handle(), &windowRect); GetClientRect(handle(), &clientRect); + + // QTBUG-117704 It is also possible that the user has manually removed the frame (for example + // by handling WM_NCCALCSIZE). If that is the case, i.e., the client area and the window area + // have identical sizes, we don't want to override the user-defined margins. + + if (qrectFromRECT(windowRect).size() == qrectFromRECT(clientRect).size()) + return; + + // Normally obtained from WM_NCCALCSIZE. This calculation only works + // when no native menu is present. + const auto systemMargins = testFlag(DisableNonClientScaling) + ? QWindowsGeometryHint::frameOnPrimaryScreen(window(), m_data.hwnd) + : frameMargins_sys(); + const int yDiff = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top); const bool typicalFrame = (systemMargins.left() == systemMargins.right()) && (systemMargins.right() == systemMargins.bottom());