summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2022-06-13 17:33:16 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-06-16 23:01:04 +0200
commit077eddb3e1aaba1517d67e7c83574c16e971dc67 (patch)
tree55234b906d04bf1a6e1b3a0b7a02b839300cdac8
parent7037f4620fb59b669d32fbce0ef79aabe38a716a (diff)
Windows QPA: Update screen on child window DPI change
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ø <tor.arne.vestbo@qt.io> Pick-to: 6.4 Task-number: QTBUG-103383 Change-Id: Icf85dd0afa806609dbbe0ffc36efbc5127962c39 Reviewed-by: <stefan.wastl@native-instruments.de> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/plugins/platforms/windows/qtwindowsglobal.h3
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp3
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp14
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h1
4 files changed, 19 insertions, 2 deletions
diff --git a/src/plugins/platforms/windows/qtwindowsglobal.h b/src/plugins/platforms/windows/qtwindowsglobal.h
index f16c4ff709..71a4269a27 100644
--- a/src/plugins/platforms/windows/qtwindowsglobal.h
+++ b/src/plugins/platforms/windows/qtwindowsglobal.h
@@ -106,6 +106,7 @@ enum WindowsEventType // Simplify event types
ExitSizeMoveEvent = WindowEventFlag + 23,
PointerActivateWindowEvent = WindowEventFlag + 24,
DpiScaledSizeEvent = WindowEventFlag + 25,
+ DpiChangedAfterParentEvent = WindowEventFlag + 27,
MouseEvent = MouseEventFlag + 1,
MouseWheelEvent = MouseEventFlag + 2,
CursorEvent = MouseEventFlag + 3,
@@ -292,6 +293,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
return HIWORD(wParamIn) ? QtWindows::AcceleratorCommandEvent : QtWindows::MenuCommandEvent;
case WM_DPICHANGED:
return QtWindows::DpiChangedEvent;
+ case WM_DPICHANGED_AFTERPARENT:
+ return QtWindows::DpiChangedAfterParentEvent;
case WM_GETDPISCALEDSIZE:
return QtWindows::DpiScaledSizeEvent;
case WM_ENTERSIZEMOVE:
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 6dece1a518..68d2e5d98d 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -1325,6 +1325,9 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
case QtWindows::DpiChangedEvent:
platformWindow->handleDpiChanged(hwnd, wParam, lParam);
return true;
+ case QtWindows::DpiChangedAfterParentEvent:
+ platformWindow->handleDpiChangedAfterParent(hwnd);
+ 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 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
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index 9ed6197eae..29dfbdb856 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -286,6 +286,7 @@ public:
void handleCompositionSettingsChanged();
void handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result);
void handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam);
+ void handleDpiChangedAfterParent(HWND hwnd);
static void displayChanged();
static void settingsChanged();