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 <oliver.wolff@qt.io>
(cherry picked from commit f4d6d04898bcc239f4b271330ba778de69bbd893)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Timothée Keller 2023-04-17 16:20:09 +02:00 committed by Qt Cherry-pick Bot
parent 4139b6d029
commit e14fe5f848

View File

@ -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