2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2020-06-25 15:27:52 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2014-11-04 14:10:22 +00:00
|
|
|
#include "datasource_interface.h"
|
2014-11-14 08:45:02 +00:00
|
|
|
#include "datadevicemanager_interface.h"
|
2016-09-12 06:57:07 +00:00
|
|
|
#include "clientconnection.h"
|
2014-11-14 08:45:02 +00:00
|
|
|
#include "resource_p.h"
|
2014-11-04 14:10:22 +00:00
|
|
|
// Qt
|
|
|
|
#include <QStringList>
|
|
|
|
// Wayland
|
2020-06-25 15:27:52 +00:00
|
|
|
#include <qwayland-server-wayland.h>
|
2014-11-27 10:23:37 +00:00
|
|
|
// system
|
|
|
|
#include <unistd.h>
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
class DataSourceInterfacePrivate : public QtWaylandServer::wl_data_source
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-06-25 15:27:52 +00:00
|
|
|
DataSourceInterfacePrivate(DataSourceInterface *_q, ::wl_resource *resource);
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
DataSourceInterface *q;
|
2014-11-04 14:10:22 +00:00
|
|
|
QStringList mimeTypes;
|
2017-12-26 20:55:11 +00:00
|
|
|
DataDeviceManagerInterface::DnDActions supportedDnDActions = DataDeviceManagerInterface::DnDAction::None;
|
2020-10-28 11:58:25 +00:00
|
|
|
bool isAccepted = false;
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
protected:
|
|
|
|
void data_source_destroy_resource(Resource *resource) override;
|
|
|
|
void data_source_offer(Resource *resource, const QString &mime_type) override;
|
|
|
|
void data_source_destroy(Resource *resource) override;
|
|
|
|
void data_source_set_actions(Resource *resource, uint32_t dnd_actions) override;
|
|
|
|
|
2014-11-04 14:10:22 +00:00
|
|
|
private:
|
|
|
|
void offer(const QString &mimeType);
|
|
|
|
};
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
DataSourceInterfacePrivate::DataSourceInterfacePrivate(DataSourceInterface *_q, ::wl_resource *resource)
|
|
|
|
: QtWaylandServer::wl_data_source(resource)
|
|
|
|
, q(_q)
|
|
|
|
{
|
|
|
|
}
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
void DataSourceInterfacePrivate::data_source_destroy_resource(Resource *resource)
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
emit q->aboutToBeDestroyed();
|
|
|
|
delete q;
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
void DataSourceInterfacePrivate::data_source_offer(QtWaylandServer::wl_data_source::Resource *resource, const QString &mime_type)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
mimeTypes << mime_type;
|
|
|
|
emit q->mimeTypeOffered(mime_type);
|
|
|
|
}
|
2014-11-04 14:10:22 +00:00
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
void DataSourceInterfacePrivate::data_source_destroy(QtWaylandServer::wl_data_source::Resource *resource)
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
wl_resource_destroy(resource->handle);
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
void DataSourceInterfacePrivate::offer(const QString &mimeType)
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
mimeTypes << mimeType;
|
|
|
|
emit q->mimeTypeOffered(mimeType);
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
void DataSourceInterfacePrivate::data_source_set_actions(Resource *resource, uint32_t dnd_actions)
|
2017-11-26 15:31:57 +00:00
|
|
|
{
|
2020-10-28 13:26:20 +00:00
|
|
|
// verify that the no other actions are sent
|
|
|
|
if (dnd_actions & ~(QtWaylandServer::wl_data_device_manager::dnd_action_copy |
|
|
|
|
QtWaylandServer::wl_data_device_manager::dnd_action_move |
|
|
|
|
QtWaylandServer::wl_data_device_manager::dnd_action_ask)) {
|
|
|
|
wl_resource_post_error(resource->handle, error_invalid_action_mask, "Invalid action mask");
|
|
|
|
return;
|
|
|
|
}
|
2017-11-26 15:31:57 +00:00
|
|
|
DataDeviceManagerInterface::DnDActions supportedActions;
|
2020-06-25 15:27:52 +00:00
|
|
|
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_copy) {
|
2017-11-26 15:31:57 +00:00
|
|
|
supportedActions |= DataDeviceManagerInterface::DnDAction::Copy;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_move) {
|
2017-11-26 15:31:57 +00:00
|
|
|
supportedActions |= DataDeviceManagerInterface::DnDAction::Move;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
if (dnd_actions & QtWaylandServer::wl_data_device_manager::dnd_action_ask) {
|
2017-11-26 15:31:57 +00:00
|
|
|
supportedActions |= DataDeviceManagerInterface::DnDAction::Ask;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
if (supportedDnDActions!= supportedActions) {
|
|
|
|
supportedDnDActions = supportedActions;
|
|
|
|
emit q->supportedDragAndDropActionsChanged();
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:27:52 +00:00
|
|
|
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *resource)
|
|
|
|
: AbstractDataSource(parent)
|
|
|
|
, d(new DataSourceInterfacePrivate(this, resource))
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
if (d->resource()->version() < WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
|
2017-12-26 20:55:11 +00:00
|
|
|
d->supportedDnDActions = DataDeviceManagerInterface::DnDAction::Copy;
|
|
|
|
}
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceInterface::~DataSourceInterface() = default;
|
|
|
|
|
|
|
|
void DataSourceInterface::accept(const QString &mimeType)
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_target(mimeType);
|
2020-10-28 11:58:25 +00:00
|
|
|
d->isAccepted = !mimeType.isNull();
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::requestData(const QString &mimeType, qint32 fd)
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_send(mimeType, int32_t(fd));
|
2014-11-27 10:23:37 +00:00
|
|
|
close(fd);
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::cancel()
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_cancelled();
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList DataSourceInterface::mimeTypes() const
|
|
|
|
{
|
|
|
|
return d->mimeTypes;
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:22:15 +00:00
|
|
|
DataSourceInterface *DataSourceInterface::get(wl_resource *native)
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
if (!native) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto priv = static_cast<DataSourceInterfacePrivate*>(QtWaylandServer::wl_data_source::Resource::fromResource(native)->object());
|
|
|
|
return priv->q;
|
2014-11-14 08:45:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 15:31:57 +00:00
|
|
|
DataDeviceManagerInterface::DnDActions DataSourceInterface::supportedDragAndDropActions() const
|
|
|
|
{
|
|
|
|
return d->supportedDnDActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::dropPerformed()
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
if (d->resource()->version() < WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {
|
2017-11-26 15:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_dnd_drop_performed();
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::dndFinished()
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
if (d->resource()->version() < WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) {
|
2017-11-26 15:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_dnd_finished();
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::dndAction(DataDeviceManagerInterface::DnDAction action)
|
|
|
|
{
|
2020-06-25 15:27:52 +00:00
|
|
|
if (d->resource()->version() < WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
|
2017-11-26 15:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
uint32_t wlAction = QtWaylandServer::wl_data_device_manager::dnd_action_none;
|
2017-11-26 15:31:57 +00:00
|
|
|
if (action == DataDeviceManagerInterface::DnDAction::Copy) {
|
2020-06-25 15:27:52 +00:00
|
|
|
wlAction = QtWaylandServer::wl_data_device_manager::dnd_action_copy;
|
2017-11-26 15:31:57 +00:00
|
|
|
} else if (action == DataDeviceManagerInterface::DnDAction::Move ) {
|
2020-06-25 15:27:52 +00:00
|
|
|
wlAction = QtWaylandServer::wl_data_device_manager::dnd_action_move;
|
2017-11-26 15:31:57 +00:00
|
|
|
} else if (action == DataDeviceManagerInterface::DnDAction::Ask) {
|
2020-06-25 15:27:52 +00:00
|
|
|
wlAction = QtWaylandServer::wl_data_device_manager::dnd_action_ask;
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
2020-06-25 15:27:52 +00:00
|
|
|
d->send_action(wlAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource *DataSourceInterface::resource() const
|
|
|
|
{
|
|
|
|
return d->resource()->handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_client *DataSourceInterface::client() const
|
|
|
|
{
|
|
|
|
return d->resource()->client();
|
2017-11-26 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 11:58:25 +00:00
|
|
|
bool DataSourceInterface::isAccepted() const
|
|
|
|
{
|
|
|
|
return d->isAccepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::setAccepted(bool accepted)
|
|
|
|
{
|
|
|
|
d->isAccepted = accepted;
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:22:15 +00:00
|
|
|
}
|