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
Change-Id: I9947feab4cb900293fb6be6cf09c56268f38d64a
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 03a4164206d64151da7e0b0f850063e501bdea57)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit d2881ae09b0a5e06b9c223e51a61a99655b4036f)
(cherry picked from commit 0056998ba8def608c00e544765484407b186b3ff)
This commit is contained in:
Timothée Keller 2023-10-04 10:59:45 +02:00 committed by Qt Cherry-pick Bot
parent 67f497ed97
commit 0eb11bcee0

View File

@ -2780,11 +2780,6 @@ void QWindowsWindow::calculateFullFrameMargins()
{
if (shouldOmitFrameAdjustment(m_data.flags, m_data.hwnd))
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()
@ -2798,6 +2793,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());