1// Copyright (C) 2019 The Qt Company Ltd.
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 QWAYLANDPRIMARYSELECTIONV1_P_H
5#define QWAYLANDPRIMARYSELECTIONV1_P_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-wp-primary-selection-unstable-v1.h>
19
20#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
21#include <QtWaylandClient/private/qwaylanddataoffer_p.h>
22
23#include <QtCore/QObject>
24
25QT_REQUIRE_CONFIG(wayland_client_primary_selection);
26
27QT_BEGIN_NAMESPACE
28
29class QMimeData;
30
31namespace QtWaylandClient {
32
33class QWaylandInputDevice;
34class QWaylandPrimarySelectionDeviceV1;
35
36class QWaylandPrimarySelectionDeviceManagerV1 : public QtWayland::zwp_primary_selection_device_manager_v1
37{
38public:
39 explicit QWaylandPrimarySelectionDeviceManagerV1(QWaylandDisplay *display, uint id, uint version);
40 QWaylandPrimarySelectionDeviceV1 *createDevice(QWaylandInputDevice *seat);
41 QWaylandDisplay *display() const { return m_display; }
42
43private:
44 QWaylandDisplay *m_display = nullptr;
45};
46
47class QWaylandPrimarySelectionOfferV1 : public QtWayland::zwp_primary_selection_offer_v1, public QWaylandAbstractDataOffer
48{
49public:
50 explicit QWaylandPrimarySelectionOfferV1(QWaylandDisplay *display, ::zwp_primary_selection_offer_v1 *offer);
51 ~QWaylandPrimarySelectionOfferV1() override { destroy(); }
52 void startReceiving(const QString &mimeType, int fd) override;
53 QMimeData *mimeData() override { return m_mimeData.data(); }
54
55protected:
56 void zwp_primary_selection_offer_v1_offer(const QString &mime_type) override;
57
58private:
59 QWaylandDisplay *m_display = nullptr;
60 QScopedPointer<QWaylandMimeData> m_mimeData;
61};
62
63class Q_WAYLANDCLIENT_EXPORT QWaylandPrimarySelectionSourceV1 : public QObject, public QtWayland::zwp_primary_selection_source_v1
64{
65 Q_OBJECT
66public:
67 explicit QWaylandPrimarySelectionSourceV1(QWaylandPrimarySelectionDeviceManagerV1 *manager, QMimeData *mimeData);
68 ~QWaylandPrimarySelectionSourceV1() override;
69
70 QMimeData *mimeData() const { return m_mimeData; }
71
72signals:
73 void cancelled();
74
75protected:
76 void zwp_primary_selection_source_v1_send(const QString &mime_type, int32_t fd) override;
77 void zwp_primary_selection_source_v1_cancelled() override { emit cancelled(); }
78
79private:
80 QMimeData *m_mimeData = nullptr;
81};
82
83class QWaylandPrimarySelectionDeviceV1 : public QObject, public QtWayland::zwp_primary_selection_device_v1
84{
85 Q_OBJECT
86 QWaylandPrimarySelectionDeviceV1(QWaylandPrimarySelectionDeviceManagerV1 *manager, QWaylandInputDevice *seat);
87
88public:
89 ~QWaylandPrimarySelectionDeviceV1() override;
90 QWaylandPrimarySelectionOfferV1 *selectionOffer() const { return m_selectionOffer.data(); }
91 void invalidateSelectionOffer();
92 QWaylandPrimarySelectionSourceV1 *selectionSource() const { return m_selectionSource.data(); }
93 void setSelectionSource(QWaylandPrimarySelectionSourceV1 *source);
94
95protected:
96 void zwp_primary_selection_device_v1_data_offer(struct ::zwp_primary_selection_offer_v1 *offer) override;
97 void zwp_primary_selection_device_v1_selection(struct ::zwp_primary_selection_offer_v1 *id) override;
98
99private:
100 QWaylandDisplay *m_display = nullptr;
101 QWaylandInputDevice *m_seat = nullptr;
102 QScopedPointer<QWaylandPrimarySelectionOfferV1> m_selectionOffer;
103 QScopedPointer<QWaylandPrimarySelectionSourceV1> m_selectionSource;
104 friend class QWaylandPrimarySelectionDeviceManagerV1;
105};
106
107} // namespace QtWaylandClient
108
109QT_END_NAMESPACE
110
111#endif // QWAYLANDPRIMARYSELECTIONV1_P_H
112

source code of qtwayland/src/client/qwaylandprimaryselectionv1_p.h