Index: src/server/CMakeLists.txt =================================================================== --- src/server/CMakeLists.txt +++ src/server/CMakeLists.txt @@ -1,5 +1,6 @@ set(SERVER_LIB_SRCS ../compat/wayland-xdg-shell-v5-protocol.c + abstract_data_source.cpp appmenu_interface.cpp blur_interface.cpp buffer_interface.cpp @@ -331,6 +332,7 @@ 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 Index: src/server/abstract_data_source.h =================================================================== --- /dev/null +++ src/server/abstract_data_source.h @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2020 David Edmundson + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#pragma once + +#include "resource.h" + +#include "datadevicemanager_interface.h" + +#include + +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 + +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); + }; + +Q_SIGNALS: + void mimeTypeOffered(const QString&); + void supportedDragAndDropActionsChanged(); + +protected: + explicit AbstractDataSource(Resource::Private *d, QObject *parent = nullptr); +}; + +} Index: src/server/abstract_data_source.cpp =================================================================== --- /dev/null +++ src/server/abstract_data_source.cpp @@ -0,0 +1,13 @@ +/* + SPDX-FileCopyrightText: 2020 David Edmundson + + 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) +{} Index: src/server/datadevice_interface.h =================================================================== --- src/server/datadevice_interface.h +++ src/server/datadevice_interface.h @@ -18,6 +18,7 @@ class DataDeviceManagerInterface; class DataOfferInterface; class DataSourceInterface; +class AbstractDataSource; class SeatInterface; class SurfaceInterface; @@ -51,7 +52,7 @@ 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. Index: src/server/datadevice_interface.cpp =================================================================== --- src/server/datadevice_interface.cpp +++ src/server/datadevice_interface.cpp @@ -24,7 +24,7 @@ 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 @@ } } -DataOfferInterface *DataDeviceInterface::Private::createDataOffer(DataSourceInterface *source) +DataOfferInterface *DataDeviceInterface::Private::createDataOffer(AbstractDataSource *source) { if (!resource) { return nullptr; @@ -209,7 +209,7 @@ return d->selection; } -void DataDeviceInterface::sendSelection(DataSourceInterface *other) +void DataDeviceInterface::sendSelection(AbstractDataSource *other) { Q_D(); auto r = d->createDataOffer(other); Index: src/server/dataoffer_interface.h =================================================================== --- src/server/dataoffer_interface.h +++ src/server/dataoffer_interface.h @@ -17,7 +17,7 @@ { class DataDeviceInterface; -class DataSourceInterface; +class AbstractDataSource; /** * @brief Represents the Resource for the wl_data_offer interface. @@ -59,7 +59,7 @@ 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; Index: src/server/dataoffer_interface.cpp =================================================================== --- src/server/dataoffer_interface.cpp +++ src/server/dataoffer_interface.cpp @@ -26,7 +26,7 @@ }; #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 @@ 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); Index: src/server/dataoffer_interface_p.h =================================================================== --- src/server/dataoffer_interface_p.h +++ src/server/dataoffer_interface_p.h @@ -16,9 +16,9 @@ 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; Index: src/server/datasource_interface.h =================================================================== --- src/server/datasource_interface.h +++ src/server/datasource_interface.h @@ -6,63 +6,41 @@ #ifndef WAYLAND_SERVER_DATA_SOURCE_INTERFACE_H #define WAYLAND_SERVER_DATA_SOURCE_INTERFACE_H -#include +#include "abstract_data_source.h" #include -#include "resource.h" #include "datadevicemanager_interface.h" 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); /** * @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; Index: src/server/datasource_interface.cpp =================================================================== --- src/server/datasource_interface.cpp +++ src/server/datasource_interface.cpp @@ -92,7 +92,7 @@ } 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(); Index: src/server/seat_interface.h =================================================================== --- src/server/seat_interface.h +++ src/server/seat_interface.h @@ -23,7 +23,7 @@ { class DataDeviceInterface; -class DataSourceInterface; +class AbstractDataSource; class Display; class SurfaceInterface; class TextInputInterface; @@ -695,7 +695,7 @@ * @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 @@ * @see selectionChanged * @since 5.24 **/ - void setSelection(DataSourceInterface *selection); + void setSelection(AbstractDataSource *selection); static SeatInterface *get(wl_resource *native); @@ -739,7 +739,7 @@ * @see selection * @see setSelection **/ - void selectionChanged(DataSourceInterface*); + void selectionChanged(KWaylandServer::AbstractDataSource*); /** * Emitted when a drag'n'drop operation is started Index: src/server/seat_interface.cpp =================================================================== --- src/server/seat_interface.cpp +++ src/server/seat_interface.cpp @@ -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" @@ -1547,13 +1548,13 @@ 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) { Index: src/server/seat_interface_p.h =================================================================== --- src/server/seat_interface_p.h +++ src/server/seat_interface_p.h @@ -19,6 +19,7 @@ namespace KWaylandServer { +class AbstractDataSource; class DataDeviceInterface; class TextInputInterface; @@ -52,7 +53,7 @@ QVector textInputs; // the last thing copied into the clipboard content - DataSourceInterface *currentSelection = nullptr; + AbstractDataSource *currentSelection = nullptr; // Pointer related members struct Pointer {