From 077eddb3e1aaba1517d67e7c83574c16e971dc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 13 Jun 2022 17:33:16 +0200 Subject: Windows QPA: Update screen on child window DPI change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows does not send WM_DPICHANGED to child windows, which means that the normal DPI change handling code does not run for QWindows which are embedded in a foreign, non-Qt, window. Add code which handles WM_DPICHANGED_AFTERPARENT. This event is sent to all child windows, but not the top-level window. Call checkForScreenChanged() here, similar to what the WM_DPICHANGED code does. This commit does not add code to resize the child window, since it is uncertain if this is the responsibility of the window which receives WM_DPICHANGED, or of each child window. Done-with: Tor Arne Vestbø Pick-to: 6.4 Task-number: QTBUG-103383 Change-Id: Icf85dd0afa806609dbbe0ffc36efbc5127962c39 Reviewed-by: Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/windows/qwindowswindow.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (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 61d512a33f..c953abbc61 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2007,6 +2007,14 @@ void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam) } } +void QWindowsWindow::handleDpiChangedAfterParent(HWND hwnd) +{ + // FIXME: refactor, do we really need this? + setSavedDpi(GetDpiForWindow(hwnd)); + + checkForScreenChanged(QWindowsWindow::FromDpiChange); +} + static QRect normalFrameGeometry(HWND hwnd) { WINDOWPLACEMENT wp; @@ -2150,12 +2158,14 @@ static inline bool equalDpi(const QDpi &d1, const QDpi &d2) void QWindowsWindow::checkForScreenChanged(ScreenChangeMode mode) { - if (parent() || QWindowsScreenManager::isSingleScreen()) + if ((parent() && !parent()->isForeignWindow()) || QWindowsScreenManager::isSingleScreen()) return; QPlatformScreen *currentScreen = screen(); + auto topLevel = isTopLevel_sys() ? m_data.hwnd : GetAncestor(m_data.hwnd, GA_ROOT); const QWindowsScreen *newScreen = - QWindowsContext::instance()->screenManager().screenForHwnd(m_data.hwnd); + QWindowsContext::instance()->screenManager().screenForHwnd(topLevel); + if (newScreen == nullptr || newScreen == currentScreen) return; // For screens with different DPI: postpone until WM_DPICHANGE -- cgit v1.2.3