Fix QApplication::primaryScreen() in Windows

QPlatformInterface::screenAdded() documentation specifies that first
added screen will be the primary screen, so we need to ensure that
the screen Windows reports as the main display gets added first.

Task-number: QTBUG-27988
Change-Id: Ibc17b05a6c37007ff749fb54ab62d47ffa40f8ac
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Miikka Heikkinen 2012-11-14 12:22:19 +02:00 committed by The Qt Project
parent e4c2a5c29f
commit 9ae2159251

View File

@ -125,11 +125,19 @@ BOOL QT_WIN_CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM
Qt::PortraitOrientation : Qt::LandscapeOrientation;
// EnumDisplayMonitors (as opposed to EnumDisplayDevices) enumerates only
// virtual desktop screens.
data.flags = QWindowsScreenData::VirtualDesktop;
if (info.dwFlags & MONITORINFOF_PRIMARY)
data.flags |= QWindowsScreenData::PrimaryScreen;
data.name = QString::fromWCharArray(info.szDevice);
data.flags = QWindowsScreenData::VirtualDesktop;
if (info.dwFlags & MONITORINFOF_PRIMARY) {
data.flags |= QWindowsScreenData::PrimaryScreen;
// QPlatformIntegration::screenAdded() documentation specifies that first
// added screen will be the primary screen, so order accordingly.
// Note that the side effect of this policy is that there is no way to change primary
// screen reported by Qt, unless we want to delete all existing screens and add them
// again whenever primary screen changes.
result->prepend(data);
} else {
result->append(data);
}
return TRUE;
}