| 1 | // Copyright (C) 2024 Jie Liu <liujie01@kylinos.cn> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDDATACONTROLV1_H |
| 5 | #define QWAYLANDDATACONTROLV1_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWaylandClient/private/qwayland-wlr-data-control-unstable-v1.h> |
| 19 | |
| 20 | #include <QtWaylandClient/private/qtwaylandclientglobal_p.h> |
| 21 | #include <QtWaylandClient/private/qwaylanddataoffer_p.h> |
| 22 | |
| 23 | #include <QtCore/QObject> |
| 24 | |
| 25 | QT_REQUIRE_CONFIG(clipboard); |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QMimeData; |
| 30 | |
| 31 | namespace QtWaylandClient { |
| 32 | |
| 33 | class QWaylandInputDevice; |
| 34 | class QWaylandDataControlDeviceV1; |
| 35 | |
| 36 | class QWaylandDataControlManagerV1 : public QtWayland::zwlr_data_control_manager_v1 |
| 37 | { |
| 38 | public: |
| 39 | explicit QWaylandDataControlManagerV1(QWaylandDisplay *display, uint id, uint version); |
| 40 | QWaylandDataControlDeviceV1 *createDevice(QWaylandInputDevice *seat); |
| 41 | QWaylandDisplay *display() const { return m_display; } |
| 42 | |
| 43 | private: |
| 44 | QWaylandDisplay *m_display = nullptr; |
| 45 | }; |
| 46 | |
| 47 | class QWaylandDataControlOfferV1 : public QtWayland::zwlr_data_control_offer_v1, public QWaylandAbstractDataOffer |
| 48 | { |
| 49 | public: |
| 50 | explicit QWaylandDataControlOfferV1(QWaylandDisplay *display, ::zwlr_data_control_offer_v1 *offer); |
| 51 | ~QWaylandDataControlOfferV1() override { destroy(); } |
| 52 | void startReceiving(const QString &mimeType, int fd) override; |
| 53 | QMimeData *mimeData() override { return m_mimeData.data(); } |
| 54 | |
| 55 | protected: |
| 56 | void zwlr_data_control_offer_v1_offer(const QString &mime_type) override; |
| 57 | |
| 58 | private: |
| 59 | QWaylandDisplay *m_display = nullptr; |
| 60 | QScopedPointer<QWaylandMimeData> m_mimeData; |
| 61 | }; |
| 62 | |
| 63 | class Q_WAYLANDCLIENT_EXPORT QWaylandDataControlSourceV1 : public QObject, public QtWayland::zwlr_data_control_source_v1 |
| 64 | { |
| 65 | Q_OBJECT |
| 66 | public: |
| 67 | explicit QWaylandDataControlSourceV1(QWaylandDataControlManagerV1 *manager, QMimeData *mimeData); |
| 68 | ~QWaylandDataControlSourceV1() override; |
| 69 | |
| 70 | QMimeData *mimeData() const { return m_mimeData; } |
| 71 | |
| 72 | Q_SIGNALS: |
| 73 | void cancelled(); |
| 74 | |
| 75 | protected: |
| 76 | void zwlr_data_control_source_v1_send(const QString &mime_type, int32_t fd) override; |
| 77 | void zwlr_data_control_source_v1_cancelled() override { Q_EMIT cancelled(); } |
| 78 | |
| 79 | private: |
| 80 | QWaylandDisplay *m_display = nullptr; |
| 81 | QMimeData *m_mimeData = nullptr; |
| 82 | }; |
| 83 | |
| 84 | class QWaylandDataControlDeviceV1 : public QObject, public QtWayland::zwlr_data_control_device_v1 |
| 85 | { |
| 86 | Q_OBJECT |
| 87 | QWaylandDataControlDeviceV1(QWaylandDataControlManagerV1 *manager, QWaylandInputDevice *seat); |
| 88 | |
| 89 | public: |
| 90 | ~QWaylandDataControlDeviceV1() override; |
| 91 | QWaylandDataControlOfferV1 *primarySelectionOffer() const { return m_primarySelectionOffer.data(); } |
| 92 | QWaylandDataControlOfferV1 *selectionOffer() const { return m_selectionOffer.data(); } |
| 93 | void invalidateSelectionOffer(); |
| 94 | QWaylandDataControlSourceV1 *selectionSource() const { return m_selectionSource.data(); } |
| 95 | QWaylandDataControlSourceV1 *primarySelectionSource() const { return m_primarySelectionSource.data(); } |
| 96 | void setSelectionSource(QWaylandDataControlSourceV1 *source); |
| 97 | void setPrimarySelectionSource(QWaylandDataControlSourceV1 *source); |
| 98 | |
| 99 | protected: |
| 100 | void zwlr_data_control_device_v1_data_offer(struct ::zwlr_data_control_offer_v1 *id) override; |
| 101 | void zwlr_data_control_device_v1_selection(struct ::zwlr_data_control_offer_v1 *id) override; |
| 102 | void zwlr_data_control_device_v1_finished() override; |
| 103 | void zwlr_data_control_device_v1_primary_selection(struct ::zwlr_data_control_offer_v1 *id) override; |
| 104 | |
| 105 | private: |
| 106 | QWaylandDisplay *m_display = nullptr; |
| 107 | QWaylandInputDevice *m_seat = nullptr; |
| 108 | QScopedPointer<QWaylandDataControlOfferV1> m_selectionOffer; |
| 109 | QScopedPointer<QWaylandDataControlOfferV1> m_primarySelectionOffer; |
| 110 | QScopedPointer<QWaylandDataControlSourceV1> m_selectionSource; |
| 111 | QScopedPointer<QWaylandDataControlSourceV1> m_primarySelectionSource; |
| 112 | friend class QWaylandDataControlManagerV1; |
| 113 | }; |
| 114 | |
| 115 | } // namespace QtWaylandClient |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif // QWAYLANDDATACONTROLV1_H |
| 120 | |