From e14fe5f84843da3390bc13a8f057527fc2664e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Keller?= Date: Mon, 17 Apr 2023 16:20:09 +0200 Subject: [PATCH] Windows QPA: Change monitor index detection Monitor index detection changed from comparing deviceNames to comparing serialNumbers, to prevent the case where two monitors with identical names might overwrite one another. Fixes: QTBUG-112829 Change-Id: Ibfad08e178774396c4b347acfcfbdb83ed4fe332 Reviewed-by: Oliver Wolff (cherry picked from commit f4d6d04898bcc239f4b271330ba778de69bbd893) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowsscreen.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 6b85a68f69b..2168e00605b 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -695,19 +695,19 @@ bool QWindowsScreenManager::isSingleScreen() } static inline int indexOfMonitor(const QWindowsScreenManager::WindowsScreenList &screens, - const QString &deviceName) + const QString &serialNumberIn) { - for (int i= 0; i < screens.size(); ++i) - if (screens.at(i)->data().deviceName == deviceName) + for (int i = 0; i < screens.size(); ++i) + if (screens.at(i)->data().serialNumber == serialNumberIn) return i; return -1; } static inline int indexOfMonitor(const WindowsScreenDataList &screenData, - const QString &deviceName) + const QString &serialNumberIn) { for (int i = 0; i < screenData.size(); ++i) - if (screenData.at(i).deviceName == deviceName) + if (screenData.at(i).serialNumber == serialNumberIn) return i; return -1; } @@ -773,7 +773,7 @@ bool QWindowsScreenManager::handleScreenChanges() const bool lockScreen = newDataList.size() == 1 && (newDataList.front().flags & QWindowsScreenData::LockScreen); bool primaryScreenChanged = false; for (const QWindowsScreenData &newData : newDataList) { - const int existingIndex = indexOfMonitor(m_screens, newData.deviceName); + const int existingIndex = indexOfMonitor(m_screens, newData.serialNumber); if (existingIndex != -1) { m_screens.at(existingIndex)->handleChanges(newData); if (existingIndex == 0) @@ -790,7 +790,7 @@ bool QWindowsScreenManager::handleScreenChanges() // temporary lock screen to avoid window recreation (QTBUG-33062). if (!lockScreen) { for (int i = m_screens.size() - 1; i >= 0; --i) { - if (indexOfMonitor(newDataList, m_screens.at(i)->data().deviceName) == -1) + if (indexOfMonitor(newDataList, m_screens.at(i)->data().serialNumber) == -1) removeScreen(i); } // for existing screens } // not lock screen