summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Fedin <fedin-ilja2010@ya.ru>2022-06-22 19:02:59 +0400
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-11 07:43:15 +0000
commit98323fb8199aef3026e9fd7ef1e04693ad8161bf (patch)
tree1b67c4d2e690a0da80246135086bbbba76367181
parenta4b5083ea52a77b29db12b1e2726775cb59a9b8d (diff)
downloadqtwayland-98323fb8199aef3026e9fd7ef1e04693ad8161bf.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>
-rw-r--r--src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp26
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 7d776eb3..d7a5f565 100644
--- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
+++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
@@ -46,6 +46,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
@@ -513,8 +514,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;
}