File indexing completed on 2024-11-10 04:57:36
0001 /* 0002 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "xdgactivation_v1.h" 0008 #include "clientconnection.h" 0009 #include "display.h" 0010 #include "seat.h" 0011 #include "surface.h" 0012 0013 #include "qwayland-server-xdg-activation-v1.h" 0014 0015 #include <QPointer> 0016 0017 namespace KWin 0018 { 0019 static const int s_version = 1; 0020 0021 class XdgActivationTokenV1Interface : public QtWaylandServer::xdg_activation_token_v1 0022 { 0023 public: 0024 XdgActivationTokenV1Interface(XdgActivationV1Interface::CreatorFunction creator, ClientConnection *client, uint32_t newId) 0025 : QtWaylandServer::xdg_activation_token_v1(*client, newId, s_version) 0026 , m_creator(creator) 0027 , m_client(client) 0028 { 0029 } 0030 0031 protected: 0032 void xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) override; 0033 void xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) override; 0034 void xdg_activation_token_v1_set_surface(QtWaylandServer::xdg_activation_token_v1::Resource *resource, struct ::wl_resource *surface) override; 0035 void xdg_activation_token_v1_commit(Resource *resource) override; 0036 void xdg_activation_token_v1_destroy(Resource *resource) override; 0037 void xdg_activation_token_v1_destroy_resource(Resource *resource) override; 0038 0039 const XdgActivationV1Interface::CreatorFunction m_creator; 0040 QPointer<SurfaceInterface> m_surface; 0041 uint m_serial = 0; 0042 struct ::wl_resource *m_seat = nullptr; 0043 QString m_appId; 0044 bool m_committed = false; 0045 ClientConnection *const m_client; 0046 }; 0047 0048 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) 0049 { 0050 m_serial = serial; 0051 m_seat = seat; 0052 } 0053 0054 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) 0055 { 0056 m_appId = app_id; 0057 } 0058 0059 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_surface(Resource *resource, struct ::wl_resource *surface) 0060 { 0061 m_surface = SurfaceInterface::get(surface); 0062 } 0063 0064 void XdgActivationTokenV1Interface::xdg_activation_token_v1_commit(Resource *resource) 0065 { 0066 QString token; 0067 if (m_creator) { 0068 token = m_creator(m_client, m_surface, m_serial, SeatInterface::get(m_seat), m_appId); 0069 } 0070 0071 m_committed = true; 0072 send_done(resource->handle, token); 0073 } 0074 0075 void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy(Resource *resource) 0076 { 0077 if (!m_committed) { 0078 send_done(resource->handle, {}); 0079 } 0080 wl_resource_destroy(resource->handle); 0081 } 0082 0083 void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy_resource(Resource *resource) 0084 { 0085 delete this; 0086 } 0087 0088 class XdgActivationV1InterfacePrivate : public QtWaylandServer::xdg_activation_v1 0089 { 0090 public: 0091 XdgActivationV1InterfacePrivate(Display *display, XdgActivationV1Interface *q) 0092 : QtWaylandServer::xdg_activation_v1(*display, s_version) 0093 , q(q) 0094 , m_display(display) 0095 { 0096 } 0097 0098 protected: 0099 void xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) override; 0100 void xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) override; 0101 void xdg_activation_v1_destroy(Resource *resource) override; 0102 0103 public: 0104 XdgActivationV1Interface::CreatorFunction m_creator; 0105 XdgActivationV1Interface *const q; 0106 Display *const m_display; 0107 }; 0108 0109 void XdgActivationV1InterfacePrivate::xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) 0110 { 0111 new XdgActivationTokenV1Interface(m_creator, m_display->getConnection(resource->client()), id); 0112 } 0113 0114 void XdgActivationV1InterfacePrivate::xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) 0115 { 0116 Q_EMIT q->activateRequested(SurfaceInterface::get(surface), token); 0117 } 0118 0119 void XdgActivationV1InterfacePrivate::xdg_activation_v1_destroy(Resource *resource) 0120 { 0121 wl_resource_destroy(resource->handle); 0122 } 0123 0124 XdgActivationV1Interface::XdgActivationV1Interface(Display *display, QObject *parent) 0125 : QObject(parent) 0126 , d(new XdgActivationV1InterfacePrivate(display, this)) 0127 { 0128 } 0129 0130 XdgActivationV1Interface::~XdgActivationV1Interface() 0131 { 0132 } 0133 0134 void XdgActivationV1Interface::setActivationTokenCreator(const CreatorFunction &creator) 0135 { 0136 d->m_creator = creator; 0137 } 0138 0139 } 0140 0141 #include "moc_xdgactivation_v1.cpp"