From ee68257b61268ef8f5f4c9b4090d8a1624cd98ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 22 Jun 2021 13:32:45 +0200 Subject: [PATCH] Fix PerMonitorV2 DPI aware NonCLientAreaScaling handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The value returned from shouldHaveNonClientDpiScaling() controls two related behaviors: 1) Should Qt call user32dll.enableNonClientDpiScaling() 2) Should Qt code treat NonClientAreaScaling as enabled. Commit c35643db updated shouldHaveNonClientDpiScaling() to account for the fact that PerMonitorV2 always enables NonCLientAreaScaling, with the intent to disable 1) However this also disables 2), which was not intended. Instead, make shouldHaveNonClientDpiScaling() always return true when PerMonitorV2 is enabled, and then also omit calling the user32dll API in this case. Change-Id: I1d06f36a3d06becc667351fadcb00ab28af6ec4b Pick-to: 6.2 Reviewed-by: Tor Arne Vestbø Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowscontext.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 78961472b0..983fc9d47b 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1110,8 +1110,11 @@ static inline bool resizeOnDpiChanged(const QWindow *w) bool QWindowsContext::shouldHaveNonClientDpiScaling(const QWindow *window) { + // DPI aware V2 processes always have NonClientDpiScaling enabled. + if (QWindowsContextPrivate::m_v2DpiAware) + return true; + return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10 - && !QWindowsContextPrivate::m_v2DpiAware // V2 implies NonClientDpiScaling; no need to enable && window->isTopLevel() && !window->property(QWindowsWindow::embeddedNativeParentHandleProperty).isValid() #if QT_CONFIG(opengl) // /QTBUG-62901, EnableNonClientDpiScaling has problems with GL @@ -1288,8 +1291,12 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, d->m_creationContext->obtainedPos = QPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); return true; case QtWindows::NonClientCreate: - if (shouldHaveNonClientDpiScaling(d->m_creationContext->window)) - enableNonClientDpiScaling(msg.hwnd); + if (shouldHaveNonClientDpiScaling(d->m_creationContext->window) && + // DPI aware V2 processes always have NonClientDpiScaling enabled + // and there is no need to make an API call to manually enable. + !QWindowsContextPrivate::m_v2DpiAware) { + enableNonClientDpiScaling(msg.hwnd); + } return false; case QtWindows::CalculateSize: return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->customMargins, msg, result);