1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef WLDATADEVICEMANAGER_H
5#define WLDATADEVICEMANAGER_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 <QtCore/QList>
19#include <QtCore/QMap>
20#include <QtGui/QClipboard>
21#include <QtCore/QMimeData>
22
23#include <QtWaylandCompositor/QWaylandCompositor>
24
25#include <QtWaylandCompositor/private/qwayland-server-wayland.h>
26#include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h>
27
28QT_REQUIRE_CONFIG(wayland_datadevice);
29
30QT_BEGIN_NAMESPACE
31
32class QSocketNotifier;
33
34namespace QtWayland {
35
36class DataDevice;
37class DataSource;
38
39class DataDeviceManager : public QObject, public QtWaylandServer::wl_data_device_manager
40{
41 Q_OBJECT
42
43public:
44 DataDeviceManager(QWaylandCompositor *compositor);
45
46 void setCurrentSelectionSource(DataSource *source);
47 DataSource *currentSelectionSource();
48
49 struct wl_display *display() const;
50
51 void sourceDestroyed(DataSource *source);
52
53 void overrideSelection(const QMimeData &mimeData);
54 bool offerFromCompositorToClient(wl_resource *clientDataDeviceResource);
55 void offerRetainedSelection(wl_resource *clientDataDeviceResource);
56
57protected:
58 void data_device_manager_create_data_source(Resource *resource, uint32_t id) override;
59 void data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat) override;
60
61private Q_SLOTS:
62 void readFromClient(int fd);
63
64private:
65 void retain();
66 void finishReadFromClient(bool exhausted = false);
67
68 QWaylandCompositor *m_compositor = nullptr;
69 QList<DataDevice *> m_data_device_list;
70
71 DataSource *m_current_selection_source = nullptr;
72
73 QMimeData m_retainedData;
74 QSocketNotifier *m_retainedReadNotifier = nullptr;
75 QList<QSocketNotifier *> m_obsoleteRetainedReadNotifiers;
76 int m_retainedReadIndex = 0;
77 QByteArray m_retainedReadBuf;
78
79 bool m_compositorOwnsSelection = false;
80
81
82 static void comp_accept(struct wl_client *client,
83 struct wl_resource *resource,
84 uint32_t time,
85 const char *type);
86 static void comp_receive(struct wl_client *client,
87 struct wl_resource *resource,
88 const char *mime_type,
89 int32_t fd);
90 static void comp_destroy(struct wl_client *client,
91 struct wl_resource *resource);
92
93 static const struct wl_data_offer_interface compositor_offer_interface;
94};
95
96}
97
98QT_END_NAMESPACE
99
100#endif // WLDATADEVICEMANAGER_H
101

source code of qtwayland/src/compositor/wayland_wrapper/qwldatadevicemanager_p.h