diff options
author | Morteza Jamshidi <[email protected]> | 2025-06-16 16:12:16 +0200 |
---|---|---|
committer | Morteza Jamshidi <[email protected]> | 2025-07-01 09:59:28 +0000 |
commit | a264d099fbcf7587f068bd582e2fc61a28850e41 (patch) | |
tree | c558d0f2122d23a9ff3ca0025dacf5851b0e1c2b /src | |
parent | b9cd3e08d98ef70c5423c0053aab7fc229e206c3 (diff) |
Windows: Check for screen changes for each window after adding screen6.10
When a new screen is attached Window might move windows to the new
screen automatically, in which case they will get a WM_DPICHANGED
event. But at that point we have not received WM_DISPLAYCHANGE yet,
so we fail to reflect the new screen's DPI.
To account for this we explicitly check for screen change after adding
a new screen.
Fixes: QTBUG-125319
Change-Id: Ic854fe9f9ae52f53bb34cb8434111a6a1ba032d2
Reviewed-by: Tor Arne Vestbø <[email protected]>
(cherry picked from commit 78a0018c86b98a63ccb13f61d4a33e94c3f053cc)
Reviewed-by: Oliver Wolff <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.cpp | 30 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 2 |
3 files changed, 26 insertions, 7 deletions
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index ddc1114485e..57b833b299b 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -762,6 +762,28 @@ static void moveToVirtualScreen(QWindow *w, const QScreen *newScreen) w->setGeometry(geometry); } +void QWindowsScreenManager::addScreen(const QWindowsScreenData &screenData) +{ + auto *newScreen = new QWindowsScreen(screenData); + m_screens.push_back(newScreen); + QWindowSystemInterface::handleScreenAdded(newScreen, + screenData.flags & QWindowsScreenData::PrimaryScreen); + qCDebug(lcQpaScreen) << "New Monitor: " << screenData; + + // When a new screen is attached Window might move windows to the new screen + // automatically, in which case they will get a WM_DPICHANGED event. But at + // that point we have not received WM_DISPLAYCHANGE yet, so we fail to reflect + // the new screen's DPI. To account for this we explicitly check for screen + // change here, now that we are processing the WM_DISPLAYCHANGE. + const auto allWindows = QGuiApplication::allWindows(); + for (QWindow *w : allWindows) { + if (w->isVisible() && w->handle() && w->type() != Qt::Desktop) { + if (QWindowsWindow *window = QWindowsWindow::windowsWindowOf(w)) + window->checkForScreenChanged(QWindowsWindow::ScreenChangeMode::FromScreenAdded); + } + } +} + void QWindowsScreenManager::removeScreen(int index) { qCDebug(lcQpaScreen) << "Removing Monitor:" << m_screens.at(index)->data(); @@ -784,7 +806,7 @@ void QWindowsScreenManager::removeScreen(int index) && (QWindowsWindow::baseWindowOf(w)->exStyle() & WS_EX_TOOLWINDOW)) { moveToVirtualScreen(w, primaryScreen); } else { - QWindowSystemInterface::handleWindowScreenChanged(w, primaryScreen); + QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(w, primaryScreen); } ++movedWindowCount; } @@ -813,11 +835,7 @@ bool QWindowsScreenManager::handleScreenChanges() if (existingIndex == 0) primaryScreenChanged = true; } else { - auto *newScreen = new QWindowsScreen(newData); - m_screens.push_back(newScreen); - QWindowSystemInterface::handleScreenAdded(newScreen, - newData.flags & QWindowsScreenData::PrimaryScreen); - qCDebug(lcQpaScreen) << "New Monitor: " << newData; + addScreen(newData); } // exists } // for new screens. // Remove deleted ones but keep main monitors if we get only the diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h index ea6a29efe38..8d555998388 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.h +++ b/src/plugins/platforms/windows/qwindowsscreen.h @@ -119,6 +119,7 @@ public: static bool isSingleScreen(); private: + void addScreen(const QWindowsScreenData &screenData); void removeScreen(int index); HWND m_displayChangeObserver = nullptr; diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 424848503be..b67bd2850b3 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -342,7 +342,7 @@ public: void alertWindow(int durationMs = 0); void stopAlertWindow(); - enum ScreenChangeMode { FromGeometryChange, FromDpiChange }; + enum ScreenChangeMode { FromGeometryChange, FromDpiChange, FromScreenAdded }; void checkForScreenChanged(ScreenChangeMode mode = FromGeometryChange); void registerTouchWindow(); |