1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#ifndef WAYLAND_DATA_DEVICE_MANAGER_H
7#define WAYLAND_DATA_DEVICE_MANAGER_H
8
9#include <QObject>
10
11#include "KWayland/Client/kwaylandclient_export.h"
12
13struct wl_data_device_manager;
14
15namespace KWayland
16{
17namespace Client
18{
19class EventQueue;
20class DataDevice;
21class DataSource;
22class Seat;
23
24/**
25 * @short Wrapper for the wl_data_device_manager interface.
26 *
27 * This class provides a convenient wrapper for the wl_data_device_manager interface.
28 *
29 * To use this class one needs to interact with the Registry. There are two
30 * possible ways to create the DataDeviceManager interface:
31 * @code
32 * DataDeviceManager *m = registry->createDataDeviceManager(name, version);
33 * @endcode
34 *
35 * This creates the DataDeviceManager and sets it up directly. As an alternative this
36 * can also be done in a more low level way:
37 * @code
38 * DataDeviceManager *m = new DataDeviceManager;
39 * m->setup(registry->bindDataDeviceManager(name, version));
40 * @endcode
41 *
42 * The DataDeviceManager can be used as a drop-in replacement for any wl_data_device_manager
43 * pointer as it provides matching cast operators.
44 *
45 * @see Registry
46 **/
47class KWAYLANDCLIENT_EXPORT DataDeviceManager : public QObject
48{
49 Q_OBJECT
50public:
51 /**
52 * Drag and Drop actions supported by DataSource and DataOffer.
53 * @since 5.42
54 **/
55 enum class DnDAction {
56 None = 0,
57 Copy = 1 << 0,
58 Move = 1 << 1,
59 Ask = 1 << 2,
60 };
61 Q_DECLARE_FLAGS(DnDActions, DnDAction)
62
63 /**
64 * Creates a new Compositor.
65 * Note: after constructing the Compositor it is not yet valid and one needs
66 * to call setup. In order to get a ready to use Compositor prefer using
67 * Registry::createCompositor.
68 **/
69 explicit DataDeviceManager(QObject *parent = nullptr);
70 ~DataDeviceManager() override;
71
72 /**
73 * @returns @c true if managing a wl_data_device_manager.
74 **/
75 bool isValid() const;
76 /**
77 * Setup this DataDeviceManager to manage the @p manager.
78 * When using Registry::createDataDeviceManager there is no need to call this
79 * method.
80 **/
81 void setup(wl_data_device_manager *manager);
82 /**
83 * Releases the wl_data_device_manager interface.
84 * After the interface has been released the DataDeviceManager instance is no
85 * longer valid and can be setup with another wl_data_device_manager interface.
86 **/
87 void release();
88 /**
89 * Destroys the data held by this DataDeviceManager.
90 * This method is supposed to be used when the connection to the Wayland
91 * server goes away. If the connection is not valid anymore, it's not
92 * possible to call release anymore as that calls into the Wayland
93 * connection and the call would fail. This method cleans up the data, so
94 * that the instance can be deleted or set up to a new wl_data_device_manager interface
95 * once there is a new connection available.
96 *
97 * This method is automatically invoked when the Registry which created this
98 * DataDeviceManager gets destroyed.
99 *
100 * @see release
101 **/
102 void destroy();
103
104 /**
105 * Sets the @p queue to use for creating a DataSource.
106 **/
107 void setEventQueue(EventQueue *queue);
108 /**
109 * @returns The event queue to use for creating a DataSource.
110 **/
111 EventQueue *eventQueue();
112
113 DataSource *createDataSource(QObject *parent = nullptr);
114
115 DataDevice *getDataDevice(Seat *seat, QObject *parent = nullptr);
116
117 operator wl_data_device_manager *();
118 operator wl_data_device_manager *() const;
119
120Q_SIGNALS:
121 /**
122 * The corresponding global for this interface on the Registry got removed.
123 *
124 * This signal gets only emitted if the Compositor got created by
125 * Registry::createDataDeviceManager
126 *
127 * @since 5.5
128 **/
129 void removed();
130
131private:
132 class Private;
133 QScopedPointer<Private> d;
134};
135
136Q_DECLARE_OPERATORS_FOR_FLAGS(DataDeviceManager::DnDActions)
137
138}
139}
140
141#endif
142

source code of kwayland/src/client/datadevicemanager.h