KWin
Loading...
Searching...
No Matches
xdgactivation_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "xdgactivation_v1.h"
8#include "clientconnection.h"
9#include "display.h"
10#include "seat.h"
11#include "surface.h"
12
13#include "qwayland-server-xdg-activation-v1.h"
14
15#include <QPointer>
16
17namespace KWin
18{
19static const int s_version = 1;
20
21class XdgActivationTokenV1Interface : public QtWaylandServer::xdg_activation_token_v1
22{
23public:
25 : QtWaylandServer::xdg_activation_token_v1(*client, newId, s_version)
26 , m_creator(creator)
27 , m_client(client)
28 {
29 }
30
31protected:
32 void xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) override;
33 void xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) override;
34 void xdg_activation_token_v1_set_surface(QtWaylandServer::xdg_activation_token_v1::Resource *resource, struct ::wl_resource *surface) override;
35 void xdg_activation_token_v1_commit(Resource *resource) override;
36 void xdg_activation_token_v1_destroy(Resource *resource) override;
37 void xdg_activation_token_v1_destroy_resource(Resource *resource) override;
38
40 QPointer<SurfaceInterface> m_surface;
41 uint m_serial = 0;
42 struct ::wl_resource *m_seat = nullptr;
43 QString m_appId;
44 bool m_committed = false;
46};
47
48void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat)
49{
50 m_serial = serial;
51 m_seat = seat;
52}
53
54void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id)
55{
56 m_appId = app_id;
57}
58
59void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_surface(Resource *resource, struct ::wl_resource *surface)
60{
62}
63
65{
66 QString token;
67 if (m_creator) {
69 }
70
71 m_committed = true;
72 send_done(resource->handle, token);
73}
74
76{
77 if (!m_committed) {
78 send_done(resource->handle, {});
79 }
80 wl_resource_destroy(resource->handle);
81}
82
84{
85 delete this;
86}
87
88class XdgActivationV1InterfacePrivate : public QtWaylandServer::xdg_activation_v1
89{
90public:
92 : QtWaylandServer::xdg_activation_v1(*display, s_version)
93 , q(q)
94 , m_display(display)
95 {
96 }
97
98protected:
99 void xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) override;
100 void xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) override;
101 void xdg_activation_v1_destroy(Resource *resource) override;
102
103public:
107};
108
113
114void XdgActivationV1InterfacePrivate::xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface)
115{
116 Q_EMIT q->activateRequested(SurfaceInterface::get(surface), token);
117}
118
120{
121 wl_resource_destroy(resource->handle);
122}
123
125 : QObject(parent)
126 , d(new XdgActivationV1InterfacePrivate(display, this))
127{
128}
129
133
135{
136 d->m_creator = creator;
137}
138
139}
140
141#include "moc_xdgactivation_v1.cpp"
Convenient Class which represents a wl_client.
Class holding the Wayland server display loop.
Definition display.h:34
ClientConnection * getConnection(wl_client *client)
Definition display.cpp:200
static SeatInterface * get(wl_resource *native)
Definition seat.cpp:429
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819
void xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) override
void xdg_activation_token_v1_destroy(Resource *resource) override
void xdg_activation_token_v1_destroy_resource(Resource *resource) override
XdgActivationTokenV1Interface(XdgActivationV1Interface::CreatorFunction creator, ClientConnection *client, uint32_t newId)
void xdg_activation_token_v1_commit(Resource *resource) override
void xdg_activation_token_v1_set_surface(QtWaylandServer::xdg_activation_token_v1::Resource *resource, struct ::wl_resource *surface) override
const XdgActivationV1Interface::CreatorFunction m_creator
QPointer< SurfaceInterface > m_surface
void xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) override
XdgActivationV1Interface(Display *display, QObject *parent=nullptr)
std::function< QString(ClientConnection *client, SurfaceInterface *surface, uint serial, SeatInterface *seat, const QString &appId)> CreatorFunction
void setActivationTokenCreator(const CreatorFunction &creator)
Provide the creator function that will be used to create a token given its parameters.
void activateRequested(SurfaceInterface *surface, const QString &token)
Notifies about the surface being activated using token.
XdgActivationV1Interface *const q
XdgActivationV1InterfacePrivate(Display *display, XdgActivationV1Interface *q)
XdgActivationV1Interface::CreatorFunction m_creator
void xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) override
void xdg_activation_v1_destroy(Resource *resource) override
void xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) override