From 602bd9873786ccadcb67da3036329f3122555cf8 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 21 May 2013 15:09:28 +0200 Subject: Make QWindow update its screen when moved to a different one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also implements the Cocoa backend for that. Change-Id: I32977e12a04e1cf48b12333442482746c69ce133 Reviewed-by: Samuel Rødal Reviewed-by: Gunnar Sletta --- src/gui/kernel/qguiapplication.cpp | 13 ++++++++++++ src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qwindow.cpp | 34 ++++++++++++++++++------------- src/gui/kernel/qwindow_p.h | 2 ++ src/gui/kernel/qwindowsysteminterface.cpp | 7 +++++++ src/gui/kernel/qwindowsysteminterface.h | 1 + src/gui/kernel/qwindowsysteminterface_p.h | 13 +++++++++++- 7 files changed, 56 insertions(+), 15 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3c79e62e75..2a1d7e3bcc 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1285,6 +1285,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv case QWindowSystemInterfacePrivate::WindowStateChanged: QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast(e)); break; + case QWindowSystemInterfacePrivate::WindowScreenChanged: + QGuiApplicationPrivate::processWindowScreenChangedEvent(static_cast(e)); + break; case QWindowSystemInterfacePrivate::ApplicationStateChanged: QGuiApplicationPrivate::processApplicationStateChangedEvent(static_cast(e)); break; @@ -1655,6 +1658,16 @@ void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfa } } +void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse) +{ + if (QWindow *window = wse->window.data()) { + if (QScreen *screen = wse->screen.data()) + window->d_func()->setScreen(screen, false /* recreate */); + else // Fall back to default behavior, and try to find some appropriate screen + window->setScreen(0); + } +} + void QGuiApplicationPrivate::processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e) { if (e->newState == applicationState) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 376890ef47..cd8dfff103 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -126,6 +126,7 @@ public: static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e); static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e); + static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e); static void processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 918c2e0b97..68ba1901c1 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -345,6 +345,25 @@ void QWindowPrivate::updateVisibility() emit q->visibilityChanged(visibility); } +void QWindowPrivate::setScreen(QScreen *newScreen, bool recreate) +{ + Q_Q(QWindow); + if (newScreen != q->screen()) { + const bool shouldRecreate = recreate && platformWindow != 0; + if (shouldRecreate) + q->destroy(); + if (screen) + q->disconnect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*))); + screen = newScreen; + if (newScreen) { + q->connect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*))); + if (shouldRecreate) + q->create(); + } + emit q->screenChanged(newScreen); + } +} + /*! Sets the \a surfaceType of the window. @@ -1568,20 +1587,7 @@ void QWindow::setScreen(QScreen *newScreen) Q_D(QWindow); if (!newScreen) newScreen = QGuiApplication::primaryScreen(); - if (newScreen != screen()) { - const bool wasCreated = d->platformWindow != 0; - if (wasCreated) - destroy(); - if (d->screen) - disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*))); - d->screen = newScreen; - if (newScreen) { - connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*))); - if (wasCreated) - create(); - } - emit screenChanged(newScreen); - } + d->setScreen(newScreen, true /* recreate */); } void QWindow::screenDestroyed(QObject *object) diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index ea2cb722ab..f43c1ea8ec 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -127,6 +127,8 @@ public: void updateVisibility(); void _q_clearAlert(); + void setScreen(QScreen *newScreen, bool recreate); + QWindow::SurfaceType surfaceType; Qt::WindowFlags windowFlags; QWindow *parentWindow; diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 7dc1e7f7e5..6fc63fe96c 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -126,6 +126,13 @@ void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowSt QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } +void QWindowSystemInterface::handleWindowScreenChanged(QWindow *tlw, QScreen *screen) +{ + QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e = + new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(tlw, screen); + QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); +} + void QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState newState) { Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)); diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 521c2a4941..b0327701bb 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -138,6 +138,7 @@ public: static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason); static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState); + static void handleWindowScreenChanged(QWindow *w, QScreen *newScreen); static void handleApplicationStateChanged(Qt::ApplicationState newState); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index a6ea15c5f2..c4968f8ca6 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -91,7 +91,8 @@ public: PlatformPanel = UserInputEvent | 0x17, ContextMenu = UserInputEvent | 0x18, ApplicationStateChanged = 0x19, - FlushEvents = 0x20 + FlushEvents = 0x20, + WindowScreenChanged = 0x21 }; class WindowSystemEvent { @@ -158,6 +159,16 @@ public: Qt::WindowState newState; }; + class WindowScreenChangedEvent : public WindowSystemEvent { + public: + WindowScreenChangedEvent(QWindow *w, QScreen *s) + : WindowSystemEvent(WindowScreenChanged), window(w), screen(s) + { } + + QPointer window; + QPointer screen; + }; + class ApplicationStateChangedEvent : public WindowSystemEvent { public: ApplicationStateChangedEvent(Qt::ApplicationState newState) -- cgit v1.2.3