KWin
Loading...
Searching...
No Matches
datacontrolsource_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
7#include "clientconnection.h"
9#include "utils/resource.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
17namespace KWin
18{
19class DataControlSourceV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_source_v1
20{
21public:
23
24 QStringList mimeTypes;
26
27protected:
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
34 : QtWaylandServer::zwlr_data_control_source_v1(resource)
35 , q(_q)
36{
37}
38
39void DataControlSourceV1InterfacePrivate::zwlr_data_control_source_v1_destroy_resource(QtWaylandServer::zwlr_data_control_source_v1::Resource *resource)
40{
41 Q_EMIT q->aboutToBeDestroyed();
42 delete q;
43}
44
46{
47 mimeTypes << mimeType;
48 Q_EMIT q->mimeTypeOffered(mimeType);
49}
50
51void DataControlSourceV1InterfacePrivate::zwlr_data_control_source_v1_destroy(QtWaylandServer::zwlr_data_control_source_v1::Resource *resource)
52{
53 wl_resource_destroy(resource->handle);
54}
55
56DataControlSourceV1Interface::DataControlSourceV1Interface(DataControlDeviceManagerV1Interface *parent, ::wl_resource *resource)
57 : AbstractDataSource(parent)
58 , d(new DataControlSourceV1InterfacePrivate(this, resource))
59{
60}
61
63
64void DataControlSourceV1Interface::requestData(const QString &mimeType, qint32 fd)
65{
66 d->send_send(mimeType, fd);
67 close(fd);
68}
69
71{
72 d->send_cancelled();
73}
74
76{
77 return d->mimeTypes;
78}
79
81{
82 return d->resource()->client();
83}
84
86{
87 if (auto sourcePrivate = resource_cast<DataControlSourceV1InterfacePrivate *>(native)) {
88 return sourcePrivate->q;
89 }
90 return nullptr;
91}
92
93}
94
95#include "moc_datacontrolsource_v1.cpp"
The AbstractDataSource class abstracts the data that can be transferred to another client.
void mimeTypeOffered(const QString &)
static DataControlSourceV1Interface * get(wl_resource *native)
wl_client * client() const override
void requestData(const QString &mimeType, qint32 fd) override
QStringList mimeTypes() const override
void zwlr_data_control_source_v1_destroy(Resource *resource) override
void zwlr_data_control_source_v1_destroy_resource(Resource *resource) override
DataControlSourceV1InterfacePrivate(DataControlSourceV1Interface *q, ::wl_resource *resource)
void zwlr_data_control_source_v1_offer(Resource *resource, const QString &mime_type) override