From 9ae215925159f4e8f1a88fc6691c916eead67539 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 14 Nov 2012 12:22:19 +0200 Subject: [PATCH] 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 --- src/plugins/platforms/windows/qwindowsscreen.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 0717a8ec60..a09ab583c8 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -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); - result->append(data); + 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; }