File indexing completed on 2024-11-10 04:57:31

0001 /*
0002     SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "primaryselectiondevicemanager_v1.h"
0008 #include "display.h"
0009 #include "primaryselectiondevice_v1.h"
0010 #include "primaryselectionsource_v1.h"
0011 #include "seat_p.h"
0012 // Wayland
0013 #include <qwayland-server-wp-primary-selection-unstable-v1.h>
0014 
0015 static const int s_version = 1;
0016 namespace KWin
0017 {
0018 class PrimarySelectionDeviceManagerV1InterfacePrivate : public QtWaylandServer::zwp_primary_selection_device_manager_v1
0019 {
0020 public:
0021     PrimarySelectionDeviceManagerV1InterfacePrivate(PrimarySelectionDeviceManagerV1Interface *q, Display *d);
0022 
0023     PrimarySelectionDeviceManagerV1Interface *q;
0024 
0025 protected:
0026     void zwp_primary_selection_device_manager_v1_create_source(Resource *resource, uint32_t id) override;
0027     void zwp_primary_selection_device_manager_v1_get_device(Resource *resource, uint32_t id, wl_resource *seat) override;
0028     void zwp_primary_selection_device_manager_v1_destroy(Resource *resource) override;
0029 };
0030 
0031 PrimarySelectionDeviceManagerV1InterfacePrivate::PrimarySelectionDeviceManagerV1InterfacePrivate(PrimarySelectionDeviceManagerV1Interface *q, Display *d)
0032     : QtWaylandServer::zwp_primary_selection_device_manager_v1(*d, s_version)
0033     , q(q)
0034 {
0035 }
0036 
0037 void PrimarySelectionDeviceManagerV1InterfacePrivate::zwp_primary_selection_device_manager_v1_create_source(Resource *resource, uint32_t id)
0038 {
0039     wl_resource *data_source_resource = wl_resource_create(resource->client(), &zwp_primary_selection_source_v1_interface, resource->version(), id);
0040     if (!data_source_resource) {
0041         wl_resource_post_no_memory(resource->handle);
0042         return;
0043     }
0044     PrimarySelectionSourceV1Interface *dataSource = new PrimarySelectionSourceV1Interface(data_source_resource);
0045     Q_EMIT q->dataSourceCreated(dataSource);
0046 }
0047 
0048 void PrimarySelectionDeviceManagerV1InterfacePrivate::zwp_primary_selection_device_manager_v1_get_device(Resource *resource, uint32_t id, wl_resource *seat)
0049 {
0050     SeatInterface *s = SeatInterface::get(seat);
0051     Q_ASSERT(s);
0052     if (!s) {
0053         return;
0054     }
0055 
0056     wl_resource *data_device_resource = wl_resource_create(resource->client(), &zwp_primary_selection_device_v1_interface, resource->version(), id);
0057     if (!data_device_resource) {
0058         wl_resource_post_no_memory(resource->handle);
0059         return;
0060     }
0061     PrimarySelectionDeviceV1Interface *dataDevice = new PrimarySelectionDeviceV1Interface(s, data_device_resource);
0062     Q_EMIT q->dataDeviceCreated(dataDevice);
0063 }
0064 
0065 void PrimarySelectionDeviceManagerV1InterfacePrivate::zwp_primary_selection_device_manager_v1_destroy(Resource *resource)
0066 {
0067     wl_resource_destroy(resource->handle);
0068 }
0069 
0070 PrimarySelectionDeviceManagerV1Interface::PrimarySelectionDeviceManagerV1Interface(Display *display, QObject *parent)
0071     : QObject(parent)
0072     , d(new PrimarySelectionDeviceManagerV1InterfacePrivate(this, display))
0073 {
0074 }
0075 
0076 PrimarySelectionDeviceManagerV1Interface::~PrimarySelectionDeviceManagerV1Interface() = default;
0077 }
0078 
0079 #include "moc_primaryselectiondevicemanager_v1.cpp"