1// Copyright (C) 2016 Klarälvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef QWAYLANDDATADEVICE_H
6#define QWAYLANDDATADEVICE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <qtwaylandclientglobal_p.h>
20#include <QObject>
21#include <QPointer>
22#include <QPoint>
23
24#include <QtWaylandClient/private/qwayland-wayland.h>
25
26QT_REQUIRE_CONFIG(wayland_datadevice);
27
28QT_BEGIN_NAMESPACE
29
30class QMimeData;
31class QPlatformDragQtResponse;
32class QWindow;
33
34namespace QtWayland {
35class qt_toplevel_drag_v1;
36}
37
38namespace QtWaylandClient {
39
40class QWaylandDisplay;
41class QWaylandDataDeviceManager;
42class QWaylandDataOffer;
43class QWaylandDataSource;
44class QWaylandInputDevice;
45class QWaylandWindow;
46
47class QWaylandDataDevice : public QObject, public QtWayland::wl_data_device
48{
49 Q_OBJECT
50public:
51 QWaylandDataDevice(QWaylandDataDeviceManager *manager, QWaylandInputDevice *inputDevice);
52 ~QWaylandDataDevice() override;
53
54 QWaylandDataOffer *selectionOffer() const;
55 void invalidateSelectionOffer();
56 QWaylandDataSource *selectionSource() const;
57 void setSelectionSource(QWaylandDataSource *source);
58
59#if QT_CONFIG(draganddrop)
60 QWaylandDataOffer *dragOffer() const;
61 bool startDrag(QMimeData *mimeData, Qt::DropActions supportedActions, QWaylandWindow *icon);
62 void cancelDrag();
63#endif
64
65protected:
66 void data_device_data_offer(struct ::wl_data_offer *id) override;
67
68#if QT_CONFIG(draganddrop)
69 void data_device_drop() override;
70 void data_device_enter(uint32_t serial, struct ::wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct ::wl_data_offer *id) override;
71 void data_device_leave() override;
72 void data_device_motion(uint32_t time, wl_fixed_t x, wl_fixed_t y) override;
73#endif
74 void data_device_selection(struct ::wl_data_offer *id) override;
75
76private Q_SLOTS:
77 void selectionSourceCancelled();
78
79#if QT_CONFIG(draganddrop)
80 void dragSourceCancelled();
81#endif
82
83private:
84#if QT_CONFIG(draganddrop)
85 QPoint calculateDragPosition(int x, int y, QWindow *wnd) const;
86#endif
87 void sendResponse(Qt::DropActions supportedActions, const QPlatformDragQtResponse &response);
88
89 static int dropActionsToWl(Qt::DropActions dropActions);
90
91
92 QWaylandDisplay *m_display = nullptr;
93 QWaylandInputDevice *m_inputDevice = nullptr;
94 uint32_t m_enterSerial = 0;
95 QPointer<QWindow> m_dragWindow;
96 QPoint m_dragPoint;
97 QScopedPointer<QWaylandDataOffer> m_dragOffer;
98 QScopedPointer<QWaylandDataOffer> m_selectionOffer;
99 QScopedPointer<QWaylandDataSource> m_selectionSource;
100 QScopedPointer<QWaylandDataSource> m_dragSource;
101 QtWayland::qt_toplevel_drag_v1 *m_toplevelDrag = nullptr;
102};
103
104}
105
106QT_END_NAMESPACE
107
108#endif // QWAYLANDDATADEVICE_H
109

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