summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmwindowstack.h
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-07-25 10:43:07 +0200
committerMikołaj Boc <Mikolaj.Boc@qt.io>2022-08-16 16:08:38 +0000
commit1007964f2d571d5a864015846025bb35c6d79ec2 (patch)
tree4fb525ad4e4305e6282b47bec511e6696a6401c4 /src/plugins/platforms/wasm/qwasmwindowstack.h
parent878328c6ab0367b7e7c1762d7f495b2c00c32496 (diff)
Maintain the window z-order properly in wasm compositor
The old stack structure used to keep track of windows has been improved to conform to the actual windowing assumptions: there shall be one root window, which is always at the bottom. The first created window immediately becomes the root window. Should the root window be removed, all windows are non-root, i.e. any of them can become the top-level window Fixes: QTBUG-105094 Pick-to: 6.4 Change-Id: Ic553244fa9f5bc3ee590b702935e66cfc62d5f8f Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmwindowstack.h')
-rw-r--r--src/plugins/platforms/wasm/qwasmwindowstack.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasmwindowstack.h b/src/plugins/platforms/wasm/qwasmwindowstack.h
new file mode 100644
index 00000000000..68ce4a51b74
--- /dev/null
+++ b/src/plugins/platforms/wasm/qwasmwindowstack.h
@@ -0,0 +1,70 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef QWASMWINDOWSTACK_H
+#define QWASMWINDOWSTACK_H
+
+#include <qglobal.h>
+#include <QtCore/qlist.h>
+
+#include <vector>
+
+QT_BEGIN_NAMESPACE
+
+class QWasmWindow;
+
+// Maintains a z-order hierarchy for a set of windows. The first added window is always treated as
+// the 'root', which always stays at the bottom. Other windows are 'regular', which means they are
+// subject to z-order changes via |raise| and |lower|/
+// If the root is ever removed, all of the current and future windows in the stack are treated as
+// regular.
+// Access to the top element is facilitated by |topWindow|.
+// Changes to the top element are signaled via the |topWindowChangedCallback| supplied at
+// construction.
+Q_AUTOTEST_EXPORT class QWasmWasmWindowStack
+{
+public:
+ using TopWindowChangedCallbackType = std::function<void(QWasmWindow *window)>;
+
+ using StorageType = QList<QWasmWindow *>;
+
+ using iterator = StorageType::reverse_iterator;
+ using const_iterator = StorageType::const_reverse_iterator;
+ using const_reverse_iterator = StorageType::const_iterator;
+
+ explicit QWasmWasmWindowStack(TopWindowChangedCallbackType topWindowChangedCallback);
+ ~QWasmWasmWindowStack();
+
+ void pushWindow(QWasmWindow *window);
+ void removeWindow(QWasmWindow *window);
+ void raise(QWasmWindow *window);
+ void lower(QWasmWindow *window);
+
+ // Iterates top-to-bottom
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ // Iterates bottom-to-top
+ const_reverse_iterator rbegin() const;
+ const_reverse_iterator rend() const;
+
+ bool empty() const;
+ size_t size() const;
+ QWasmWindow *topWindow() const;
+
+private:
+ enum class FirstWindowTreatment { AlwaysAtBottom, Regular };
+
+ QWasmWindow *rootWindow() const;
+ StorageType::iterator regularWindowsBegin();
+
+ TopWindowChangedCallbackType m_topWindowChangedCallback;
+ QList<QWasmWindow *> m_windowStack;
+ FirstWindowTreatment m_firstWindowTreatment = FirstWindowTreatment::AlwaysAtBottom;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMWINDOWSTACK_H