Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmwindowtreenode.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include "qwasmwindow.h"
7#include "qwasmscreen.h"
8
9uint64_t QWasmWindowTreeNode::s_nextActiveIndex = 0;
10
15
17
19{
21 if (!window ||
22 !window->window() ||
23 (QGuiApplication::focusWindow() && // Don't act if we have a focus window different from this
24 QGuiApplication::focusWindow() != window->window()))
25 return;
26
27 // Make a list of all windows sorted on active index.
28 // Skip windows with active index 0 as they have
29 // never been active.
30 std::map<uint64_t, QWasmWindow *> allWindows;
31 for (const auto &w : window->platformScreen()->allWindows()) {
32 if (w->getActiveIndex() > 0)
33 allWindows.insert({w->getActiveIndex(), w});
34 }
35
36 // window is not in all windows
37 if (window->getActiveIndex() > 0)
38 allWindows.insert({window->getActiveIndex(), window});
39
40 if (allWindows.size() >= 2) {
41 const auto lastIt = std::prev(allWindows.end());
42 const auto prevIt = std::prev(lastIt);
43 const auto lastW = lastIt->second;
44 const auto prevW = prevIt->second;
45
46 if (lastW == window) // Only act if window is last to be active
47 prevW->requestActivateWindow();
48 }
49}
50
52 QWasmWindowTreeNode *currentParent,
53 QWasmWindowStack::PositionPreference positionPreference)
54{
55 auto *window = asWasmWindow();
56 if (previousParent) {
57 previousParent->m_childStack.removeWindow(window);
59 window);
60 }
61
62 if (currentParent) {
63 currentParent->m_childStack.pushWindow(window, positionPreference);
65 window);
66 }
67}
68
70{
71 return nullptr;
72}
73
75 QWasmWindowTreeNode *parent, QWasmWindow *child)
76{
77 if (changeType == QWasmWindowTreeNodeChangeType::NodeInsertion && parent == this
78 && m_childStack.topWindow()
79 && m_childStack.topWindow()->window()) {
80
81 const auto flags = m_childStack.topWindow()->window()->flags();
82 const bool notToolOrPopup = ((flags & Qt::ToolTip) != Qt::ToolTip) && ((flags & Qt::Popup) != Qt::Popup);
83 const QVariant showWithoutActivating = m_childStack.topWindow()->window()->property("_q_showWithoutActivating");
84 if (!showWithoutActivating.isValid() || !showWithoutActivating.toBool()) {
85 if (notToolOrPopup)
86 m_childStack.topWindow()->requestActivateWindow();
87 }
88 }
89
90 if (parentNode())
91 parentNode()->onSubtreeChanged(changeType, parent, child);
92}
93
95{
96 window->setZOrder(z);
97}
98
100 QWasmWindowStack::PositionPreference positionPreference)
101{
102 if (parentNode()) {
103 parentNode()->m_childStack.windowPositionPreferenceChanged(asWasmWindow(),
104 positionPreference);
105 }
106}
107
109{
110 if (parentNode())
111 parentNode()->setActiveChildNode(asWasmWindow());
112
113 // At the end, this is a recursive function
114 m_activeIndex = ++s_nextActiveIndex;
115}
116
118{
119 if (!parentNode())
120 return;
121 parentNode()->m_childStack.raise(asWasmWindow());
123}
124
126{
127 if (!parentNode())
128 return;
129 m_childStack.lower(asWasmWindow());
130}
131
132void QWasmWindowTreeNode::onTopWindowChanged()
133{
134 constexpr int zOrderForElementInFrontOfScreen = 3;
135 int z = zOrderForElementInFrontOfScreen;
136 std::for_each(m_childStack.rbegin(), m_childStack.rend(),
137 [this, &z](QWasmWindow *window) { setWindowZOrder(window, z++); });
138}
139
140void QWasmWindowTreeNode::setActiveChildNode(QWasmWindow *activeChild)
141{
142 m_activeChild = activeChild;
143
144 auto it = m_childStack.begin();
145 if (it == m_childStack.end())
146 return;
147 for (; it != m_childStack.end(); ++it)
148 (*it)->onActivationChanged(*it == m_activeChild);
149
151}
virtual ~QWasmWindowTreeNode()
virtual void onParentChanged(QWasmWindowTreeNode *previous, QWasmWindowTreeNode *current, QWasmWindowStack::PositionPreference positionPreference)
virtual QWasmWindowTreeNode * parentNode()=0
virtual void onSubtreeChanged(QWasmWindowTreeNodeChangeType changeType, QWasmWindowTreeNode *parent, QWasmWindow *child)
virtual QWasmWindow * asWasmWindow()
virtual void setWindowZOrder(QWasmWindow *window, int z)
void onPositionPreferenceChanged(QWasmWindowStack::PositionPreference positionPreference)
friend class QWasmCompositor
void setZOrder(int order)
QWasmWindowTreeNodeChangeType