mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-07-14 02:54:31 -04:00
Support XDG activation
QWaylandLayerShellIntegration has virtual hooks for Xdg Activation. This is important to hook up in layer shell because activation using requestActivate in Qt will go through this path. It also means we have support for us to drop the implementation in KWindowSystem in favour of calling into Qt.
This commit is contained in:
committed by
Vlad Zahorodnii
parent
00b26a196d
commit
de9fdb3fb7
@ -8,16 +8,20 @@
|
||||
#include "interfaces/window.h"
|
||||
#include "layershellqt_logging.h"
|
||||
#include "qwaylandlayersurface_p.h"
|
||||
#include "qwaylandxdgactivationv1_p.h"
|
||||
|
||||
#include <QtWaylandClient/private/qwaylandscreen_p.h>
|
||||
#include <QtWaylandClient/private/qwaylandsurface_p.h>
|
||||
#include <QtWaylandClient/private/qwaylandwindow_p.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
namespace LayerShellQt
|
||||
{
|
||||
QWaylandLayerSurface::QWaylandLayerSurface(QtWayland::zwlr_layer_shell_v1 *shell, QtWaylandClient::QWaylandWindow *window)
|
||||
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell, QtWaylandClient::QWaylandWindow *window)
|
||||
: QtWaylandClient::QWaylandShellSurface(window)
|
||||
, QtWayland::zwlr_layer_surface_v1()
|
||||
, m_shell(shell)
|
||||
, m_interface(Window::get(window->window()))
|
||||
{
|
||||
wl_output *output = nullptr;
|
||||
@ -155,4 +159,54 @@ void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry)
|
||||
set_size(size.width(), size.height());
|
||||
}
|
||||
|
||||
bool QWaylandLayerSurface::requestActivate()
|
||||
{
|
||||
QWaylandXdgActivationV1 *activation = m_shell->activation();
|
||||
if (!activation->isActive()) {
|
||||
return false;
|
||||
}
|
||||
if (!m_activationToken.isEmpty()) {
|
||||
activation->activate(m_activationToken, window()->wlSurface());
|
||||
m_activationToken = {};
|
||||
return true;
|
||||
} else {
|
||||
const auto focusWindow = QGuiApplication::focusWindow();
|
||||
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow*>(focusWindow->handle()) : window();
|
||||
if (const auto seat = wlWindow->display()->lastInputDevice()) {
|
||||
const auto tokenProvider = activation->requestXdgActivationToken(
|
||||
wlWindow->display(), wlWindow->wlSurface(), 0, QString());
|
||||
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
|
||||
[this](const QString &token) {
|
||||
m_shell->activation()->activate(token, window()->wlSurface());
|
||||
});
|
||||
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void QWaylandLayerSurface::setXdgActivationToken(const QString &token)
|
||||
{
|
||||
m_activationToken = token;
|
||||
}
|
||||
|
||||
void QWaylandLayerSurface::requestXdgActivationToken(quint32 serial)
|
||||
{
|
||||
QWaylandXdgActivationV1 *activation = m_shell->activation();
|
||||
if (!activation->isActive()) {
|
||||
return;
|
||||
}
|
||||
auto tokenProvider = activation->requestXdgActivationToken(
|
||||
window()->display(), window()->wlSurface(), serial, QString());
|
||||
|
||||
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
|
||||
[this](const QString &token) {
|
||||
Q_EMIT window()->xdgActivationTokenCreated(token);
|
||||
});
|
||||
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user