KWin
Loading...
Searching...
No Matches
primaryselectionoffer_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-wp-primary-selection-unstable-v1.h>
14// system
15#include <unistd.h>
16
17namespace KWin
18{
19class PrimarySelectionOfferV1InterfacePrivate : public QtWaylandServer::zwp_primary_selection_offer_v1
20{
21public:
24 QPointer<AbstractDataSource> source;
25
26protected:
27 void zwp_primary_selection_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override;
28 void zwp_primary_selection_offer_v1_destroy(Resource *resource) override;
29 void zwp_primary_selection_offer_v1_destroy_resource(Resource *resource) override;
30};
31
33 AbstractDataSource *source,
34 wl_resource *resource)
35 : QtWaylandServer::zwp_primary_selection_offer_v1(resource)
36 , q(_q)
37 , source(source)
38{
39}
40
41void PrimarySelectionOfferV1InterfacePrivate::zwp_primary_selection_offer_v1_destroy(QtWaylandServer::zwp_primary_selection_offer_v1::Resource *resource)
42{
43 wl_resource_destroy(resource->handle);
44}
45
47 QtWaylandServer::zwp_primary_selection_offer_v1::Resource *resource)
48{
49 delete q;
50}
51
52void PrimarySelectionOfferV1InterfacePrivate::zwp_primary_selection_offer_v1_receive(Resource *resource, const QString &mimeType, qint32 fd)
53{
54 if (!source) {
55 close(fd);
56 return;
57 }
58 source->requestData(mimeType, fd);
59}
60
61PrimarySelectionOfferV1Interface::PrimarySelectionOfferV1Interface(AbstractDataSource *source, wl_resource *resource)
62 : QObject()
63 , d(new PrimarySelectionOfferV1InterfacePrivate(this, source, resource))
64{
65 Q_ASSERT(source);
66 connect(source, &AbstractDataSource::mimeTypeOffered, this, [this](const QString &mimeType) {
67 d->send_offer(mimeType);
68 });
69}
70
72
74{
75 for (const QString &mimeType : d->source->mimeTypes()) {
76 d->send_offer(mimeType);
77 }
78}
79
81{
82 return d->resource()->handle;
83}
84
85}
86
87#include "moc_primaryselectionoffer_v1.cpp"
The AbstractDataSource class abstracts the data that can be transferred to another client.
void mimeTypeOffered(const QString &)
Represents the Resource for the wl_data_offer interface. Lifespan is mapped to the underlying object.
void zwp_primary_selection_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override
void zwp_primary_selection_offer_v1_destroy_resource(Resource *resource) override
void zwp_primary_selection_offer_v1_destroy(Resource *resource) override
PrimarySelectionOfferV1InterfacePrivate(PrimarySelectionOfferV1Interface *q, AbstractDataSource *source, wl_resource *resource)