1 /********************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
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 "data_device_manager.h"
21
22 #include "client.h"
23 #include "data_device.h"
24 #include "data_source.h"
25 #include "display.h"
26 #include "selection_device_manager_p.h"
27
28 #include "wayland/bind.h"
29 #include "wayland/global.h"
30
31 #include <wayland-server.h>
32
33 namespace Wrapland::Server
34 {
35
36 constexpr uint32_t DataDeviceManagerVersion = 3;
37 using DataDeviceManagerGlobal = Wayland::Global<DataDeviceManager, DataDeviceManagerVersion>;
38
39 class DataDeviceManager::Private : public device_manager<DataDeviceManagerGlobal>
40 {
41 public:
42 Private(DataDeviceManager* q, Display* display);
43
44 private:
45 static const struct wl_data_device_manager_interface s_interface;
46 };
47
48 const struct wl_data_device_manager_interface DataDeviceManager::Private::s_interface = {
49 cb<create_source>,
50 cb<get_device>,
51 };
52
Private(DataDeviceManager * q,Display * display)53 DataDeviceManager::Private::Private(DataDeviceManager* q, Display* display)
54 : device_manager<DataDeviceManagerGlobal>(q,
55 display,
56 &wl_data_device_manager_interface,
57 &s_interface)
58 {
59 }
60
DataDeviceManager(Display * display,QObject * parent)61 DataDeviceManager::DataDeviceManager(Display* display, [[maybe_unused]] QObject* parent)
62 : QObject(parent)
63 , d_ptr(new Private(this, display))
64 {
65 d_ptr->create();
66 }
67
68 DataDeviceManager::~DataDeviceManager() = default;
69
create_source(Client * client,uint32_t version,uint32_t id)70 void DataDeviceManager::create_source(Client* client, uint32_t version, uint32_t id)
71 {
72 auto source = new DataSource(client, version, id);
73 if (!source) {
74 return;
75 }
76
77 Q_EMIT sourceCreated(source);
78 }
79
get_device(Client * client,uint32_t version,uint32_t id,Seat * seat)80 void DataDeviceManager::get_device(Client* client, uint32_t version, uint32_t id, Seat* seat)
81 {
82 auto device = new DataDevice(client, version, id, seat);
83 if (!device) {
84 return;
85 }
86
87 QObject::connect(device, &DataDevice::dragStarted, seat, [seat, device] {
88 seat->d_ptr->drags.perform_drag(device);
89 });
90
91 seat->d_ptr->data_devices.register_device(device);
92 Q_EMIT deviceCreated(device);
93 }
94
95 }
96