Restore the visibility of a moved QWindow in QWindow::screenDestroyed
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>
Thu, 29 Nov 2012 15:25:59 +0000 (16:25 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 30 Nov 2012 17:28:10 +0000 (18:28 +0100)
QWindow::screenDestroyed triggers an move of the window to the primary
screen. This causes the screen to be destroyed and shown again on the
new QScreen.

The issue is that QWindow::destroy() hides the window but create()
doesn't set it visible, and this ultimately causes any QWindow to be
automatically hidden when their QScreen is destroyed.

As stated in the comment, it could be the intended behavior that
windows aren't shown automatically on a remaining screen like when
using two screens not logically part of the same desktop. Once the
platform plugins have access to an API allowing them to adjust the
screens of their QWindow, this patch shouldn't be needed anymore.

Change-Id: I7628377c969f79f9eebb3deabaf0470542d68a9c
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
src/gui/kernel/qwindow.cpp

index 24ba92f..c24609e 100644 (file)
@@ -1388,8 +1388,16 @@ void QWindow::setScreen(QScreen *newScreen)
 void QWindow::screenDestroyed(QObject *object)
 {
     Q_D(QWindow);
-    if (object == static_cast<QObject *>(d->screen))
+    if (object == static_cast<QObject *>(d->screen)) {
+        const bool wasVisible = isVisible();
         setScreen(0);
+        // destroy() might have hidden our window, show it again.
+        // This might not be the best behavior if the new screen isn't a virtual sibling
+        // of the old one. This can be removed once platform plugins have the power to
+        // update the QScreen of its QWindows itself.
+        if (wasVisible && d->platformWindow)
+            setVisible(true);
+    }
 }
 
 /*!