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 "global_p.h"
9 #include "display.h"
10 #include "seat_interface_p.h"
11 // Wayland
12 #include <wayland-server.h>
13 
14 namespace KWayland
15 {
16 namespace Server
17 {
18 
19 class DataDeviceManagerInterface::Private : public Global::Private
20 {
21 public:
22  Private(DataDeviceManagerInterface *q, Display *d);
23 
24 private:
25  void bind(wl_client *client, uint32_t version, uint32_t id) override;
26  void createDataSource(wl_client *client, wl_resource *resource, uint32_t id);
27  void getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
28 
29  static void unbind(wl_resource *resource);
30  static void createDataSourceCallback(wl_client *client, wl_resource *resource, uint32_t id);
31  static void getDataDeviceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat);
32  static Private *cast(wl_resource *r) {
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 = {
49  createDataSourceCallback,
50  getDataDeviceCallback
51 };
52 #endif
53 
54 DataDeviceManagerInterface::Private::Private(DataDeviceManagerInterface *q, Display *d)
55  : Global::Private(d, &wl_data_device_manager_interface, s_version)
56  , q(q)
57 {
58 }
59 
60 void DataDeviceManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
61 {
62  auto c = display->getConnection(client);
63  wl_resource *resource = c->createResource(&wl_data_device_manager_interface, qMin(version, s_version), id);
64  if (!resource) {
65  wl_client_post_no_memory(client);
66  return;
67  }
68  wl_resource_set_implementation(resource, &s_interface, this, unbind);
69  // TODO: should we track?
70 }
71 
72 void DataDeviceManagerInterface::Private::unbind(wl_resource *resource)
73 {
74  Q_UNUSED(resource)
75 }
76 
77 void DataDeviceManagerInterface::Private::createDataSourceCallback(wl_client *client, wl_resource *resource, uint32_t id)
78 {
79  cast(resource)->createDataSource(client, resource, id);
80 }
81 
82 void DataDeviceManagerInterface::Private::createDataSource(wl_client *client, wl_resource *resource, uint32_t id)
83 {
84  DataSourceInterface *dataSource = new DataSourceInterface(q, resource);
85  dataSource->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_dataSourceVersion) , id);
86  if (!dataSource->resource()) {
87  wl_resource_post_no_memory(resource);
88  delete dataSource;
89  return;
90  }
91  emit q->dataSourceCreated(dataSource);
92 }
93 
94 void DataDeviceManagerInterface::Private::getDataDeviceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat)
95 {
96  cast(resource)->getDataDevice(client, resource, id, seat);
97 }
98 
99 void DataDeviceManagerInterface::Private::getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat)
100 {
101  SeatInterface *s = SeatInterface::get(seat);
102  Q_ASSERT(s);
103  DataDeviceInterface *dataDevice = new DataDeviceInterface(s, q, resource);
104  dataDevice->create(display->getConnection(client), qMin(wl_resource_get_version(resource), s_dataDeviceVersion), id);
105  if (!dataDevice->resource()) {
106  wl_resource_post_no_memory(resource);
107  return;
108  }
109  s->d_func()->registerDataDevice(dataDevice);
110  emit q->dataDeviceCreated(dataDevice);
111 }
112 
113 DataDeviceManagerInterface::DataDeviceManagerInterface(Display *display, QObject *parent)
114  : Global(new Private(this, display), parent)
115 {
116 }
117 
118 DataDeviceManagerInterface::~DataDeviceManagerInterface() = default;
119 
120 }
121 }
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.