2020-05-12 11:26:57 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
2021-08-10 12:29:35 +00:00
|
|
|
SPDX-FileCopyrightText: 2021 David Redondo <kde@david-redondo.de>
|
2020-05-12 11:26:57 +00:00
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2020-05-28 07:25:56 +00:00
|
|
|
#include "datacontroldevice_v1_interface.h"
|
|
|
|
#include "datacontroldevicemanager_v1_interface.h"
|
|
|
|
#include "datacontroloffer_v1_interface.h"
|
|
|
|
#include "datacontrolsource_v1_interface.h"
|
2020-05-12 11:26:57 +00:00
|
|
|
#include "display.h"
|
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "seat_interface_p.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "surface_interface.h"
|
2020-05-12 11:26:57 +00:00
|
|
|
|
|
|
|
// Wayland
|
|
|
|
#include <qwayland-server-wlr-data-control-unstable-v1.h>
|
|
|
|
|
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
2021-08-29 05:11:06 +00:00
|
|
|
class DataControlDeviceV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_device_v1
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlDeviceV1InterfacePrivate(DataControlDeviceV1Interface *q, SeatInterface *seat, wl_resource *resource);
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface *createDataOffer(AbstractDataSource *source);
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlDeviceV1Interface *q;
|
2020-05-12 11:26:57 +00:00
|
|
|
QPointer<SeatInterface> seat;
|
2020-05-28 07:25:56 +00:00
|
|
|
QPointer<DataControlSourceV1Interface> selection;
|
2021-08-10 12:29:35 +00:00
|
|
|
QPointer<DataControlSourceV1Interface> primarySelection;
|
2020-05-12 11:26:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void zwlr_data_control_device_v1_destroy_resource(Resource *resource) override;
|
|
|
|
void zwlr_data_control_device_v1_set_selection(Resource *resource, wl_resource *source) override;
|
2021-08-29 05:11:06 +00:00
|
|
|
void zwlr_data_control_device_v1_set_primary_selection(Resource *resource, struct ::wl_resource *source) override;
|
2020-05-12 11:26:57 +00:00
|
|
|
void zwlr_data_control_device_v1_destroy(Resource *resource) override;
|
|
|
|
};
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlDeviceV1InterfacePrivate::DataControlDeviceV1InterfacePrivate(DataControlDeviceV1Interface *_q, SeatInterface *seat, wl_resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
: QtWaylandServer::zwlr_data_control_device_v1(resource)
|
2021-08-29 05:11:06 +00:00
|
|
|
, q(_q)
|
2020-05-12 11:26:57 +00:00
|
|
|
, seat(seat)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_set_selection(Resource *resource, wl_resource *source)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlSourceV1Interface *dataSource = nullptr;
|
2020-05-12 11:26:57 +00:00
|
|
|
|
|
|
|
if (source) {
|
2020-05-28 07:25:56 +00:00
|
|
|
dataSource = DataControlSourceV1Interface::get(source);
|
2021-08-29 05:11:06 +00:00
|
|
|
Q_ASSERT(dataSource);
|
|
|
|
if (dataSource == seat->selection() || dataSource == seat->primarySelection()) {
|
|
|
|
wl_resource_post_error(resource->handle, error::error_used_source, "source given to set_selection was already used before");
|
2020-05-12 11:26:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selection) {
|
|
|
|
selection->cancel();
|
|
|
|
}
|
|
|
|
selection = dataSource;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->selectionChanged(selection);
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 12:29:35 +00:00
|
|
|
void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_set_primary_selection(Resource *resource, wl_resource *source)
|
|
|
|
{
|
|
|
|
DataControlSourceV1Interface *dataSource = nullptr;
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
dataSource = DataControlSourceV1Interface::get(source);
|
2021-08-29 05:11:06 +00:00
|
|
|
Q_ASSERT(dataSource);
|
|
|
|
if (dataSource == seat->selection() || dataSource == seat->primarySelection()) {
|
|
|
|
wl_resource_post_error(resource->handle, error::error_used_source, "source given to set_primary_selection was already used before");
|
2021-08-10 12:29:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (primarySelection) {
|
|
|
|
primarySelection->cancel();
|
|
|
|
}
|
|
|
|
primarySelection = dataSource;
|
|
|
|
Q_EMIT q->primarySelectionChanged(primarySelection);
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_destroy(QtWaylandServer::zwlr_data_control_device_v1::Resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface *DataControlDeviceV1InterfacePrivate::createDataOffer(AbstractDataSource *source)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
if (!source) {
|
|
|
|
// a data offer can only exist together with a source
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource *data_offer_resource = wl_resource_create(resource()->client(), &zwlr_data_control_offer_v1_interface, resource()->version(), 0);
|
|
|
|
if (!data_offer_resource) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface *offer = new DataControlOfferV1Interface(source, data_offer_resource);
|
2020-05-12 11:26:57 +00:00
|
|
|
send_data_offer(offer->resource());
|
|
|
|
offer->sendAllOffers();
|
|
|
|
return offer;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlDeviceV1InterfacePrivate::zwlr_data_control_device_v1_destroy_resource(QtWaylandServer::zwlr_data_control_device_v1::Resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlDeviceV1Interface::DataControlDeviceV1Interface(SeatInterface *seat, wl_resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
: QObject()
|
2020-05-28 07:25:56 +00:00
|
|
|
, d(new DataControlDeviceV1InterfacePrivate(this, seat, resource))
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
2021-02-13 15:40:56 +00:00
|
|
|
SeatInterfacePrivate *seatPrivate = SeatInterfacePrivate::get(seat);
|
|
|
|
seatPrivate->registerDataControlDevice(this);
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlDeviceV1Interface::~DataControlDeviceV1Interface() = default;
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
SeatInterface *DataControlDeviceV1Interface::seat() const
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
return d->seat;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlSourceV1Interface *DataControlDeviceV1Interface::selection() const
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
return d->selection;
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:29:35 +00:00
|
|
|
DataControlSourceV1Interface *DataControlDeviceV1Interface::primarySelection() const
|
|
|
|
{
|
|
|
|
return d->primarySelection;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlDeviceV1Interface::sendSelection(AbstractDataSource *other)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
if (!other) {
|
|
|
|
sendClearSelection();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-28 07:34:20 +00:00
|
|
|
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
|
|
|
if (!offer) {
|
2020-05-12 11:26:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-28 07:34:20 +00:00
|
|
|
d->send_selection(offer->resource());
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlDeviceV1Interface::sendClearSelection()
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
d->send_selection(nullptr);
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:29:35 +00:00
|
|
|
void DataControlDeviceV1Interface::sendPrimarySelection(KWaylandServer::AbstractDataSource *other)
|
|
|
|
{
|
|
|
|
if (!other) {
|
|
|
|
sendClearPrimarySelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DataControlOfferV1Interface *offer = d->createDataOffer(other);
|
|
|
|
if (!offer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->send_primary_selection(offer->resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataControlDeviceV1Interface::sendClearPrimarySelection()
|
|
|
|
{
|
|
|
|
d->send_primary_selection(nullptr);
|
|
|
|
}
|
|
|
|
|
2020-05-12 11:26:57 +00:00
|
|
|
}
|