Blame SOURCES/qtwayland-client-expose-toplevel-window-state.patch

b814f0
From d533901938a996367d7b6f87b0214f5a17098aed Mon Sep 17 00:00:00 2001
b814f0
From: Jan Grulich <jgrulich@redhat.com>
b814f0
Date: Tue, 23 Mar 2021 16:03:22 +0100
b814f0
Subject: [PATCH] Client: expose toplevel window state
b814f0
b814f0
QWaylandWindow has only basic information about window state, like if
b814f0
it's active or maximized, but it has no information about tiling, which
b814f0
can be useful for client-side decorations. We also need to bump version
b814f0
of xdg-shell protocol we support, because additional states are not in
b814f0
the version currently supported by QtWayland. It shouldn't be a problem
b814f0
to increase the version as the new version adds just these additional
b814f0
window states.
b814f0
b814f0
Change-Id: I4c46516d9c7296c69ea51a022b3bdb4ca06bef8d
b814f0
Reviewed-by: David Edmundson <davidedmundson@kde.org>
b814f0
---
b814f0
 src/client/qwaylandwindow.cpp                    | 15 +++++++++++++++
b814f0
 src/client/qwaylandwindow_p.h                    | 16 ++++++++++++++++
b814f0
 .../xdg-shell/qwaylandxdgshell.cpp               | 16 +++++++++++++++-
b814f0
 .../xdg-shell/qwaylandxdgshell_p.h               |  3 ++-
b814f0
 4 files changed, 48 insertions(+), 2 deletions(-)
b814f0
b814f0
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
b814f0
index ba881cb..a1e891d 100644
b814f0
--- a/src/client/qwaylandwindow.cpp
b814f0
+++ b/src/client/qwaylandwindow.cpp
b814f0
@@ -1089,6 +1089,16 @@ Qt::WindowStates QWaylandWindow::windowStates() const
b814f0
     return mLastReportedWindowStates;
b814f0
 }
b814f0
b814f0
+QWaylandWindow::ToplevelWindowTilingStates QWaylandWindow::toplevelWindowTilingStates() const
b814f0
+{
b814f0
+    return mLastReportedToplevelWindowTilingStates;
b814f0
+}
b814f0
+
b814f0
+void QWaylandWindow::handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states)
b814f0
+{
b814f0
+    mLastReportedToplevelWindowTilingStates = states;
b814f0
+}
b814f0
+
b814f0
 void QWaylandWindow::handleWindowStatesChanged(Qt::WindowStates states)
b814f0
 {
b814f0
     createDecoration();
b814f0
diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
b814f0
index e068796..f4e5d3d 100644
b814f0
--- a/src/client/qwaylandwindow_p.h
b814f0
+++ b/src/client/qwaylandwindow_p.h
b814f0
@@ -95,6 +95,15 @@ public:
b814f0
         Vulkan
b814f0
     };
b814f0
b814f0
+    enum ToplevelWindowTilingState {
b814f0
+        WindowNoState = 0,
b814f0
+        WindowTiledLeft = 1,
b814f0
+        WindowTiledRight = 2,
b814f0
+        WindowTiledTop = 4,
b814f0
+        WindowTiledBottom = 8
b814f0
+    };
b814f0
+    Q_DECLARE_FLAGS(ToplevelWindowTilingStates, ToplevelWindowTilingState)
b814f0
+
b814f0
     QWaylandWindow(QWindow *window, QWaylandDisplay *display);
b814f0
     ~QWaylandWindow() override;
b814f0
b814f0
@@ -145,6 +154,9 @@ public:
b814f0
     void handleContentOrientationChange(Qt::ScreenOrientation orientation) override;
b814f0
     void setOrientationMask(Qt::ScreenOrientations mask);
b814f0
b814f0
+    ToplevelWindowTilingStates toplevelWindowTilingStates() const;
b814f0
+    void handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states);
b814f0
+
b814f0
     void setWindowState(Qt::WindowStates states) override;
b814f0
     void setWindowFlags(Qt::WindowFlags flags) override;
b814f0
     void handleWindowStatesChanged(Qt::WindowStates states);
b814f0
@@ -257,6 +269,7 @@ protected:
b814f0
     QRegion mMask;
b814f0
     QRegion mOpaqueArea;
b814f0
     Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState;
b814f0
+    ToplevelWindowTilingStates mLastReportedToplevelWindowTilingStates = WindowNoState;
b814f0
b814f0
     QWaylandShmBackingStore *mBackingStore = nullptr;
b814f0
     QWaylandBuffer *mQueuedBuffer = nullptr;
b814f0
@@ -293,6 +306,8 @@ private:
b814f0
     friend class QWaylandSubSurface;
b814f0
 };
b814f0
b814f0
+Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandWindow::ToplevelWindowTilingStates)
b814f0
+
b814f0
 inline QIcon QWaylandWindow::windowIcon() const
b814f0
 {
b814f0
     return mWindowIcon;
b814f0
diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
b814f0
index d7d0ddf..2c6e84b 100644
b814f0
--- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
b814f0
+++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
b814f0
@@ -88,6 +88,7 @@ void QWaylandXdgSurface::Toplevel::applyConfigure()
b814f0
         && !m_xdgSurface->m_window->display()->isKeyboardAvailable())
b814f0
         m_xdgSurface->m_window->display()->handleWindowDeactivated(m_xdgSurface->m_window);
b814f0
b814f0
+    m_xdgSurface->m_window->handleToplevelWindowTilingStatesChanged(m_toplevelStates);
b814f0
     m_xdgSurface->m_window->handleWindowStatesChanged(m_pending.states);
b814f0
b814f0
     if (m_pending.size.isEmpty()) {
b814f0
@@ -120,6 +121,7 @@ void QWaylandXdgSurface::Toplevel::xdg_toplevel_configure(int32_t width, int32_t
b814f0
     size_t numStates = states->size / sizeof(uint32_t);
b814f0
b814f0
     m_pending.states = Qt::WindowNoState;
b814f0
+    m_toplevelStates = QWaylandWindow::WindowNoState;
b814f0
b814f0
     for (size_t i = 0; i < numStates; i++) {
b814f0
         switch (xdgStates[i]) {
b814f0
@@ -132,6 +134,18 @@ void QWaylandXdgSurface::Toplevel::xdg_toplevel_configure(int32_t width, int32_t
b814f0
         case XDG_TOPLEVEL_STATE_FULLSCREEN:
b814f0
             m_pending.states |= Qt::WindowFullScreen;
b814f0
             break;
b814f0
+        case XDG_TOPLEVEL_STATE_TILED_LEFT:
b814f0
+            m_toplevelStates |= QWaylandWindow::WindowTiledLeft;
b814f0
+            break;
b814f0
+        case XDG_TOPLEVEL_STATE_TILED_RIGHT:
b814f0
+            m_toplevelStates |= QWaylandWindow::WindowTiledRight;
b814f0
+            break;
b814f0
+        case XDG_TOPLEVEL_STATE_TILED_TOP:
b814f0
+            m_toplevelStates |= QWaylandWindow::WindowTiledTop;
b814f0
+            break;
b814f0
+        case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
b814f0
+            m_toplevelStates |= QWaylandWindow::WindowTiledBottom;
b814f0
+            break;
b814f0
         default:
b814f0
             break;
b814f0
         }
b814f0
@@ -451,7 +465,7 @@ void QWaylandXdgSurface::xdg_surface_configure(uint32_t serial)
b814f0
 }
b814f0
b814f0
 QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion)
b814f0
-    : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 1u))
b814f0
+    : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 2u))
b814f0
     , m_display(display)
b814f0
 {
b814f0
     display->addRegistryListener(&QWaylandXdgShell::handleRegistryGlobal, this);
b814f0
diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
b814f0
index 0c98be3..d791213 100644
b814f0
--- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
b814f0
+++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
b814f0
@@ -58,6 +58,7 @@
b814f0
b814f0
 #include <QtWaylandClient/qtwaylandclientglobal.h>
b814f0
 #include <QtWaylandClient/private/qwaylandshellsurface_p.h>
b814f0
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
b814f0
b814f0
 #include <QtCore/QSize>
b814f0
 #include <QtGui/QRegion>
b814f0
@@ -69,7 +70,6 @@ class QWindow;
b814f0
 namespace QtWaylandClient {
b814f0
b814f0
 class QWaylandDisplay;
b814f0
-class QWaylandWindow;
b814f0
 class QWaylandInputDevice;
b814f0
 class QWaylandXdgShell;
b814f0
b814f0
@@ -123,6 +123,7 @@ private:
b814f0
             QSize size = {0, 0};
b814f0
             Qt::WindowStates states = Qt::WindowNoState;
b814f0
         }  m_pending, m_applied;
b814f0
+        QWaylandWindow::ToplevelWindowTilingStates m_toplevelStates = QWaylandWindow::WindowNoState;
b814f0
         QSize m_normalSize;
b814f0
b814f0
         QWaylandXdgSurface *m_xdgSurface = nullptr;