diff options
author | Ilya Fedin <fedin-ilja2010@ya.ru> | 2022-06-22 19:02:59 +0400 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-11 08:04:57 +0000 |
commit | 741aeb0e8855451351630bed118b9e537d3ebf22 (patch) | |
tree | 159a7a4ee93544b5a6f16b8ed0e1b4a814710872 /src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp | |
parent | d9503c89a37cbf6caf332200ba6142ad1cc5fad9 (diff) | |
download | qtwayland-741aeb0e8855451351630bed118b9e537d3ebf22.tar.gz |
Client: get activation token automatically whenever possible
This allows the application to change focus between its own windows
without any code change whenever possbile
I.e. if application already has a focused window or the token is specified
in XDG_ACTIVATION_TOKEN environment variable
Change-Id: I6f54d12197ac0c10bfda2a517aa11bc291e3b471
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org>
(cherry picked from commit 4488385015255c1cd916e2695d0df8aaf6d8f6df)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp')
-rw-r--r-- | src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 3d2fc61d..e227971b 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -10,6 +10,7 @@ #include <QtWaylandClient/private/qwaylandscreen_p.h> #include <QtWaylandClient/private/qwaylandabstractdecoration_p.h> +#include <QtGui/QGuiApplication> #include <QtGui/private/qwindow_p.h> QT_BEGIN_NAMESPACE @@ -477,8 +478,29 @@ void QWaylandXdgSurface::xdg_surface_configure(uint32_t serial) bool QWaylandXdgSurface::requestActivate() { if (auto *activation = m_shell->activation()) { - activation->activate(m_activationToken, window()->wlSurface()); - return true; + if (!m_activationToken.isEmpty()) { + activation->activate(m_activationToken, window()->wlSurface()); + m_activationToken = {}; + return true; + } else if (const auto token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN"); !token.isEmpty()) { + activation->activate(token, window()->wlSurface()); + qunsetenv("XDG_ACTIVATION_TOKEN"); + return true; + } else if (const auto focusWindow = QGuiApplication::focusWindow()) { + const auto wlWindow = static_cast<QWaylandWindow*>(focusWindow->handle()); + if (const auto xdgSurface = qobject_cast<QWaylandXdgSurface *>(wlWindow->shellSurface())) { + if (const auto seat = wlWindow->display()->lastInputDevice()) { + const auto tokenProvider = activation->requestXdgActivationToken( + wlWindow->display(), wlWindow->wlSurface(), seat->serial(), xdgSurface->m_appId); + connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this, + [this, tokenProvider](const QString &token) { + m_shell->activation()->activate(token, window()->wlSurface()); + tokenProvider->deleteLater(); + }); + return true; + } + } + } } return false; } |