KWaylandServer

primaryselectionsource_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 "primaryselectionsource_v1_interface.h"
7 #include "clientconnection.h"
8 #include "primaryselectiondevicemanager_v1_interface.h"
9 #include "utils.h"
10 // Qt
11 #include <QStringList>
12 // Wayland
13 #include <qwayland-server-wp-primary-selection-unstable-v1.h>
14 // system
15 #include <unistd.h>
16 
17 namespace KWaylandServer
18 {
19 class PrimarySelectionSourceV1InterfacePrivate : public QtWaylandServer::zwp_primary_selection_source_v1
20 {
21 public:
22  PrimarySelectionSourceV1InterfacePrivate(PrimarySelectionSourceV1Interface *q, ::wl_resource *resource);
23 
25  PrimarySelectionSourceV1Interface *q;
26 
27 protected:
28  void zwp_primary_selection_source_v1_destroy_resource(Resource *resource) override;
29  void zwp_primary_selection_source_v1_offer(Resource *resource, const QString &mime_type) override;
30  void zwp_primary_selection_source_v1_destroy(Resource *resource) override;
31 };
32 
33 PrimarySelectionSourceV1InterfacePrivate::PrimarySelectionSourceV1InterfacePrivate(PrimarySelectionSourceV1Interface *_q, ::wl_resource *resource)
34  : QtWaylandServer::zwp_primary_selection_source_v1(resource)
35  , q(_q)
36 {
37 }
38 
39 void PrimarySelectionSourceV1InterfacePrivate::zwp_primary_selection_source_v1_destroy_resource(
40  QtWaylandServer::zwp_primary_selection_source_v1::Resource *resource)
41 {
42  Q_UNUSED(resource)
43  Q_EMIT q->aboutToBeDestroyed();
44  delete q;
45 }
46 
47 void PrimarySelectionSourceV1InterfacePrivate::zwp_primary_selection_source_v1_offer(Resource *, const QString &mimeType)
48 {
49  mimeTypes << mimeType;
50  Q_EMIT q->mimeTypeOffered(mimeType);
51 }
52 
53 void PrimarySelectionSourceV1InterfacePrivate::zwp_primary_selection_source_v1_destroy(QtWaylandServer::zwp_primary_selection_source_v1::Resource *resource)
54 {
55  wl_resource_destroy(resource->handle);
56 }
57 
58 PrimarySelectionSourceV1Interface::PrimarySelectionSourceV1Interface(PrimarySelectionDeviceManagerV1Interface *parent, ::wl_resource *resource)
59  : AbstractDataSource(parent)
60  , d(new PrimarySelectionSourceV1InterfacePrivate(this, resource))
61 {
62 }
63 
64 PrimarySelectionSourceV1Interface::~PrimarySelectionSourceV1Interface() = default;
65 
66 void PrimarySelectionSourceV1Interface::requestData(const QString &mimeType, qint32 fd)
67 {
68  d->send_send(mimeType, fd);
69  close(fd);
70 }
71 
72 void PrimarySelectionSourceV1Interface::cancel()
73 {
74  d->send_cancelled();
75 }
76 
77 QStringList PrimarySelectionSourceV1Interface::mimeTypes() const
78 {
79  return d->mimeTypes;
80 }
81 
82 wl_client *PrimarySelectionSourceV1Interface::client() const
83 {
84  return d->resource()->client();
85 }
86 
87 PrimarySelectionSourceV1Interface *PrimarySelectionSourceV1Interface::get(wl_resource *native)
88 {
89  if (auto sourcePrivate = resource_cast<PrimarySelectionSourceV1InterfacePrivate *>(native)) {
90  return sourcePrivate->q;
91  }
92  return nullptr;
93 }
94 
95 }
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 Mon Oct 25 2021 23:08:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.