|
| 1 | +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +#include "xdgactivationmanager_p.h" |
| 6 | + |
| 7 | +#include <wayland/xdgactivation.h> |
| 8 | + |
| 9 | +#include <QGuiApplication> |
| 10 | +#include <QLoggingCategory> |
| 11 | +#include <QWindow> |
| 12 | + |
| 13 | +#include <QtWaylandCompositor/QWaylandSeat> |
| 14 | + |
| 15 | +Q_LOGGING_CATEGORY(xdgActivationMgr, "dde.shell.xdgactivation.manager") |
| 16 | + |
| 17 | +// --------------------------------------------------------------------------- |
| 18 | +// XdgActivationManager |
| 19 | +// --------------------------------------------------------------------------- |
| 20 | + |
| 21 | +XdgActivationManager::XdgActivationManager(QWaylandCompositor *compositor) |
| 22 | + : QWaylandCompositorExtensionTemplate(compositor) |
| 23 | + , m_compositor(compositor) |
| 24 | +{ |
| 25 | +} |
| 26 | + |
| 27 | +void XdgActivationManager::initialize() |
| 28 | +{ |
| 29 | + QWaylandCompositorExtensionTemplate::initialize(); |
| 30 | + QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); |
| 31 | + Q_ASSERT(compositor); |
| 32 | + m_compositor = compositor; |
| 33 | + init(compositor->display(), 1); |
| 34 | + |
| 35 | + // Create the client-side xdg_activation_v1 connection to the outer compositor |
| 36 | + m_outerActivation = new ds::XdgActivation(this); |
| 37 | + connect(m_outerActivation, &ds::XdgActivation::tokenReady, this, &XdgActivationManager::onTokenReady); |
| 38 | +} |
| 39 | + |
| 40 | +void XdgActivationManager::xdg_activation_v1_destroy(Resource *resource) |
| 41 | +{ |
| 42 | + wl_resource_destroy(resource->handle); |
| 43 | +} |
| 44 | + |
| 45 | +void XdgActivationManager::xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) |
| 46 | +{ |
| 47 | + QWaylandResource tokenResource(wl_resource_create(resource->client(), &xdg_activation_token_v1_interface, wl_resource_get_version(resource->handle), id)); |
| 48 | + new XdgActivationTokenV1(this, tokenResource); |
| 49 | +} |
| 50 | + |
| 51 | +void XdgActivationManager::setPendingToken(XdgActivationTokenV1 *token) |
| 52 | +{ |
| 53 | + m_pendingToken = token; |
| 54 | +} |
| 55 | + |
| 56 | +void XdgActivationManager::requestOuterToken(const QString &appId) |
| 57 | +{ |
| 58 | + QWindow *window = QGuiApplication::focusWindow(); |
| 59 | + m_outerActivation->requestToken(window, appId); |
| 60 | +} |
| 61 | + |
| 62 | +void XdgActivationManager::clearPendingTokenIf(XdgActivationTokenV1 *token) |
| 63 | +{ |
| 64 | + if (m_pendingToken == token) { |
| 65 | + m_pendingToken = nullptr; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +void XdgActivationManager::onTokenReady(const QString &token) |
| 70 | +{ |
| 71 | + if (m_pendingToken) { |
| 72 | + qCDebug(xdgActivationMgr) << "Forwarding activation token to plugin client"; |
| 73 | + m_pendingToken->sendToken(token); |
| 74 | + m_pendingToken = nullptr; |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +// --------------------------------------------------------------------------- |
| 79 | +// XdgActivationTokenV1 |
| 80 | +// --------------------------------------------------------------------------- |
| 81 | +// XdgActivationTokenV1 |
| 82 | +// --------------------------------------------------------------------------- |
| 83 | + |
| 84 | +XdgActivationTokenV1::XdgActivationTokenV1(XdgActivationManager *manager, const QWaylandResource &resource) |
| 85 | + : QObject(manager) |
| 86 | + , m_manager(manager) |
| 87 | +{ |
| 88 | + init(resource.resource()); |
| 89 | +} |
| 90 | + |
| 91 | +XdgActivationTokenV1::~XdgActivationTokenV1() = default; |
| 92 | + |
| 93 | +void XdgActivationTokenV1::sendToken(const QString &token) |
| 94 | +{ |
| 95 | + send_done(token); |
| 96 | +} |
| 97 | + |
| 98 | +void XdgActivationTokenV1::xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) |
| 99 | +{ |
| 100 | + Q_UNUSED(resource) |
| 101 | + Q_UNUSED(seat) |
| 102 | + m_serial = serial; |
| 103 | +} |
| 104 | + |
| 105 | +void XdgActivationTokenV1::xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) |
| 106 | +{ |
| 107 | + Q_UNUSED(resource) |
| 108 | + m_appId = app_id; |
| 109 | +} |
| 110 | + |
| 111 | +void XdgActivationTokenV1::xdg_activation_token_v1_set_surface(Resource *resource, struct ::wl_resource *surface) |
| 112 | +{ |
| 113 | + Q_UNUSED(resource) |
| 114 | + m_surface = QWaylandSurface::fromResource(surface); |
| 115 | +} |
| 116 | + |
| 117 | +void XdgActivationTokenV1::xdg_activation_token_v1_commit(Resource *resource) |
| 118 | +{ |
| 119 | + Q_UNUSED(resource) |
| 120 | + qCDebug(xdgActivationMgr) << "Token committed by plugin client, appId:" << m_appId; |
| 121 | + |
| 122 | + // Store this token as pending and request from the outer compositor |
| 123 | + m_manager->setPendingToken(this); |
| 124 | + m_manager->requestOuterToken(m_appId); |
| 125 | +} |
| 126 | + |
| 127 | +void XdgActivationTokenV1::xdg_activation_token_v1_destroy(Resource *resource) |
| 128 | +{ |
| 129 | + Q_UNUSED(resource) |
| 130 | + m_manager->clearPendingTokenIf(this); |
| 131 | + deleteLater(); |
| 132 | +} |
0 commit comments