Commit e08b201b authored by David Edmundson's avatar David Edmundson
Browse files

Introduce AbstractDataSource round the DataSourceInterface

Summary:
Clipboard managers and middle click paste are new protocols.

We want to be able to copy from a clipboard manager to a regular
clipboard and vice versa without duplicating loads of code.

If we support kliper's "syncronise contents of the clipboard and
selection" inside the compositor that would become an unmanageable amount
of combinations.

It also potentially allows the idea of our XWayland bridge not being a
wayland client and simplifying that code.

Test Plan: Unit test passes

Reviewers: #kwin

Subscribers: zzag

Differential Revision: https://phabricator.kde.org/D29329
parent f9da1809
set(SERVER_LIB_SRCS
../compat/wayland-xdg-shell-v5-protocol.c
abstract_data_source.cpp
appmenu_interface.cpp
blur_interface.cpp
buffer_interface.cpp
......@@ -329,6 +330,7 @@ install(TARGETS KWaylandServer EXPORT KWaylandServerTargets ${KF5_INSTALL_TARGET
set(SERVER_LIB_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/KWaylandServer/kwaylandserver_export.h
abstract_data_source.h
appmenu_interface.h
blur_interface.h
buffer_interface.h
......
/*
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "abstract_data_source.h"
using namespace KWaylandServer;
AbstractDataSource::AbstractDataSource(Resource::Private *d, QObject *parent)
: Resource(d, parent)
{}
/*
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include "resource.h"
#include "clientconnection.h"
#include "datadevicemanager_interface.h"
#include <KWaylandServer/kwaylandserver_export.h>
struct wl_client;
namespace KWaylandServer {
/**
* @brief The AbstractDataSource class abstracts the data that
* can be transferred to another client.
*
* It loosely maps to DataDeviceInterface
*/
// Anything related to selections are pure virtual, content relating
// to drag and drop has a default implementation
// TODO ideally this shouldn't inherit from resource as it provides some misleading public methods
// This can be resolved once DataSource is ported to the new system
class KWAYLANDSERVER_EXPORT AbstractDataSource : public Resource
{
Q_OBJECT
public:
virtual void accept(const QString &mimeType) {
Q_UNUSED(mimeType);
};
virtual void requestData(const QString &mimeType, qint32 fd) = 0;
virtual void cancel() = 0;
virtual QStringList mimeTypes() const = 0;
/**
* @returns The Drag and Drop actions supported by this DataSourceInterface.
**/
virtual DataDeviceManagerInterface::DnDActions supportedDragAndDropActions() const {
return {};
};
/**
* The user performed the drop action during a drag and drop operation.
**/
virtual void dropPerformed() {};
/**
* The drop destination finished interoperating with this data source.
**/
virtual void dndFinished() {};
/**
* This event indicates the @p action selected by the compositor after matching the
* source/destination side actions. Only one action (or none) will be offered here.
**/
virtual void dndAction(DataDeviceManagerInterface::DnDAction action) {
Q_UNUSED(action);
};
virtual wl_client* client() {
return Resource::client()->client();
}
Q_SIGNALS:
void mimeTypeOffered(const QString&);
void supportedDragAndDropActionsChanged();
protected:
explicit AbstractDataSource(Resource::Private *d, QObject *parent = nullptr);
};
}
......@@ -24,7 +24,7 @@ public:
Private(SeatInterface *seat, DataDeviceInterface *q, DataDeviceManagerInterface *manager, wl_resource *parentResource);
~Private();
DataOfferInterface *createDataOffer(DataSourceInterface *source);
DataOfferInterface *createDataOffer(AbstractDataSource *source);
SeatInterface *seat;
DataSourceInterface *source = nullptr;
......@@ -149,7 +149,7 @@ void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource)
}
}
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source)
DataOfferInterface *DataDeviceInterface::Private::createDataOffer(AbstractDataSource *source)
{
if (!resource) {
return nullptr;
......@@ -209,7 +209,7 @@ DataSourceInterface *DataDeviceInterface::selection() const
return d->selection;
}
void DataDeviceInterface::sendSelection(DataSourceInterface *other)
void DataDeviceInterface::sendSelection(AbstractDataSource *other)
{
Q_D();
auto r = d->createDataOffer(other);
......
......@@ -18,6 +18,7 @@ namespace KWaylandServer
class DataDeviceManagerInterface;
class DataOfferInterface;
class DataSourceInterface;
class AbstractDataSource;
class SeatInterface;
class SurfaceInterface;
......@@ -51,7 +52,7 @@ public:
DataSourceInterface *selection() const;
void sendSelection(DataSourceInterface *other);
void sendSelection(KWaylandServer::AbstractDataSource *other);
void sendClearSelection();
/**
* The event is sent when a drag-and-drop operation is ended because the implicit grab is removed.
......
......@@ -26,7 +26,7 @@ const struct wl_data_offer_interface DataOfferInterface::Private::s_interface =
};
#endif
DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource)
DataOfferInterface::Private::Private(AbstractDataSource *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource)
: Resource::Private(q, nullptr, parentResource, &wl_data_offer_interface, &s_interface)
, source(source)
, dataDevice(parentInterface)
......@@ -137,7 +137,7 @@ void DataOfferInterface::Private::sendSourceActions()
wl_data_offer_send_source_actions(resource, wlActions);
}
DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource)
DataOfferInterface::DataOfferInterface(AbstractDataSource *source, DataDeviceInterface *parentInterface, wl_resource *parentResource)
: Resource(new Private(source, parentInterface, this, parentResource))
{
Q_ASSERT(source);
......
......@@ -17,7 +17,7 @@ namespace KWaylandServer
{
class DataDeviceInterface;
class DataSourceInterface;
class AbstractDataSource;
/**
* @brief Represents the Resource for the wl_data_offer interface.
......@@ -59,7 +59,7 @@ Q_SIGNALS:
private:
friend class DataDeviceInterface;
explicit DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource);
explicit DataOfferInterface(AbstractDataSource *source, DataDeviceInterface *parentInterface, wl_resource *parentResource);
class Private;
Private *d_func() const;
......
......@@ -16,9 +16,9 @@ namespace KWaylandServer
class Q_DECL_HIDDEN DataOfferInterface::Private : public Resource::Private
{
public:
Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource);
Private(AbstractDataSource *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource);
~Private();
DataSourceInterface *source;
AbstractDataSource *source;
DataDeviceInterface *dataDevice;
// defaults are set to sensible values for < version 3 interfaces
DataDeviceManagerInterface::DnDActions supportedDnDActions = DataDeviceManagerInterface::DnDAction::Copy | DataDeviceManagerInterface::DnDAction::Move;
......
......@@ -92,7 +92,7 @@ void DataSourceInterface::Private::setActionsCallback(wl_client *client, wl_reso
}
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *parentResource)
: Resource(new Private(this, parent, parentResource))
: AbstractDataSource(new Private(this, parent, parentResource))
{
if (wl_resource_get_version(parentResource) < WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
Q_D();
......@@ -126,7 +126,7 @@ void DataSourceInterface::cancel()
return;
}
wl_data_source_send_cancelled(d->resource);
client()->flush();
Resource::client()->flush();
}
QStringList DataSourceInterface::mimeTypes() const
......
......@@ -6,11 +6,10 @@
#ifndef WAYLAND_SERVER_DATA_SOURCE_INTERFACE_H
#define WAYLAND_SERVER_DATA_SOURCE_INTERFACE_H
#include <QObject>
#include "abstract_data_source.h"
#include <KWaylandServer/kwaylandserver_export.h>
#include "resource.h"
#include "datadevicemanager_interface.h"
namespace KWaylandServer
......@@ -19,17 +18,17 @@ namespace KWaylandServer
/**
* @brief Represents the Resource for the wl_data_source interface.
**/
class KWAYLANDSERVER_EXPORT DataSourceInterface : public Resource
class KWAYLANDSERVER_EXPORT DataSourceInterface : public AbstractDataSource
{
Q_OBJECT
public:
virtual ~DataSourceInterface();
void accept(const QString &mimeType);
void requestData(const QString &mimeType, qint32 fd);
void cancel();
void accept(const QString &mimeType) override;
void requestData(const QString &mimeType, qint32 fd) override;
void cancel() override;
QStringList mimeTypes() const;
QStringList mimeTypes() const override;
static DataSourceInterface *get(wl_resource *native);
......@@ -37,32 +36,11 @@ public:
* @returns The Drag and Drop actions supported by this DataSourceInterface.
* @since 5.42
**/
DataDeviceManagerInterface::DnDActions supportedDragAndDropActions() const;
DataDeviceManagerInterface::DnDActions supportedDragAndDropActions() const override;
/**
* The user performed the drop action during a drag and drop operation.
* @since 5.42
**/
void dropPerformed();
/**
* The drop destination finished interoperating with this data source.
* @since 5.42
**/
void dndFinished();
/**
* This event indicates the @p action selected by the compositor after matching the
* source/destination side actions. Only one action (or none) will be offered here.
* @since 5.42
**/
void dndAction(DataDeviceManagerInterface::DnDAction action);
Q_SIGNALS:
void mimeTypeOffered(const QString&);
/**
* Emitted whenever this DataSourceInterface changes the supported drag and drop actions
* @since 5.42
**/
void supportedDragAndDropActionsChanged();
void dropPerformed() override;
void dndFinished() override;
void dndAction(DataDeviceManagerInterface::DnDAction action) override;
private:
friend class DataDeviceManagerInterface;
......
......@@ -3,6 +3,7 @@
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "abstract_data_source.h"
#include "seat_interface.h"
#include "seat_interface_p.h"
#include "display.h"
......@@ -1554,13 +1555,13 @@ TextInputInterface *SeatInterface::focusedTextInput() const
return d->textInput.focus.textInput;
}
DataSourceInterface *SeatInterface::selection() const
AbstractDataSource *SeatInterface::selection() const
{
Q_D();
return d->currentSelection;
}
void SeatInterface::setSelection(DataSourceInterface *selection)
void SeatInterface::setSelection(AbstractDataSource *selection)
{
Q_D();
if (d->currentSelection == selection) {
......
......@@ -23,7 +23,7 @@ namespace KWaylandServer
{
class DataDeviceInterface;
class DataSourceInterface;
class AbstractDataSource;
class Display;
class SurfaceInterface;
class TextInputInterface;
......@@ -695,7 +695,7 @@ public:
* @see setSelection
* This may be null
**/
DataSourceInterface *selection() const;
KWaylandServer::AbstractDataSource *selection() const;
/**
* This method allows to manually set the @p dataDevice for the current clipboard selection.
......@@ -710,7 +710,7 @@ public:
* @see selectionChanged
* @since 5.24
**/
void setSelection(DataSourceInterface *selection);
void setSelection(AbstractDataSource *selection);
static SeatInterface *get(wl_resource *native);
......@@ -739,7 +739,7 @@ Q_SIGNALS:
* @see selection
* @see setSelection
**/
void selectionChanged(DataSourceInterface*);
void selectionChanged(KWaylandServer::AbstractDataSource*);
/**
* Emitted when a drag'n'drop operation is started
......
......@@ -19,6 +19,7 @@
namespace KWaylandServer
{
class AbstractDataSource;
class DataDeviceInterface;
class TextInputInterface;
......@@ -52,7 +53,7 @@ public:
QVector<TextInputInterface*> textInputs;
// the last thing copied into the clipboard content
DataSourceInterface *currentSelection = nullptr;
AbstractDataSource *currentSelection = nullptr;
// Pointer related members
struct Pointer {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment