From 8cbaea441a8c9adea6ba804b76bf3bd1e79f77b7 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 4 Sep 2015 16:52:04 +0200 Subject: Notify when the primary screen changes Makes it possible to notify that the QGuiApplication::primaryScreen has changed. XCB backend adopts the new API, as it was accessing QGuiApplication private API directly. Change-Id: Icde05c44138265f865fa42d2cd6974c552fdc5e2 Task-number: QTBUG-38404 Task-number: QTBUG-40659 Reviewed-by: Frederik Gladhorn Reviewed-by: Shawn Rutledge --- src/gui/kernel/qplatformintegration.cpp | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel/qplatformintegration.cpp') diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index e935907a62..457a420148 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -456,6 +456,24 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps, bool isPrimary) QGuiApplicationPrivate::screen_list.append(screen); } emit qGuiApp->screenAdded(screen); + + if (isPrimary) + emit qGuiApp->primaryScreenChanged(screen); +} + +/*! + Just removes the screen, call destroyScreen instead. + + \sa destroyScreen() +*/ + +void QPlatformIntegration::removeScreen(QScreen *screen) +{ + const bool wasPrimary = (!QGuiApplicationPrivate::screen_list.isEmpty() && QGuiApplicationPrivate::screen_list[0] == screen); + QGuiApplicationPrivate::screen_list.removeOne(screen); + + if (wasPrimary && qGuiApp && !QGuiApplicationPrivate::screen_list.isEmpty()) + emit qGuiApp->primaryScreenChanged(QGuiApplicationPrivate::screen_list[0]); } /*! @@ -469,11 +487,30 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps, bool isPrimary) void QPlatformIntegration::destroyScreen(QPlatformScreen *screen) { QScreen *qScreen = screen->screen(); - QGuiApplicationPrivate::screen_list.removeOne(qScreen); + removeScreen(qScreen); delete qScreen; delete screen; } +/*! + Should be called whenever the primary screen changes. + + When the screen specified as primary changes, this method will notify + QGuiApplication and emit the QGuiApplication::primaryScreenChanged signal. + */ + +void QPlatformIntegration::setPrimaryScreen(QPlatformScreen *newPrimary) +{ + QScreen* newPrimaryScreen = newPrimary->screen(); + int idx = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen); + Q_ASSERT(idx >= 0); + if (idx == 0) + return; + + QGuiApplicationPrivate::screen_list.swap(0, idx); + emit qGuiApp->primaryScreenChanged(newPrimaryScreen); +} + QStringList QPlatformIntegration::themeNames() const { return QStringList(); -- cgit v1.2.3