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_DATADEVICE_H |
7 | #define WAYLAND_DATADEVICE_H |
8 | |
9 | #include "dataoffer.h" |
10 | |
11 | #include <QObject> |
12 | |
13 | #include "KWayland/Client/kwaylandclient_export.h" |
14 | |
15 | struct wl_data_device; |
16 | |
17 | namespace KWayland |
18 | { |
19 | namespace Client |
20 | { |
21 | class DataSource; |
22 | class Surface; |
23 | |
24 | /** |
25 | * @short DataDevice allows clients to share data by copy-and-paste and drag-and-drop. |
26 | * |
27 | * This class is a convenient wrapper for the wl_data_device interface. |
28 | * To create a DataDevice call DataDeviceManager::getDataDevice. |
29 | * |
30 | * @see DataDeviceManager |
31 | **/ |
32 | class KWAYLANDCLIENT_EXPORT DataDevice : public QObject |
33 | { |
34 | Q_OBJECT |
35 | public: |
36 | explicit DataDevice(QObject *parent = nullptr); |
37 | ~DataDevice() override; |
38 | |
39 | /** |
40 | * Setup this DataDevice to manage the @p dataDevice. |
41 | * When using DataDeviceManager::createDataDevice there is no need to call this |
42 | * method. |
43 | **/ |
44 | void setup(wl_data_device *dataDevice); |
45 | /** |
46 | * Releases the wl_data_device interface. |
47 | * After the interface has been released the DataDevice instance is no |
48 | * longer valid and can be setup with another wl_data_device interface. |
49 | **/ |
50 | void release(); |
51 | /** |
52 | * Destroys the data held by this DataDevice. |
53 | * This method is supposed to be used when the connection to the Wayland |
54 | * server goes away. If the connection is not valid anymore, it's not |
55 | * possible to call release anymore as that calls into the Wayland |
56 | * connection and the call would fail. This method cleans up the data, so |
57 | * that the instance can be deleted or set up to a new wl_data_device interface |
58 | * once there is a new connection available. |
59 | * |
60 | * This method is automatically invoked when the Registry which created this |
61 | * DataDevice gets destroyed. |
62 | * |
63 | * @see release |
64 | **/ |
65 | void destroy(); |
66 | /** |
67 | * @returns @c true if managing a wl_data_device. |
68 | **/ |
69 | bool isValid() const; |
70 | |
71 | void startDrag(quint32 serial, DataSource *source, Surface *origin, Surface *icon = nullptr); |
72 | void startDragInternally(quint32 serial, Surface *origin, Surface *icon = nullptr); |
73 | |
74 | void setSelection(quint32 serial, DataSource *source = nullptr); |
75 | void clearSelection(quint32 serial); |
76 | |
77 | DataOffer *offeredSelection() const; |
78 | |
79 | /** |
80 | * @returns the currently focused surface during drag'n'drop on this DataDevice. |
81 | * @since 5.22 |
82 | **/ |
83 | QPointer<Surface> dragSurface() const; |
84 | /** |
85 | * @returns the DataOffer during a drag'n'drop operation. |
86 | * @since 5.22 |
87 | **/ |
88 | DataOffer *dragOffer() const; |
89 | |
90 | operator wl_data_device *(); |
91 | operator wl_data_device *() const; |
92 | |
93 | Q_SIGNALS: |
94 | void selectionOffered(KWayland::Client::DataOffer *); |
95 | void selectionCleared(); |
96 | /** |
97 | * Notification that a drag'n'drop operation entered a Surface on this DataDevice. |
98 | * |
99 | * @param serial The serial for this enter |
100 | * @param relativeToSurface Coordinates relative to the upper-left corner of the Surface. |
101 | * @see dragSurface |
102 | * @see dragOffer |
103 | * @see dragLeft |
104 | * @see dragMotion |
105 | * @since 5.22 |
106 | **/ |
107 | void dragEntered(quint32 serial, const QPointF &relativeToSurface); |
108 | /** |
109 | * Notification that the drag'n'drop operation left the Surface on this DataDevice. |
110 | * |
111 | * The leave notification is sent before the enter notification for the new focus. |
112 | * @see dragEnter |
113 | * @since 5.22 |
114 | **/ |
115 | void dragLeft(); |
116 | /** |
117 | * Notification of drag motion events on the current drag surface. |
118 | * |
119 | * @param relativeToSurface Coordinates relative to the upper-left corner of the entered Surface. |
120 | * @param time timestamp with millisecond granularity |
121 | * @see dragEntered |
122 | * @since 5.22 |
123 | **/ |
124 | void dragMotion(const QPointF &relativeToSurface, quint32 time); |
125 | /** |
126 | * Emitted when the implicit grab is removed and the drag'n'drop operation ended on this |
127 | * DataDevice. |
128 | * |
129 | * The client can now start a data transfer on the DataOffer. |
130 | * @see dragEntered |
131 | * @see dragOffer |
132 | * @since 5.22 |
133 | **/ |
134 | void dropped(); |
135 | |
136 | private: |
137 | class Private; |
138 | QScopedPointer<Private> d; |
139 | }; |
140 | |
141 | } |
142 | } |
143 | |
144 | #endif |
145 | |