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_DATADEVICE_H 0007 #define WAYLAND_DATADEVICE_H 0008 0009 #include "dataoffer.h" 0010 0011 #include <QObject> 0012 0013 #include "KWayland/Client/kwaylandclient_export.h" 0014 0015 struct wl_data_device; 0016 0017 namespace KWayland 0018 { 0019 namespace Client 0020 { 0021 class DataSource; 0022 class Surface; 0023 0024 /** 0025 * @short DataDevice allows clients to share data by copy-and-paste and drag-and-drop. 0026 * 0027 * This class is a convenient wrapper for the wl_data_device interface. 0028 * To create a DataDevice call DataDeviceManager::getDataDevice. 0029 * 0030 * @see DataDeviceManager 0031 **/ 0032 class KWAYLANDCLIENT_EXPORT DataDevice : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit DataDevice(QObject *parent = nullptr); 0037 ~DataDevice() override; 0038 0039 /** 0040 * Setup this DataDevice to manage the @p dataDevice. 0041 * When using DataDeviceManager::createDataDevice there is no need to call this 0042 * method. 0043 **/ 0044 void setup(wl_data_device *dataDevice); 0045 /** 0046 * Releases the wl_data_device interface. 0047 * After the interface has been released the DataDevice instance is no 0048 * longer valid and can be setup with another wl_data_device interface. 0049 **/ 0050 void release(); 0051 /** 0052 * Destroys the data held by this DataDevice. 0053 * This method is supposed to be used when the connection to the Wayland 0054 * server goes away. If the connection is not valid anymore, it's not 0055 * possible to call release anymore as that calls into the Wayland 0056 * connection and the call would fail. This method cleans up the data, so 0057 * that the instance can be deleted or set up to a new wl_data_device interface 0058 * once there is a new connection available. 0059 * 0060 * This method is automatically invoked when the Registry which created this 0061 * DataDevice gets destroyed. 0062 * 0063 * @see release 0064 **/ 0065 void destroy(); 0066 /** 0067 * @returns @c true if managing a wl_data_device. 0068 **/ 0069 bool isValid() const; 0070 0071 void startDrag(quint32 serial, DataSource *source, Surface *origin, Surface *icon = nullptr); 0072 void startDragInternally(quint32 serial, Surface *origin, Surface *icon = nullptr); 0073 0074 void setSelection(quint32 serial, DataSource *source = nullptr); 0075 void clearSelection(quint32 serial); 0076 0077 DataOffer *offeredSelection() const; 0078 0079 /** 0080 * @returns the currently focused surface during drag'n'drop on this DataDevice. 0081 * @since 5.22 0082 **/ 0083 QPointer<Surface> dragSurface() const; 0084 /** 0085 * @returns the DataOffer during a drag'n'drop operation. 0086 * @since 5.22 0087 **/ 0088 DataOffer *dragOffer() const; 0089 0090 operator wl_data_device *(); 0091 operator wl_data_device *() const; 0092 0093 Q_SIGNALS: 0094 void selectionOffered(KWayland::Client::DataOffer *); 0095 void selectionCleared(); 0096 /** 0097 * Notification that a drag'n'drop operation entered a Surface on this DataDevice. 0098 * 0099 * @param serial The serial for this enter 0100 * @param relativeToSurface Coordinates relative to the upper-left corner of the Surface. 0101 * @see dragSurface 0102 * @see dragOffer 0103 * @see dragLeft 0104 * @see dragMotion 0105 * @since 5.22 0106 **/ 0107 void dragEntered(quint32 serial, const QPointF &relativeToSurface); 0108 /** 0109 * Notification that the drag'n'drop operation left the Surface on this DataDevice. 0110 * 0111 * The leave notification is sent before the enter notification for the new focus. 0112 * @see dragEnter 0113 * @since 5.22 0114 **/ 0115 void dragLeft(); 0116 /** 0117 * Notification of drag motion events on the current drag surface. 0118 * 0119 * @param relativeToSurface Coordinates relative to the upper-left corner of the entered Surface. 0120 * @param time timestamp with millisecond granularity 0121 * @see dragEntered 0122 * @since 5.22 0123 **/ 0124 void dragMotion(const QPointF &relativeToSurface, quint32 time); 0125 /** 0126 * Emitted when the implicit grab is removed and the drag'n'drop operation ended on this 0127 * DataDevice. 0128 * 0129 * The client can now start a data transfer on the DataOffer. 0130 * @see dragEntered 0131 * @see dragOffer 0132 * @since 5.22 0133 **/ 0134 void dropped(); 0135 0136 private: 0137 class Private; 0138 QScopedPointer<Private> d; 0139 }; 0140 0141 } 0142 } 0143 0144 #endif