File indexing completed on 2024-12-22 05:09:19

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #ifndef WAYLAND_DATA_DEVICE_MANAGER_H
0007 #define WAYLAND_DATA_DEVICE_MANAGER_H
0008 
0009 #include <QObject>
0010 
0011 #include "KWayland/Client/kwaylandclient_export.h"
0012 
0013 struct wl_data_device_manager;
0014 
0015 namespace KWayland
0016 {
0017 namespace Client
0018 {
0019 class EventQueue;
0020 class DataDevice;
0021 class DataSource;
0022 class Seat;
0023 
0024 /**
0025  * @short Wrapper for the wl_data_device_manager interface.
0026  *
0027  * This class provides a convenient wrapper for the wl_data_device_manager interface.
0028  *
0029  * To use this class one needs to interact with the Registry. There are two
0030  * possible ways to create the DataDeviceManager interface:
0031  * @code
0032  * DataDeviceManager *m = registry->createDataDeviceManager(name, version);
0033  * @endcode
0034  *
0035  * This creates the DataDeviceManager and sets it up directly. As an alternative this
0036  * can also be done in a more low level way:
0037  * @code
0038  * DataDeviceManager *m = new DataDeviceManager;
0039  * m->setup(registry->bindDataDeviceManager(name, version));
0040  * @endcode
0041  *
0042  * The DataDeviceManager can be used as a drop-in replacement for any wl_data_device_manager
0043  * pointer as it provides matching cast operators.
0044  *
0045  * @see Registry
0046  **/
0047 class KWAYLANDCLIENT_EXPORT DataDeviceManager : public QObject
0048 {
0049     Q_OBJECT
0050 public:
0051     /**
0052      * Drag and Drop actions supported by DataSource and DataOffer.
0053      * @since 5.42
0054      **/
0055     enum class DnDAction {
0056         None = 0,
0057         Copy = 1 << 0,
0058         Move = 1 << 1,
0059         Ask = 1 << 2,
0060     };
0061     Q_DECLARE_FLAGS(DnDActions, DnDAction)
0062 
0063     /**
0064      * Creates a new Compositor.
0065      * Note: after constructing the Compositor it is not yet valid and one needs
0066      * to call setup. In order to get a ready to use Compositor prefer using
0067      * Registry::createCompositor.
0068      **/
0069     explicit DataDeviceManager(QObject *parent = nullptr);
0070     ~DataDeviceManager() override;
0071 
0072     /**
0073      * @returns @c true if managing a wl_data_device_manager.
0074      **/
0075     bool isValid() const;
0076     /**
0077      * Setup this DataDeviceManager to manage the @p manager.
0078      * When using Registry::createDataDeviceManager there is no need to call this
0079      * method.
0080      **/
0081     void setup(wl_data_device_manager *manager);
0082     /**
0083      * Releases the wl_data_device_manager interface.
0084      * After the interface has been released the DataDeviceManager instance is no
0085      * longer valid and can be setup with another wl_data_device_manager interface.
0086      **/
0087     void release();
0088     /**
0089      * Destroys the data held by this DataDeviceManager.
0090      * This method is supposed to be used when the connection to the Wayland
0091      * server goes away. If the connection is not valid anymore, it's not
0092      * possible to call release anymore as that calls into the Wayland
0093      * connection and the call would fail. This method cleans up the data, so
0094      * that the instance can be deleted or set up to a new wl_data_device_manager interface
0095      * once there is a new connection available.
0096      *
0097      * This method is automatically invoked when the Registry which created this
0098      * DataDeviceManager gets destroyed.
0099      *
0100      * @see release
0101      **/
0102     void destroy();
0103 
0104     /**
0105      * Sets the @p queue to use for creating a DataSource.
0106      **/
0107     void setEventQueue(EventQueue *queue);
0108     /**
0109      * @returns The event queue to use for creating a DataSource.
0110      **/
0111     EventQueue *eventQueue();
0112 
0113     DataSource *createDataSource(QObject *parent = nullptr);
0114 
0115     DataDevice *getDataDevice(Seat *seat, QObject *parent = nullptr);
0116 
0117     operator wl_data_device_manager *();
0118     operator wl_data_device_manager *() const;
0119 
0120 Q_SIGNALS:
0121     /**
0122      * The corresponding global for this interface on the Registry got removed.
0123      *
0124      * This signal gets only emitted if the Compositor got created by
0125      * Registry::createDataDeviceManager
0126      *
0127      * @since 5.5
0128      **/
0129     void removed();
0130 
0131 private:
0132     class Private;
0133     QScopedPointer<Private> d;
0134 };
0135 
0136 Q_DECLARE_OPERATORS_FOR_FLAGS(DataDeviceManager::DnDActions)
0137 
0138 }
0139 }
0140 
0141 #endif