QPlatformWindow: change API for QPlatformWindow::setWindowState
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>
Tue, 9 Oct 2012 08:52:44 +0000 (10:52 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 17 Oct 2012 07:39:01 +0000 (09:39 +0200)
The current implementation requests the platform window to set
the window state if it can, and return the actual window state
back.

The problem with this approach is that the platform window is created
as late as possible, so a call to QWindow::setWindowState would in
many (most?) cases never be forwarded to the platform window (instead,
the platform window is responsible to check the current window state
upon creation). As such, the window state might be left unsynched with
the platform window.

This patch suggests removing the return value from
QPlatformWindow::setWindowState. This will at least be consistent, so
that setting/getting state would produce the same result independent of
delayed window creation. If needed, we can later add new API to
QPlatformIntegration or QPlatformWindow for querying supported/actual
window state.

Change-Id: Ie43f56169656854a765ce88b47a808f8f3d51bb4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
15 files changed:
src/gui/kernel/qplatformwindow.cpp
src/gui/kernel/qplatformwindow.h
src/gui/kernel/qwindow.cpp
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm
src/plugins/platforms/eglfs/qeglfswindow.cpp
src/plugins/platforms/eglfs/qeglfswindow.h
src/plugins/platforms/qnx/qqnxwindow.cpp
src/plugins/platforms/qnx/qqnxwindow.h
src/plugins/platforms/windows/qwindowswindow.cpp
src/plugins/platforms/windows/qwindowswindow.h
src/plugins/platforms/xcb/qxcbwindow.cpp
src/plugins/platforms/xcb/qxcbwindow.h
src/widgets/kernel/qwidget_p.h
src/widgets/kernel/qwidget_qpa.cpp

index 27dfd7c..2bc6b01 100644 (file)
@@ -213,13 +213,12 @@ QPoint QPlatformWindow::mapFromGlobal(const QPoint &pos) const
 
 /*!
     Requests setting the window state of this surface
-    to \a type. Returns the actual state set.
+    to \a type.
 
     Qt::WindowActive can be ignored.
 */
-Qt::WindowState QPlatformWindow::setWindowState(Qt::WindowState)
+void QPlatformWindow::setWindowState(Qt::WindowState)
 {
-    return Qt::WindowNoState;
 }
 
 /*!
index 2b2d227..12650d6 100644 (file)
@@ -91,7 +91,7 @@ public:
 
     virtual void setVisible(bool visible);
     virtual void setWindowFlags(Qt::WindowFlags flags);
-    virtual Qt::WindowState setWindowState(Qt::WindowState state);
+    virtual void setWindowState(Qt::WindowState state);
 
     virtual WId winId() const;
     virtual void setParent(const QPlatformWindow *window);
index 39a6603..4f1610c 100644 (file)
@@ -828,9 +828,8 @@ void QWindow::setWindowState(Qt::WindowState state)
 
     Q_D(QWindow);
     if (d->platformWindow)
-        d->windowState = d->platformWindow->setWindowState(state);
-    else
-        d->windowState = state;
+        d->platformWindow->setWindowState(state);
+    d->windowState = state;
 }
 
 /*!
index 3c6dd96..d5dbe58 100644 (file)
@@ -99,7 +99,7 @@ public:
     void setCocoaGeometry(const QRect &rect);
     void setVisible(bool visible);
     void setWindowFlags(Qt::WindowFlags flags);
-    Qt::WindowState setWindowState(Qt::WindowState state);
+    void setWindowState(Qt::WindowState state);
     void setWindowTitle(const QString &title);
     void setWindowFilePath(const QString &filePath);
     void setWindowIcon(const QIcon &icon);
index c658a8d..93d566d 100644 (file)
@@ -400,12 +400,10 @@ void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
     m_windowFlags = flags;
 }
 
-Qt::WindowState QCocoaWindow::setWindowState(Qt::WindowState state)
+void QCocoaWindow::setWindowState(Qt::WindowState state)
 {
     if ([m_nsWindow isVisible])
         syncWindowState(state);  // Window state set for hidden windows take effect when show() is called.
-
-    return state;
 }
 
 void QCocoaWindow::setWindowTitle(const QString &title)
index 9822262..036b26a 100644 (file)
@@ -117,10 +117,9 @@ void QEglFSWindow::setGeometry(const QRect &)
     QPlatformWindow::setGeometry(rect);
 }
 
-Qt::WindowState QEglFSWindow::setWindowState(Qt::WindowState)
+void QEglFSWindow::setWindowState(Qt::WindowState)
 {
     setGeometry(QRect());
-    return Qt::WindowFullScreen;
 }
 
 WId QEglFSWindow::winId() const
index c9ef60a..40a38fc 100644 (file)
@@ -56,7 +56,7 @@ public:
     ~QEglFSWindow();
 
     void setGeometry(const QRect &);
-    Qt::WindowState setWindowState(Qt::WindowState state);
+    void setWindowState(Qt::WindowState state);
     WId winId() const;
 
     EGLSurface surface() const { return m_surface; }
index 9dd8ad7..097b578 100644 (file)
@@ -580,13 +580,13 @@ void QQnxWindow::requestActivateWindow()
 }
 
 
-Qt::WindowState QQnxWindow::setWindowState(Qt::WindowState state)
+void QQnxWindow::setWindowState(Qt::WindowState state)
 {
     qWindowDebug() << Q_FUNC_INFO << "state =" << state;
 
     // Prevent two calls with Qt::WindowFullScreen from changing m_unmaximizedGeometry
     if (m_windowState == state)
-        return state;
+        return;
 
     switch (state) {
 
@@ -594,7 +594,7 @@ Qt::WindowState QQnxWindow::setWindowState(Qt::WindowState state)
     // WindowActive is not an accepted parameter according to the docs
     case Qt::WindowMinimized:
     case Qt::WindowActive:
-        return m_windowState;
+        return;
 
     case Qt::WindowMaximized:
     case Qt::WindowFullScreen:
@@ -609,7 +609,6 @@ Qt::WindowState QQnxWindow::setWindowState(Qt::WindowState state)
     }
 
     m_windowState = state;
-    return state;
 }
 
 void QQnxWindow::gainedFocus()
index d79c678..90226bb 100644 (file)
@@ -101,7 +101,7 @@ public:
     void raise();
     void lower();
     void requestActivateWindow();
-    Qt::WindowState setWindowState(Qt::WindowState state);
+    void setWindowState(Qt::WindowState state);
 
     void gainedFocus();
 
index a31b09d..fc35666 100644 (file)
@@ -1235,13 +1235,12 @@ void QWindowsWindow::handleWindowStateChange(Qt::WindowState state)
     QWindowSystemInterface::handleWindowStateChanged(window(), state);
 }
 
-Qt::WindowState QWindowsWindow::setWindowState(Qt::WindowState state)
+void QWindowsWindow::setWindowState(Qt::WindowState state)
 {
     if (m_data.hwnd) {
         setWindowState_sys(state);
         m_windowState = state;
     }
-    return state;
 }
 
 bool QWindowsWindow::isFullScreen_sys() const
index 5d898a2..978d1d5 100644 (file)
@@ -160,7 +160,7 @@ public:
     virtual QPoint mapFromGlobal(const QPoint &pos) const;
 
     virtual void setWindowFlags(Qt::WindowFlags flags);
-    virtual Qt::WindowState setWindowState(Qt::WindowState state);
+    virtual void setWindowState(Qt::WindowState state);
 
     HWND handle() const { return m_data.hwnd; }
 
index cefe1a7..bab1884 100644 (file)
@@ -847,10 +847,10 @@ void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two)
     Q_XCB_CALL(xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
 }
 
-Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
+void QXcbWindow::setWindowState(Qt::WindowState state)
 {
     if (state == m_windowState)
-        return state;
+        return;
 
     // unset old state
     switch (m_windowState) {
@@ -905,7 +905,6 @@ Qt::WindowState QXcbWindow::setWindowState(Qt::WindowState state)
     connection()->sync();
 
     m_windowState = state;
-    return m_windowState;
 }
 
 void QXcbWindow::setNetWmWindowFlags(Qt::WindowFlags flags)
index e2f6240..bd4d18a 100644 (file)
@@ -82,7 +82,7 @@ public:
 
     void setVisible(bool visible);
     void setWindowFlags(Qt::WindowFlags flags);
-    Qt::WindowState setWindowState(Qt::WindowState state);
+    void setWindowState(Qt::WindowState state);
     WId winId() const;
     void setParent(const QPlatformWindow *window);
 
index c3a1d27..8aba276 100644 (file)
@@ -803,8 +803,6 @@ public:
     static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
     void registerTouchWindow(bool enable = true);
 #endif
-    void setMaxWindowState_helper();
-    void setFullScreenSize_helper();
     bool stealKeyboardGrab(bool grab);
     bool stealMouseGrab(bool grab);
 };
index e756426..2950c19 100644 (file)
@@ -586,33 +586,6 @@ void QWidgetPrivate::hide_sys()
         window->setVisible(false);
 }
 
-void QWidgetPrivate::setMaxWindowState_helper()
-{
-    Q_Q(QWidget);
-
-    const uint old_state = data.in_set_window_state;
-    data.in_set_window_state = 1;
-
-    const QRect desktop = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(q));
-    q->setGeometry(desktop);
-
-    data.in_set_window_state = old_state;
-}
-
-void QWidgetPrivate::setFullScreenSize_helper()
-{
-    Q_Q(QWidget);
-
-    const uint old_state = data.in_set_window_state;
-    data.in_set_window_state = 1;
-
-    const QRect screen = qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(q));
-    q->move(screen.topLeft());
-    q->resize(screen.size());
-
-    data.in_set_window_state = old_state;
-}
-
 Qt::WindowState effectiveState(Qt::WindowStates state)
  {
      if (state & Qt::WindowMinimized)
@@ -635,7 +608,6 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
 
     data->window_state = newstate;
     data->in_set_window_state = 1;
-    bool needShow = false;
     Qt::WindowState newEffectiveState = effectiveState(newstate);
     Qt::WindowState oldEffectiveState = effectiveState(oldstate);
     if (isWindow() && newEffectiveState != oldEffectiveState) {
@@ -649,54 +621,9 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
 
         Q_ASSERT(windowHandle());
         windowHandle()->setWindowState(newEffectiveState);
-        bool supported = windowHandle()->windowState() == newEffectiveState;
-
-        if (!supported) {
-            const bool wasResized = testAttribute(Qt::WA_Resized);
-            const bool wasMoved = testAttribute(Qt::WA_Moved);
-
-            // undo the effects of the old emulated state
-            if (oldEffectiveState == Qt::WindowFullScreen) {
-                setParent(0, d->topData()->savedFlags);
-                needShow = true;
-            } else if (oldEffectiveState == Qt::WindowMinimized) {
-                needShow = true;
-            }
-
-            // emulate the new window state
-            if (newEffectiveState == Qt::WindowMinimized) {
-                //### not ideal...
-                hide();
-                needShow = false;
-            } else if (newEffectiveState == Qt::WindowFullScreen) {
-                d->topData()->savedFlags = windowFlags();
-                setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint));
-                d->setFullScreenSize_helper();
-                raise();
-                needShow = true;
-            } else if (newEffectiveState == Qt::WindowMaximized) {
-                createWinId();
-                d->setMaxWindowState_helper();
-            } else if (newEffectiveState == Qt::WindowNoState) {
-                // reset old geometry
-                QRect r = d->topData()->normalGeometry;
-                if (r.width() >= 0) {
-                    d->topData()->normalGeometry = QRect(0,0,-1,-1);
-                    setGeometry(r);
-                }
-            }
-
-            // setWindowState() is not an explicit move/resize, same as the supported == true
-            // case
-            setAttribute(Qt::WA_Resized, wasResized);
-            setAttribute(Qt::WA_Moved, wasMoved);
-        }
     }
     data->in_set_window_state = 0;
 
-    if (needShow)
-        setVisible(true);
-
     if (newstate & Qt::WindowActive)
         activateWindow();