summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2021-09-23 16:28:55 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-12 16:37:41 +0000
commit64148e8d363adcea59ee15cc7b726ead21574d0c (patch)
tree30c281790f7e420f56f7a177a058807182a115f3
parente799b890bba0490c18627ebd718086d97ec6956a (diff)
Move VM_DPICHANGE handling to QWindowsWindow
We want to have as little code in the QWindowsContext event switch as possible. Change-Id: I04d578aae81c4ee804310a70bd87ee60b2890b6a Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit cd96d870118d15734a61a019f69ef5f0269bbe05) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp31
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp27
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h1
3 files changed, 30 insertions, 29 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index bbdf1ad692..91fb80dc28 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -1453,36 +1453,9 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
return true;
#endif
} break;
- case QtWindows::DpiChangedEvent: {
-
- const UINT dpi = HIWORD(wParam);
- const qreal scale = qreal(dpi) / qreal(platformWindow->savedDpi());
- platformWindow->setSavedDpi(dpi);
-
- // Send screen change first, so that the new sceen is set during any following resize
- platformWindow->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.
- platformWindow->updateFullFrameMargins();
- const auto prcNewWindow = reinterpret_cast<RECT *>(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 : platformWindow->window()->findChildren<QWindow *>()) {
- QWindowsWindow *platformChildWindow = static_cast<QWindowsWindow *>(childWindow->handle());
- if (!platformChildWindow)
- continue;
- QRect currentGeometry = platformChildWindow->geometry();
- QRect scaledGeometry = QRect(currentGeometry.topLeft() * scale, currentGeometry.size() * scale);
- platformChildWindow->setGeometry(scaledGeometry);
- }
-
+ case QtWindows::DpiChangedEvent:
+ platformWindow->handleDpiChanged(hwnd, wParam, lParam);
return true;
- }
#if QT_CONFIG(sessionmanager)
case QtWindows::QueryEndSessionApplicationEvent: {
QWindowsSessionManager *sessionManager = platformSessionManager();
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 7e322bf5f3..bbe19e4fcc 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<RECT *>(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<QWindow *>()) {
+ QWindowsWindow *platformChildWindow = static_cast<QWindowsWindow *>(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;
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index ea170aeee1..14c5f47853 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -318,6 +318,7 @@ public:
void handleResized(int wParam);
void handleHidden();
void handleCompositionSettingsChanged();
+ void handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam);
static void displayChanged();
static void settingsChanged();