From cd96d870118d15734a61a019f69ef5f0269bbe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 23 Sep 2021 16:28:55 +0200 Subject: Move VM_DPICHANGE handling to QWindowsWindow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to have as little code in the QWindowsContext event switch as possible. Pick-to: 6.2 Change-Id: I04d578aae81c4ee804310a70bd87ee60b2890b6a Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/windows/qwindowswindow.cpp | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/plugins/platforms/windows/qwindowswindow.cpp') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index bbbf261273..3c64ae1a35 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1833,6 +1833,33 @@ void QWindowsWindow::handleCompositionSettingsChanged() } } +void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + const UINT dpi = HIWORD(wParam); + const qreal scale = qreal(dpi) / qreal(savedDpi()); + setSavedDpi(dpi); + + // Send screen change first, so that the new sceen is set during any following resize + checkForScreenChanged(QWindowsWindow::FromDpiChange); + + // Apply the suggested window geometry to the native window. This will make + // sure the window tracks the mouse cursor during screen change, and also + // that the window size is scaled according to the DPI change. + updateFullFrameMargins(); + const auto prcNewWindow = reinterpret_cast(lParam); + SetWindowPos(hwnd, nullptr, prcNewWindow->left, prcNewWindow->top, + prcNewWindow->right - prcNewWindow->left, + prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE); + + // Scale child QPlatformWindow size. Windows sends WM_DPICHANGE to top-level windows only. + for (QWindow *childWindow : window()->findChildren()) { + QWindowsWindow *platformChildWindow = static_cast(childWindow->handle()); + QRect currentGeometry = platformChildWindow->geometry(); + QRect scaledGeometry = QRect(currentGeometry.topLeft() * scale, currentGeometry.size() * scale); + platformChildWindow->setGeometry(scaledGeometry); + } +} + static QRect normalFrameGeometry(HWND hwnd) { WINDOWPLACEMENT wp; -- cgit v1.2.3