Skip to content

Commit

Permalink
Automatically request token & get it from the variable when we're abl…
Browse files Browse the repository at this point in the history
…e to
  • Loading branch information
ilya-fedin authored and john-preston committed Jun 15, 2022
1 parent 866d361 commit 50d5fef
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions waylandshells/xdg-shell/qwaylandxdgshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Q_DECLARE_METATYPE(QMargins)
Expand Down Expand Up @@ -547,8 +548,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;
}
Expand Down

0 comments on commit 50d5fef

Please sign in to comment.