summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-05-21 15:09:28 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-23 12:49:39 +0200
commit602bd9873786ccadcb67da3036329f3122555cf8 (patch)
tree49cee7b06178f5e3b514bdd82e34d900325a3cf5 /src/gui/kernel
parentf610814b058b4639ef0d4d2592a8bcc3f81c974d (diff)
Make QWindow update its screen when moved to a different one
Also implements the Cocoa backend for that. Change-Id: I32977e12a04e1cf48b12333442482746c69ce133 Reviewed-by: Samuel Rødal <samuel.rodal@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp13
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--src/gui/kernel/qwindow.cpp34
-rw-r--r--src/gui/kernel/qwindow_p.h2
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp7
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h1
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h13
7 files changed, 56 insertions, 15 deletions
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<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
break;
+ case QWindowSystemInterfacePrivate::WindowScreenChanged:
+ QGuiApplicationPrivate::processWindowScreenChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
+ break;
case QWindowSystemInterfacePrivate::ApplicationStateChanged:
QGuiApplicationPrivate::processApplicationStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(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<QWindow> window;
+ QPointer<QScreen> screen;
+ };
+
class ApplicationStateChangedEvent : public WindowSystemEvent {
public:
ApplicationStateChangedEvent(Qt::ApplicationState newState)