Directory: | ./ |
---|---|
File: | src/client/datadevicemanager.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 43 | 49 | 87.8% |
Branches: | 11 | 22 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | ||
20 | #include "datadevicemanager.h" | ||
21 | #include "datadevice.h" | ||
22 | #include "datasource.h" | ||
23 | #include "event_queue.h" | ||
24 | #include "seat.h" | ||
25 | #include "wayland_pointer_p.h" | ||
26 | |||
27 | #include <wayland-client-protocol.h> | ||
28 | |||
29 | namespace Wrapland | ||
30 | { | ||
31 | namespace Client | ||
32 | { | ||
33 | |||
34 | 41 | class Q_DECL_HIDDEN DataDeviceManager::Private | |
35 | { | ||
36 | public: | ||
37 | WaylandPointer<wl_data_device_manager, wl_data_device_manager_destroy> manager; | ||
38 | 41 | EventQueue* queue = nullptr; | |
39 | }; | ||
40 | |||
41 | 41 | DataDeviceManager::DataDeviceManager(QObject* parent) | |
42 | 41 | : QObject(parent) | |
43 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | , d(new Private) |
44 | 41 | { | |
45 | 41 | } | |
46 | |||
47 | 82 | DataDeviceManager::~DataDeviceManager() | |
48 | 82 | { | |
49 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | release(); |
50 | 82 | } | |
51 | |||
52 | 43 | void DataDeviceManager::release() | |
53 | { | ||
54 | 43 | d->manager.release(); | |
55 | 43 | } | |
56 | |||
57 | 81 | bool DataDeviceManager::isValid() const | |
58 | { | ||
59 | 81 | return d->manager.isValid(); | |
60 | } | ||
61 | |||
62 | 41 | void DataDeviceManager::setup(wl_data_device_manager* manager) | |
63 | { | ||
64 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | Q_ASSERT(manager); |
65 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | Q_ASSERT(!d->manager.isValid()); |
66 | 41 | d->manager.setup(manager); | |
67 | 41 | } | |
68 | |||
69 | ✗ | EventQueue* DataDeviceManager::eventQueue() | |
70 | { | ||
71 | ✗ | return d->queue; | |
72 | } | ||
73 | |||
74 | 41 | void DataDeviceManager::setEventQueue(EventQueue* queue) | |
75 | { | ||
76 | 41 | d->queue = queue; | |
77 | 41 | } | |
78 | |||
79 | 32 | DataSource* DataDeviceManager::createSource(QObject* parent) | |
80 | { | ||
81 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | Q_ASSERT(isValid()); |
82 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | DataSource* s = new DataSource(parent); |
83 | 32 | auto w = wl_data_device_manager_create_data_source(d->manager); | |
84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (d->queue) { |
85 | 32 | d->queue->addProxy(w); | |
86 | 32 | } | |
87 | 32 | s->setup(w); | |
88 | 32 | return s; | |
89 | } | ||
90 | |||
91 | 33 | DataDevice* DataDeviceManager::getDevice(Seat* seat, QObject* parent) | |
92 | { | ||
93 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | Q_ASSERT(isValid()); |
94 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | Q_ASSERT(seat); |
95 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | DataDevice* device = new DataDevice(parent); |
96 | 33 | auto w = wl_data_device_manager_get_data_device(d->manager, *seat); | |
97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (d->queue) { |
98 | 33 | d->queue->addProxy(w); | |
99 | 33 | } | |
100 | 33 | device->setup(w); | |
101 | 33 | return device; | |
102 | } | ||
103 | |||
104 | ✗ | DataDeviceManager::operator wl_data_device_manager*() const | |
105 | { | ||
106 | ✗ | return d->manager; | |
107 | } | ||
108 | |||
109 | ✗ | DataDeviceManager::operator wl_data_device_manager*() | |
110 | { | ||
111 | ✗ | return d->manager; | |
112 | } | ||
113 | |||
114 | } | ||
115 | } | ||
116 |