KWin
Loading...
Searching...
No Matches
datacontroldevice_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
3 SPDX-FileCopyrightText: 2021 David Redondo <kde@david-redondo.de>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
11#include "display.h"
12#include "seat.h"
13#include "seat_p.h"
14#include "surface.h"
15
16// Wayland
17#include <qwayland-server-wlr-data-control-unstable-v1.h>
18
19namespace KWin
20{
21class DataControlDeviceV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_device_v1
22{
23public:
25
27
29 QPointer<SeatInterface> seat;
30 QPointer<DataControlSourceV1Interface> selection;
31 QPointer<DataControlSourceV1Interface> primarySelection;
32
33protected:
34 void zwlr_data_control_device_v1_destroy_resource(Resource *resource) override;
35 void zwlr_data_control_device_v1_set_selection(Resource *resource, wl_resource *source) override;
36 void zwlr_data_control_device_v1_set_primary_selection(Resource *resource, struct ::wl_resource *source) override;
37 void zwlr_data_control_device_v1_destroy(Resource *resource) override;
38};
39
41 : QtWaylandServer::zwlr_data_control_device_v1(resource)
42 , q(_q)
43 , seat(seat)
44{
45}
46
48{
49 DataControlSourceV1Interface *dataSource = nullptr;
50
51 if (source) {
52 dataSource = DataControlSourceV1Interface::get(source);
53 Q_ASSERT(dataSource);
54 if (dataSource == seat->selection() || dataSource == seat->primarySelection()) {
55 wl_resource_post_error(resource->handle, error::error_used_source, "source given to set_selection was already used before");
56 return;
57 }
58 }
59 if (selection) {
60 selection->cancel();
61 }
62 selection = dataSource;
64}
65
67{
68 DataControlSourceV1Interface *dataSource = nullptr;
69
70 if (source) {
71 dataSource = DataControlSourceV1Interface::get(source);
72 Q_ASSERT(dataSource);
73 if (dataSource == seat->selection() || dataSource == seat->primarySelection()) {
74 wl_resource_post_error(resource->handle, error::error_used_source, "source given to set_primary_selection was already used before");
75 return;
76 }
77 }
78 if (primarySelection) {
79 primarySelection->cancel();
80 }
81 primarySelection = dataSource;
83}
84
85void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_destroy(QtWaylandServer::zwlr_data_control_device_v1::Resource *resource)
86{
87 wl_resource_destroy(resource->handle);
88}
89
91{
92 if (!source) {
93 // a data offer can only exist together with a source
94 return nullptr;
95 }
96
97 wl_resource *data_offer_resource = wl_resource_create(resource()->client(), &zwlr_data_control_offer_v1_interface, resource()->version(), 0);
98 if (!data_offer_resource) {
99 return nullptr;
100 }
101
102 DataControlOfferV1Interface *offer = new DataControlOfferV1Interface(source, data_offer_resource);
103 send_data_offer(offer->resource());
104 offer->sendAllOffers();
105 return offer;
106}
107
108void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_destroy_resource(QtWaylandServer::zwlr_data_control_device_v1::Resource *resource)
109{
110 delete q;
111}
112
113DataControlDeviceV1Interface::DataControlDeviceV1Interface(SeatInterface *seat, wl_resource *resource)
114 : QObject()
115 , d(new DataControlDeviceV1InterfacePrivate(this, seat, resource))
116{
118 seatPrivate->registerDataControlDevice(this);
119}
120
122
124{
125 return d->seat;
126}
127
132
134{
135 return d->primarySelection;
136}
137
139{
140 DataControlOfferV1Interface *offer = d->createDataOffer(other);
141 d->send_selection(offer ? offer->resource() : nullptr);
142}
143
145{
146 if (d->resource()->version() >= ZWLR_DATA_CONTROL_DEVICE_V1_PRIMARY_SELECTION_SINCE_VERSION) {
147 DataControlOfferV1Interface *offer = d->createDataOffer(other);
148 d->send_primary_selection(offer ? offer->resource() : nullptr);
149 }
150}
151}
152
153#include "moc_datacontroldevice_v1.cpp"
The AbstractDataSource class abstracts the data that can be transferred to another client.
DataControlSourceV1Interface * selection() const
void primarySelectionChanged(KWin::DataControlSourceV1Interface *dataSource)
void sendPrimarySelection(AbstractDataSource *other)
void sendSelection(AbstractDataSource *other)
void selectionChanged(KWin::DataControlSourceV1Interface *dataSource)
DataControlSourceV1Interface * primarySelection() const
void zwlr_data_control_device_v1_set_primary_selection(Resource *resource, struct ::wl_resource *source) override
void zwlr_data_control_device_v1_destroy_resource(Resource *resource) override
void zwlr_data_control_device_v1_destroy(Resource *resource) override
void zwlr_data_control_device_v1_set_selection(Resource *resource, wl_resource *source) override
QPointer< DataControlSourceV1Interface > primarySelection
DataControlOfferV1Interface * createDataOffer(AbstractDataSource *source)
DataControlDeviceV1InterfacePrivate(DataControlDeviceV1Interface *q, SeatInterface *seat, wl_resource *resource)
QPointer< DataControlSourceV1Interface > selection
static DataControlSourceV1Interface * get(wl_resource *native)
Represents a Seat on the Wayland Display.
Definition seat.h:134
void registerDataControlDevice(DataControlDeviceV1Interface *dataDevice)
Definition seat.cpp:191
static KWIN_EXPORT SeatInterfacePrivate * get(SeatInterface *seat)
Definition seat.cpp:44
constexpr int version