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 Pick-to: 6.4 6.3 Change-Id: I6f54d12197ac0c10bfda2a517aa11bc291e3b471 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org>
This commit is contained in:
parent
c1187f4daa
commit
b5160ae118
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user