diff options
author | Robert Griebl <robert.griebl@qt.io> | 2023-10-31 15:15:25 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2023-11-06 15:17:46 +0100 |
commit | f6c9c07517c3ad3c39b9ddb001f92e7e271b234a (patch) | |
tree | b2e26fa067bda9dbff3112c33b086e8487292aa6 /src/window-lib | |
parent | 463f2f43a14137a00325c4c8dabaf2ae6ff9297b (diff) |
Improve Wayland WindowItem de-activation
Wayland window de-activation doesn't work automatically in case the
sys-ui gets focus, so we have to force that.
Change-Id: I57b6ec039cd15a6c2cb2d3c973628c5ee6975526
Reviewed-by: Bernd Weimer <bernd.weimer@qt.io>
Diffstat (limited to 'src/window-lib')
-rw-r--r-- | src/window-lib/waylandcompositor.cpp | 18 | ||||
-rw-r--r-- | src/window-lib/windowitem.cpp | 10 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/window-lib/waylandcompositor.cpp b/src/window-lib/waylandcompositor.cpp index d221b442..f889c8b6 100644 --- a/src/window-lib/waylandcompositor.cpp +++ b/src/window-lib/waylandcompositor.cpp @@ -191,6 +191,24 @@ void WaylandCompositor::registerOutputWindow(QQuickWindow* window) output->setSizeFollowsWindow(true); m_outputs.append(output); window->winId(); + + // Qt doesn't automatically de-focus a Wayland client, if a control in the Sys-UI gets focus + //TODO: check if upstreaming to QtWaylandCompositor is an option + connect(window, &QQuickWindow::activeFocusItemChanged, + this, [this, window]() { + QQuickItem *lastFocusItem = window->property("_am_lastFocusItem").value<QQuickItem *>(); + QQuickItem *currentFocusItem = window->activeFocusItem(); + + window->setProperty("_am_lastFocusItem", QVariant::fromValue(currentFocusItem)); + + if ((lastFocusItem != currentFocusItem) + && qobject_cast<QWaylandQuickItem *>(lastFocusItem) + && !qobject_cast<QWaylandQuickItem *>(currentFocusItem)) { + + if (QWaylandSeat *target = defaultSeat()) + target->setKeyboardFocus(nullptr); + } + }); } WaylandQtAMServerExtension *WaylandCompositor::amExtension() diff --git a/src/window-lib/windowitem.cpp b/src/window-lib/windowitem.cpp index 251d0138..cbe059ff 100644 --- a/src/window-lib/windowitem.cpp +++ b/src/window-lib/windowitem.cpp @@ -110,8 +110,8 @@ WindowItem::WindowItem(QQuickItem *parent) m_contentItem->setWidth(width()); m_contentItem->setHeight(height()); - connect(this, &QQuickItem::activeFocusChanged, this, [this] () { - if (hasActiveFocus() && m_impl) + connect(this, &QQuickItem::activeFocusChanged, this, [this](bool hasFocus) { + if (hasFocus && m_impl) m_impl->forwardActiveFocus(); }); } @@ -400,6 +400,10 @@ void WindowItem::InProcessImpl::setFocusOnClick(bool focusOnClick) #if defined(AM_MULTI_PROCESS) +// Wayland has no concept of clients ignoring/accepting key events, but even if it did, we'd get +// back the response far too late to be useful. In order to give the sys-ui a chance to handle +// key-events at all when a Wayland client has focus, we need to set the "ignore" flag on these +// events. class WaylandQuickIgnoreKeyItem : public QWaylandQuickItem { public: @@ -455,7 +459,7 @@ void WindowItem::WaylandImpl::createWaylandItem() void WindowItem::WaylandImpl::forwardActiveFocus() { - m_waylandItem->forceActiveFocus(); + m_waylandItem->takeFocus(); } bool WindowItem::WaylandImpl::focusOnClick() const |