KWaylandServer

datacontrolsource_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "datacontrolsource_v1_interface.h"
7 #include "clientconnection.h"
8 #include "datacontroldevicemanager_v1_interface.h"
9 #include "utils.h"
10 // Qt
11 #include <QStringList>
12 // Wayland
13 #include <qwayland-server-wlr-data-control-unstable-v1.h>
14 // system
15 #include <unistd.h>
16 
17 namespace KWaylandServer
18 {
19 class DataControlSourceV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_source_v1
20 {
21 public:
22  DataControlSourceV1InterfacePrivate(DataControlSourceV1Interface *q, ::wl_resource *resource);
23 
25  DataControlSourceV1Interface *q;
26 
27 protected:
28  void zwlr_data_control_source_v1_destroy_resource(Resource *resource) override;
29  void zwlr_data_control_source_v1_offer(Resource *resource, const QString &mime_type) override;
30  void zwlr_data_control_source_v1_destroy(Resource *resource) override;
31 };
32 
33 DataControlSourceV1InterfacePrivate::DataControlSourceV1InterfacePrivate(DataControlSourceV1Interface *_q, ::wl_resource *resource)
34  : QtWaylandServer::zwlr_data_control_source_v1(resource)
35  , q(_q)
36 {
37 }
38 
39 void DataControlSourceV1InterfacePrivate::zwlr_data_control_source_v1_destroy_resource(QtWaylandServer::zwlr_data_control_source_v1::Resource *resource)
40 {
41  Q_UNUSED(resource)
42  Q_EMIT q->aboutToBeDestroyed();
43  delete q;
44 }
45 
46 void DataControlSourceV1InterfacePrivate::zwlr_data_control_source_v1_offer(Resource *, const QString &mimeType)
47 {
48  mimeTypes << mimeType;
49  Q_EMIT q->mimeTypeOffered(mimeType);
50 }
51 
52 void DataControlSourceV1InterfacePrivate::zwlr_data_control_source_v1_destroy(QtWaylandServer::zwlr_data_control_source_v1::Resource *resource)
53 {
54  wl_resource_destroy(resource->handle);
55 }
56 
57 DataControlSourceV1Interface::DataControlSourceV1Interface(DataControlDeviceManagerV1Interface *parent, ::wl_resource *resource)
58  : AbstractDataSource(parent)
59  , d(new DataControlSourceV1InterfacePrivate(this, resource))
60 {
61 }
62 
63 DataControlSourceV1Interface::~DataControlSourceV1Interface() = default;
64 
65 void DataControlSourceV1Interface::requestData(const QString &mimeType, qint32 fd)
66 {
67  d->send_send(mimeType, fd);
68  close(fd);
69 }
70 
71 void DataControlSourceV1Interface::cancel()
72 {
73  d->send_cancelled();
74 }
75 
76 QStringList DataControlSourceV1Interface::mimeTypes() const
77 {
78  return d->mimeTypes;
79 }
80 
81 wl_client *DataControlSourceV1Interface::client() const
82 {
83  return d->resource()->client();
84 }
85 
86 DataControlSourceV1Interface *DataControlSourceV1Interface::get(wl_resource *native)
87 {
88  if (auto sourcePrivate = resource_cast<DataControlSourceV1InterfacePrivate *>(native)) {
89  return sourcePrivate->q;
90  }
91  return nullptr;
92 }
93 
94 }
const QList< QKeySequence > & close()
QStringList mimeTypes(Types)
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.