1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #include "datadevicemanager.h" |
7 | #include "datadevice.h" |
8 | #include "datasource.h" |
9 | #include "event_queue.h" |
10 | #include "seat.h" |
11 | #include "wayland_pointer_p.h" |
12 | |
13 | #include <wayland-client-protocol.h> |
14 | |
15 | namespace KWayland |
16 | { |
17 | namespace Client |
18 | { |
19 | class Q_DECL_HIDDEN DataDeviceManager::Private |
20 | { |
21 | public: |
22 | WaylandPointer<wl_data_device_manager, wl_data_device_manager_destroy> manager; |
23 | EventQueue *queue = nullptr; |
24 | }; |
25 | |
26 | DataDeviceManager::DataDeviceManager(QObject *parent) |
27 | : QObject(parent) |
28 | , d(new Private) |
29 | { |
30 | } |
31 | |
32 | DataDeviceManager::~DataDeviceManager() |
33 | { |
34 | release(); |
35 | } |
36 | |
37 | void DataDeviceManager::release() |
38 | { |
39 | d->manager.release(); |
40 | } |
41 | |
42 | void DataDeviceManager::destroy() |
43 | { |
44 | d->manager.destroy(); |
45 | } |
46 | |
47 | bool DataDeviceManager::isValid() const |
48 | { |
49 | return d->manager.isValid(); |
50 | } |
51 | |
52 | void DataDeviceManager::setup(wl_data_device_manager *manager) |
53 | { |
54 | Q_ASSERT(manager); |
55 | Q_ASSERT(!d->manager.isValid()); |
56 | d->manager.setup(pointer: manager); |
57 | } |
58 | |
59 | EventQueue *DataDeviceManager::eventQueue() |
60 | { |
61 | return d->queue; |
62 | } |
63 | |
64 | void DataDeviceManager::setEventQueue(EventQueue *queue) |
65 | { |
66 | d->queue = queue; |
67 | } |
68 | |
69 | DataSource *DataDeviceManager::createDataSource(QObject *parent) |
70 | { |
71 | Q_ASSERT(isValid()); |
72 | DataSource *s = new DataSource(parent); |
73 | auto w = wl_data_device_manager_create_data_source(wl_data_device_manager: d->manager); |
74 | if (d->queue) { |
75 | d->queue->addProxy(proxy: w); |
76 | } |
77 | s->setup(w); |
78 | return s; |
79 | } |
80 | |
81 | DataDevice *DataDeviceManager::getDataDevice(Seat *seat, QObject *parent) |
82 | { |
83 | Q_ASSERT(isValid()); |
84 | Q_ASSERT(seat); |
85 | DataDevice *device = new DataDevice(parent); |
86 | auto w = wl_data_device_manager_get_data_device(wl_data_device_manager: d->manager, seat: *seat); |
87 | if (d->queue) { |
88 | d->queue->addProxy(proxy: w); |
89 | } |
90 | device->setup(w); |
91 | return device; |
92 | } |
93 | |
94 | DataDeviceManager::operator wl_data_device_manager *() const |
95 | { |
96 | return d->manager; |
97 | } |
98 | |
99 | DataDeviceManager::operator wl_data_device_manager *() |
100 | { |
101 | return d->manager; |
102 | } |
103 | |
104 | } |
105 | } |
106 | |
107 | #include "moc_datadevicemanager.cpp" |
108 |