KWaylandServer

xdgactivation_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <[email protected]>
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_interface.h"
8 #include "display.h"
9 #include "logging.h"
10 #include "seat_interface.h"
11 #include "surface_interface.h"
12 
13 #include "qwayland-server-xdg-activation-v1.h"
14 
15 namespace KWaylandServer
16 {
17 static const int s_version = 1;
18 
19 class XdgActivationTokenV1Interface : public QtWaylandServer::xdg_activation_token_v1
20 {
21 public:
22  XdgActivationTokenV1Interface(XdgActivationV1Interface::CreatorFunction creator, ClientConnection *client, uint32_t newId)
23  : QtWaylandServer::xdg_activation_token_v1(*client, newId, s_version)
24  , m_creator(creator)
25  , m_client(client)
26  {
27  }
28 
29 protected:
30  void xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat) override;
31  void xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id) override;
32  void xdg_activation_token_v1_set_surface(QtWaylandServer::xdg_activation_token_v1::Resource *resource, struct ::wl_resource *surface) override;
33  void xdg_activation_token_v1_commit(Resource *resource) override;
34  void xdg_activation_token_v1_destroy(Resource *resource) override;
35  void xdg_activation_token_v1_destroy_resource(Resource *resource) override;
36 
37  const XdgActivationV1Interface::CreatorFunction m_creator;
39  uint m_serial = 0;
40  struct ::wl_resource *m_seat = nullptr;
41  QString m_appId;
42  bool m_committed = false;
43  ClientConnection *const m_client;
44 };
45 
46 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_serial(Resource *resource, uint32_t serial, struct ::wl_resource *seat)
47 {
48  Q_UNUSED(resource);
49  m_serial = serial;
50  m_seat = seat;
51 }
52 
53 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_app_id(Resource *resource, const QString &app_id)
54 {
55  Q_UNUSED(resource);
56  m_appId = app_id;
57 }
58 
59 void XdgActivationTokenV1Interface::xdg_activation_token_v1_set_surface(Resource *resource, struct ::wl_resource *surface)
60 {
61  Q_UNUSED(resource);
62  m_surface = SurfaceInterface::get(surface);
63 }
64 
65 void XdgActivationTokenV1Interface::xdg_activation_token_v1_commit(Resource *resource)
66 {
67  QString token;
68  if (m_creator) {
69  token = m_creator(m_client, m_surface, m_serial, SeatInterface::get(m_seat), m_appId);
70  }
71 
72  m_committed = true;
73  send_done(resource->handle, token);
74 }
75 
76 void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy(Resource *resource)
77 {
78  if (!m_committed) {
79  send_done(resource->handle, {});
80  }
81  wl_resource_destroy(resource->handle);
82 }
83 
84 void XdgActivationTokenV1Interface::xdg_activation_token_v1_destroy_resource(Resource *resource)
85 {
86  Q_UNUSED(resource);
87  delete this;
88 }
89 
90 class XdgActivationV1InterfacePrivate : public QtWaylandServer::xdg_activation_v1
91 {
92 public:
93  XdgActivationV1InterfacePrivate(Display *display, XdgActivationV1Interface *q)
94  : QtWaylandServer::xdg_activation_v1(*display, s_version)
95  , q(q)
96  , m_display(display)
97  {
98  }
99 
100 protected:
101  void xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id) override;
102  void xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface) override;
103  void xdg_activation_v1_destroy(Resource *resource) override;
104 
105 public:
106  XdgActivationV1Interface::CreatorFunction m_creator;
107  XdgActivationV1Interface *const q;
108  Display *const m_display;
109 };
110 
111 void XdgActivationV1InterfacePrivate::xdg_activation_v1_get_activation_token(Resource *resource, uint32_t id)
112 {
113  new XdgActivationTokenV1Interface(m_creator, m_display->getConnection(resource->client()), id);
114 }
115 
116 void XdgActivationV1InterfacePrivate::xdg_activation_v1_activate(Resource *resource, const QString &token, struct ::wl_resource *surface)
117 {
118  Q_UNUSED(resource);
119  Q_EMIT q->activateRequested(SurfaceInterface::get(surface), token);
120 }
121 
122 void XdgActivationV1InterfacePrivate::xdg_activation_v1_destroy(Resource *resource)
123 {
124  wl_resource_destroy(resource->handle);
125 }
126 
127 XdgActivationV1Interface::XdgActivationV1Interface(Display *display, QObject *parent)
128  : QObject(parent)
129  , d(new XdgActivationV1InterfacePrivate(display, this))
130 {
131 }
132 
133 XdgActivationV1Interface::~XdgActivationV1Interface()
134 {
135 }
136 
137 void XdgActivationV1Interface::setActivationTokenCreator(const CreatorFunction &creator)
138 {
139  d->m_creator = creator;
140 }
141 
142 }
static SurfaceInterface * get(wl_resource *native)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:08:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.