KWin
Loading...
Searching...
No Matches
primaryselectiondevice_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 "display.h"
11#include "seat.h"
12#include "seat_p.h"
13
14// Wayland
15#include <qwayland-server-wp-primary-selection-unstable-v1.h>
16
17namespace KWin
18{
19class PrimarySelectionDeviceV1InterfacePrivate : public QtWaylandServer::zwp_primary_selection_device_v1
20{
21public:
23
25
28 QPointer<PrimarySelectionSourceV1Interface> selection;
29
30private:
31 void setSelection(PrimarySelectionSourceV1Interface *dataSource);
32
33protected:
34 void zwp_primary_selection_device_v1_destroy_resource(Resource *resource) override;
35 void zwp_primary_selection_device_v1_set_selection(Resource *resource, wl_resource *source, uint32_t serial) override;
36 void zwp_primary_selection_device_v1_destroy(Resource *resource) override;
37};
38
40 SeatInterface *seat,
41 wl_resource *resource)
42 : QtWaylandServer::zwp_primary_selection_device_v1(resource)
43 , q(_q)
44 , seat(seat)
45{
46}
47
48void PrimarySelectionDeviceV1InterfacePrivate::zwp_primary_selection_device_v1_set_selection(Resource *resource, wl_resource *source, uint32_t serial)
49{
50 PrimarySelectionSourceV1Interface *dataSource = nullptr;
51
52 if (source) {
53 dataSource = PrimarySelectionSourceV1Interface::get(source);
54 Q_ASSERT(dataSource);
55 }
56
57 if (selection == dataSource) {
58 return;
59 }
60 if (selection) {
61 selection->cancel();
62 }
63 selection = dataSource;
64 if (selection) {
66 }
67}
68
69void PrimarySelectionDeviceV1InterfacePrivate::zwp_primary_selection_device_v1_destroy(QtWaylandServer::zwp_primary_selection_device_v1::Resource *resource)
70{
71 wl_resource_destroy(resource->handle);
72}
73
75{
76 if (!source) {
77 // a data offer can only exist together with a source
78 return nullptr;
79 }
80
81 wl_resource *data_offer_resource = wl_resource_create(resource()->client(), &zwp_primary_selection_offer_v1_interface, resource()->version(), 0);
82 if (!data_offer_resource) {
83 wl_resource_post_no_memory(resource()->handle);
84 return nullptr;
85 }
86
87 PrimarySelectionOfferV1Interface *offer = new PrimarySelectionOfferV1Interface(source, data_offer_resource);
88 send_data_offer(offer->resource());
89 offer->sendAllOffers();
90 return offer;
91}
92
94 QtWaylandServer::zwp_primary_selection_device_v1::Resource *resource)
95{
96 delete q;
97}
98
99PrimarySelectionDeviceV1Interface::PrimarySelectionDeviceV1Interface(SeatInterface *seat, wl_resource *resource)
100 : QObject()
101 , d(new PrimarySelectionDeviceV1InterfacePrivate(this, seat, resource))
102{
104 seatPrivate->registerPrimarySelectionDevice(this);
105}
106
108
110{
111 return d->seat;
112}
113
118
120{
121 PrimarySelectionOfferV1Interface *offer = d->createDataOffer(other);
122 d->send_selection(offer ? offer->resource() : nullptr);
123}
124
126{
127 return d->resource()->client();
128}
129
130}
131
132#include "moc_primaryselectiondevice_v1.cpp"
The AbstractDataSource class abstracts the data that can be transferred to another client.
Represents the Resource for the wl_data_device interface.
PrimarySelectionSourceV1Interface * selection() const
void selectionChanged(KWin::PrimarySelectionSourceV1Interface *)
PrimarySelectionOfferV1Interface * createDataOffer(AbstractDataSource *source)
void zwp_primary_selection_device_v1_destroy_resource(Resource *resource) override
QPointer< PrimarySelectionSourceV1Interface > selection
void zwp_primary_selection_device_v1_destroy(Resource *resource) override
void zwp_primary_selection_device_v1_set_selection(Resource *resource, wl_resource *source, uint32_t serial) override
PrimarySelectionDeviceV1InterfacePrivate(PrimarySelectionDeviceV1Interface *q, SeatInterface *seat, wl_resource *resource)
Represents the Resource for the wl_data_offer interface. Lifespan is mapped to the underlying object.
Represents the Resource for the zwp_primary_selection_source_v1 interface. Lifespan is mapped to the ...
static PrimarySelectionSourceV1Interface * get(wl_resource *native)
Represents a Seat on the Wayland Display.
Definition seat.h:134
void registerPrimarySelectionDevice(PrimarySelectionDeviceV1Interface *primarySelectionDevice)
Definition seat.cpp:231
static KWIN_EXPORT SeatInterfacePrivate * get(SeatInterface *seat)
Definition seat.cpp:44
constexpr int version