KWayland

datadevicemanager_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "datadevicemanager_interface.h"
7 #include "datasource_interface.h"
8 #include "display.h"
9 #include "global_p.h"
10 #include "seat_interface_p.h"
11 // Wayland
12 #include <wayland-server.h>
13 
14 namespace KWayland
15 {
16 namespace Server
17 {
18 class DataDeviceManagerInterface::Private : public Global::Private
19 {
20 public:
21  Private(DataDeviceManagerInterface *q, Display *d);
22 
23 private:
24  void bind(wl_client *client, uint32_t version, uint32_t id) override;
25  void createDataSource(wl_client *client, wl_resource *resource, uint32_t id);
26  void getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
27 
28  static void unbind(wl_resource *resource);
29  static void createDataSourceCallback(wl_client *client, wl_resource *resource, uint32_t id);
30  static void getDataDeviceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
31  static Private *cast(wl_resource *r)
32  {
33  return reinterpret_cast<Private *>(wl_resource_get_user_data(r));
34  }
35 
36  DataDeviceManagerInterface *q;
37  static const struct wl_data_device_manager_interface s_interface;
38  static const quint32 s_version;
39  static const qint32 s_dataDeviceVersion;
40  static const qint32 s_dataSourceVersion;
41 };
42 
43 const quint32 DataDeviceManagerInterface::Private::s_version = 3;
44 const qint32 DataDeviceManagerInterface::Private::s_dataDeviceVersion = 3;
45 const qint32 DataDeviceManagerInterface::Private::s_dataSourceVersion = 3;
46 
47 #ifndef K_DOXYGEN
48 const struct wl_data_device_manager_interface DataDeviceManagerInterface::Private::s_interface = {createDataSourceCallback, getDataDeviceCallback};
49 #endif
50 
51 DataDeviceManagerInterface::Private::Private(DataDeviceManagerInterface *q, Display *d)
52  : Global::Private(d, &wl_data_device_manager_interface, s_version)
53  , q(q)
54 {
55 }
56 
57 void DataDeviceManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
58 {
59  auto c = display->getConnection(client);
60  wl_resource *resource = c->createResource(&wl_data_device_manager_interface, qMin(version, s_version), id);
61  if (!resource) {
62  wl_client_post_no_memory(client);
63  return;
64  }
65  wl_resource_set_implementation(resource, &s_interface, this, unbind);
66  // TODO: should we track?
67 }
68 
69 void DataDeviceManagerInterface::Private::unbind(wl_resource *resource)
70 {
71  Q_UNUSED(resource)
72 }
73 
74 void DataDeviceManagerInterface::Private::createDataSourceCallback(wl_client *client, wl_resource *resource, uint32_t id)
75 {
76  cast(resource)->createDataSource(client, resource, id);
77 }
78 
79 void DataDeviceManagerInterface::Private::createDataSource(wl_client *client, wl_resource *resource, uint32_t id)
80 {
81  DataSourceInterface *dataSource = new DataSourceInterface(q, resource);
82  dataSource->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_dataSourceVersion), id);
83  if (!dataSource->resource()) {
84  wl_resource_post_no_memory(resource);
85  delete dataSource;
86  return;
87  }
88  Q_EMIT q->dataSourceCreated(dataSource);
89 }
90 
91 void DataDeviceManagerInterface::Private::getDataDeviceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat)
92 {
93  cast(resource)->getDataDevice(client, resource, id, seat);
94 }
95 
96 void DataDeviceManagerInterface::Private::getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat)
97 {
98  SeatInterface *s = SeatInterface::get(seat);
99  Q_ASSERT(s);
100  DataDeviceInterface *dataDevice = new DataDeviceInterface(s, q, resource);
101  dataDevice->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_dataDeviceVersion), id);
102  if (!dataDevice->resource()) {
103  wl_resource_post_no_memory(resource);
104  return;
105  }
106  s->d_func()->registerDataDevice(dataDevice);
107  Q_EMIT q->dataDeviceCreated(dataDevice);
108 }
109 
110 DataDeviceManagerInterface::DataDeviceManagerInterface(Display *display, QObject *parent)
111  : Global(new Private(this, display), parent)
112 {
113 }
114 
115 DataDeviceManagerInterface::~DataDeviceManagerInterface() = default;
116 
117 }
118 }
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.