File indexing completed on 2024-11-10 04:57:26
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 #include "datadevicemanager.h" 0008 #include "datasource.h" 0009 #include "display.h" 0010 #include "seat_p.h" 0011 // Wayland 0012 #include <qwayland-server-wayland.h> 0013 0014 namespace KWin 0015 { 0016 static const quint32 s_version = 3; 0017 0018 class DataDeviceManagerInterfacePrivate : public QtWaylandServer::wl_data_device_manager 0019 { 0020 public: 0021 DataDeviceManagerInterfacePrivate(DataDeviceManagerInterface *q, Display *d); 0022 0023 DataDeviceManagerInterface *q; 0024 0025 private: 0026 void createDataSource(wl_client *client, wl_resource *resource, uint32_t id); 0027 void getDataDevice(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *seat); 0028 0029 protected: 0030 void data_device_manager_create_data_source(Resource *resource, uint32_t id) override; 0031 void data_device_manager_get_data_device(Resource *resource, uint32_t id, wl_resource *seat) override; 0032 }; 0033 0034 DataDeviceManagerInterfacePrivate::DataDeviceManagerInterfacePrivate(DataDeviceManagerInterface *q, Display *d) 0035 : QtWaylandServer::wl_data_device_manager(*d, s_version) 0036 , q(q) 0037 { 0038 } 0039 0040 void DataDeviceManagerInterfacePrivate::data_device_manager_create_data_source(Resource *resource, uint32_t id) 0041 { 0042 wl_resource *data_source_resource = wl_resource_create(resource->client(), &wl_data_source_interface, resource->version(), id); 0043 if (!data_source_resource) { 0044 wl_resource_post_no_memory(resource->handle); 0045 return; 0046 } 0047 DataSourceInterface *dataSource = new DataSourceInterface(data_source_resource); 0048 Q_EMIT q->dataSourceCreated(dataSource); 0049 } 0050 0051 void DataDeviceManagerInterfacePrivate::data_device_manager_get_data_device(Resource *resource, uint32_t id, wl_resource *seat) 0052 { 0053 SeatInterface *s = SeatInterface::get(seat); 0054 Q_ASSERT(s); 0055 if (!s) { 0056 return; 0057 } 0058 0059 wl_resource *data_device_resource = wl_resource_create(resource->client(), &wl_data_device_interface, resource->version(), id); 0060 if (!data_device_resource) { 0061 wl_resource_post_no_memory(resource->handle); 0062 return; 0063 } 0064 DataDeviceInterface *dataDevice = new DataDeviceInterface(s, data_device_resource); 0065 Q_EMIT q->dataDeviceCreated(dataDevice); 0066 } 0067 0068 DataDeviceManagerInterface::DataDeviceManagerInterface(Display *display, QObject *parent) 0069 : QObject(parent) 0070 , d(new DataDeviceManagerInterfacePrivate(this, display)) 0071 { 0072 } 0073 0074 DataDeviceManagerInterface::~DataDeviceManagerInterface() = default; 0075 0076 } 0077 0078 #include "moc_datadevicemanager.cpp"