KWin
Loading...
Searching...
No Matches
datacontroloffer_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*/
9// Qt
10#include <QPointer>
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 DataControlOfferV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_offer_v1
20{
21public:
23
25 QPointer<AbstractDataSource> source;
26
27protected:
28 void zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override;
29 void zwlr_data_control_offer_v1_destroy(Resource *resource) override;
30 void zwlr_data_control_offer_v1_destroy_resource(Resource *resource) override;
31};
32
34 : QtWaylandServer::zwlr_data_control_offer_v1(resource)
35 , q(_q)
36 , source(source)
37{
38}
39
40void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
41{
42 wl_resource_destroy(resource->handle);
43}
44
45void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy_resource(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
46{
47 delete q;
48}
49
50void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mimeType, qint32 fd)
51{
52 if (!source) {
53 close(fd);
54 return;
55 }
56 source->requestData(mimeType, fd);
57}
58
59DataControlOfferV1Interface::DataControlOfferV1Interface(AbstractDataSource *source, wl_resource *resource)
60 : QObject()
61 , d(new DataControlOfferV1InterfacePrivate(this, source, resource))
62{
63 Q_ASSERT(source);
64 connect(source, &AbstractDataSource::mimeTypeOffered, this, [this](const QString &mimeType) {
65 d->send_offer(mimeType);
66 });
67}
68
70
72{
73 Q_ASSERT(d->source);
74 for (const QString &mimeType : d->source->mimeTypes()) {
75 d->send_offer(mimeType);
76 }
77}
78
80{
81 return d->resource()->handle;
82}
83
84}
85
86#include "moc_datacontroloffer_v1.cpp"
The AbstractDataSource class abstracts the data that can be transferred to another client.
void mimeTypeOffered(const QString &)
void zwlr_data_control_offer_v1_destroy_resource(Resource *resource) override
DataControlOfferV1InterfacePrivate(DataControlOfferV1Interface *q, AbstractDataSource *source, wl_resource *resource)
void zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override
void zwlr_data_control_offer_v1_destroy(Resource *resource) override