diff options
| author | Even Oscar Andersen <even.oscar.andersen@qt.io> | 2024-10-29 09:00:08 +0100 |
|---|---|---|
| committer | Even Oscar Andersen <even.oscar.andersen@qt.io> | 2024-11-26 16:25:11 +0100 |
| commit | ef8bf4c2cf3d86a869ff8a555d4e390168864144 (patch) | |
| tree | 99020819212b9c2ec2056c5cddbfbea8aa9b2c82 /src/plugins/platforms/wasm/qwasmwindowtreenode.cpp | |
| parent | 6085b9399053cd6665dc1a7b636c078992aaffe0 (diff) | |
wasm: Fix focus handling
We had input handling enabled as a precondition for setting focus.
This is wrong, we need to have the focus for toggle buttons
and other non-input things as well.
(Also toggle buttons act on spacebar).
Also selects a new active window if the window
that is active (i.e a dialog) is deleted.
Also shift + tab did not always work, fixed
to emit Key_Backtab
Fixes: QTBUG-130371
Pick-to: 6.8
Change-Id: I3b36a3e200ba9d4b0791865e75235ddfb72bcaa5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmwindowtreenode.cpp')
| -rw-r--r-- | src/plugins/platforms/wasm/qwasmwindowtreenode.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasmwindowtreenode.cpp b/src/plugins/platforms/wasm/qwasmwindowtreenode.cpp index f11adf9b78c..08eb7e327b1 100644 --- a/src/plugins/platforms/wasm/qwasmwindowtreenode.cpp +++ b/src/plugins/platforms/wasm/qwasmwindowtreenode.cpp @@ -4,6 +4,9 @@ #include "qwasmwindowtreenode.h" #include "qwasmwindow.h" +#include "qwasmscreen.h" + +uint64_t QWasmWindowTreeNode::s_nextActiveIndex = 0; QWasmWindowTreeNode::QWasmWindowTreeNode() : m_childStack(std::bind(&QWasmWindowTreeNode::onTopWindowChanged, this)) @@ -12,6 +15,39 @@ QWasmWindowTreeNode::QWasmWindowTreeNode() QWasmWindowTreeNode::~QWasmWindowTreeNode() = default; +void QWasmWindowTreeNode::shutdown() +{ + QWasmWindow *window = asWasmWindow(); + if (!window || + !window->window() || + (QGuiApplication::focusWindow() && // Don't act if we have a focus window different from this + QGuiApplication::focusWindow() != window->window())) + return; + + // Make a list of all windows sorted on active index. + // Skip windows with active index 0 as they have + // never been active. + std::map<uint64_t, QWasmWindow *> allWindows; + for (const auto &w : window->platformScreen()->allWindows()) { + if (w->getActiveIndex() > 0) + allWindows.insert({w->getActiveIndex(), w}); + } + + // window is not in all windows + if (window->getActiveIndex() > 0) + allWindows.insert({window->getActiveIndex(), window}); + + if (allWindows.size() >= 2) { + const auto lastIt = std::prev(allWindows.end()); + const auto prevIt = std::prev(lastIt); + const auto lastW = lastIt->second; + const auto prevW = prevIt->second; + + if (lastW == window) // Only act if window is last to be active + prevW->requestActivateWindow(); + } +} + void QWasmWindowTreeNode::onParentChanged(QWasmWindowTreeNode *previousParent, QWasmWindowTreeNode *currentParent, QWasmWindowStack::PositionPreference positionPreference) @@ -73,6 +109,9 @@ void QWasmWindowTreeNode::setAsActiveNode() { if (parentNode()) parentNode()->setActiveChildNode(asWasmWindow()); + + // At the end, this is a recursive function + m_activeIndex = ++s_nextActiveIndex; } void QWasmWindowTreeNode::bringToTop() |
