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 QWAYLANDTABLETV2_P_H |
5 | #define QWAYLANDTABLETV2_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-tablet-unstable-v2.h> |
19 | |
20 | #include <QtWaylandClient/private/qtwaylandclientglobal_p.h> |
21 | |
22 | #include <QtCore/QObject> |
23 | #include <QtCore/QPointer> |
24 | #include <QtCore/QPointF> |
25 | #include <QtGui/QPointingDevice> |
26 | #include <QtGui/QInputDevice> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | namespace QtWaylandClient { |
31 | |
32 | class QWaylandDisplay; |
33 | class QWaylandInputDevice; |
34 | class QWaylandSurface; |
35 | |
36 | class QWaylandTabletSeatV2; |
37 | class QWaylandTabletV2; |
38 | class QWaylandTabletToolV2; |
39 | class QWaylandTabletPadV2; |
40 | |
41 | class Q_WAYLANDCLIENT_EXPORT QWaylandTabletManagerV2 : public QtWayland::zwp_tablet_manager_v2 |
42 | { |
43 | public: |
44 | explicit QWaylandTabletManagerV2(QWaylandDisplay *display, uint id, uint version); |
45 | QWaylandTabletSeatV2 *createTabletSeat(QWaylandInputDevice *seat); |
46 | }; |
47 | |
48 | class Q_WAYLANDCLIENT_EXPORT QWaylandTabletSeatV2 : public QObject, public QtWayland::zwp_tablet_seat_v2 |
49 | { |
50 | Q_OBJECT |
51 | public: |
52 | explicit QWaylandTabletSeatV2(QWaylandTabletManagerV2 *manager, QWaylandInputDevice *seat); |
53 | ~QWaylandTabletSeatV2() override; |
54 | |
55 | QWaylandInputDevice *seat() const { return m_seat; } |
56 | |
57 | protected: |
58 | void zwp_tablet_seat_v2_tablet_added(struct ::zwp_tablet_v2 *id) override; |
59 | void zwp_tablet_seat_v2_tool_added(struct ::zwp_tablet_tool_v2 *id) override; |
60 | void zwp_tablet_seat_v2_pad_added(struct ::zwp_tablet_pad_v2 *id) override; |
61 | |
62 | private: |
63 | QWaylandInputDevice *m_seat; |
64 | QList<QWaylandTabletV2 *> m_tablets; |
65 | QList<QWaylandTabletToolV2 *> m_tools; |
66 | QList<QWaylandTabletPadV2 *> m_pads; |
67 | }; |
68 | |
69 | class Q_WAYLANDCLIENT_EXPORT QWaylandTabletV2 : public QObject, public QtWayland::zwp_tablet_v2 |
70 | { |
71 | Q_OBJECT |
72 | public: |
73 | explicit QWaylandTabletV2(::zwp_tablet_v2 *tablet); |
74 | |
75 | protected: |
76 | // void zwp_tablet_v2_name(const QString &name) override; |
77 | // void zwp_tablet_v2_id(uint32_t vid, uint32_t pid) override; |
78 | // void zwp_tablet_v2_path(const QString &path) override; |
79 | // void zwp_tablet_v2_done() override; |
80 | void zwp_tablet_v2_removed() override; |
81 | }; |
82 | |
83 | class Q_WAYLANDCLIENT_EXPORT QWaylandTabletToolV2 : public QObject, public QtWayland::zwp_tablet_tool_v2 |
84 | { |
85 | Q_OBJECT |
86 | public: |
87 | QWaylandTabletToolV2(QWaylandTabletSeatV2 *tabletSeat, ::zwp_tablet_tool_v2 *tool); |
88 | |
89 | protected: |
90 | void zwp_tablet_tool_v2_type(uint32_t tool_type) override; |
91 | void zwp_tablet_tool_v2_hardware_serial(uint32_t hardware_serial_hi, uint32_t hardware_serial_lo) override; |
92 | // void zwp_tablet_tool_v2_hardware_id_wacom(uint32_t hardware_id_hi, uint32_t hardware_id_lo) override; |
93 | void zwp_tablet_tool_v2_capability(uint32_t capability) override; |
94 | void zwp_tablet_tool_v2_done() override; |
95 | void zwp_tablet_tool_v2_removed() override; |
96 | void zwp_tablet_tool_v2_proximity_in(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override; |
97 | void zwp_tablet_tool_v2_proximity_out() override; |
98 | void zwp_tablet_tool_v2_down(uint32_t serial) override; |
99 | void zwp_tablet_tool_v2_up() override; |
100 | void zwp_tablet_tool_v2_motion(wl_fixed_t x, wl_fixed_t y) override; |
101 | void zwp_tablet_tool_v2_pressure(uint32_t pressure) override; |
102 | void zwp_tablet_tool_v2_distance(uint32_t distance) override; |
103 | void zwp_tablet_tool_v2_tilt(wl_fixed_t tilt_x, wl_fixed_t tilt_y) override; |
104 | void zwp_tablet_tool_v2_rotation(wl_fixed_t degrees) override; |
105 | void zwp_tablet_tool_v2_slider(int32_t position) override; |
106 | // void zwp_tablet_tool_v2_wheel(wl_fixed_t degrees, int32_t clicks) override; |
107 | void zwp_tablet_tool_v2_button(uint32_t serial, uint32_t button, uint32_t state) override; |
108 | void zwp_tablet_tool_v2_frame(uint32_t time) override; |
109 | |
110 | private: |
111 | QWaylandTabletSeatV2 *m_tabletSeat; |
112 | |
113 | // Static state (sent before done event) |
114 | QPointingDevice::PointerType m_pointerType = QPointingDevice::PointerType::Unknown; |
115 | QInputDevice::DeviceType m_tabletDevice = QInputDevice::DeviceType::Unknown; |
116 | type m_toolType = type_pen; |
117 | bool m_hasRotation = false; |
118 | quint64 m_uid = 0; |
119 | |
120 | // Accumulated state (applied on frame event) |
121 | struct State { |
122 | bool down = false; |
123 | QPointer<QWaylandSurface> proximitySurface; |
124 | bool enteredSurface = false; // Not enough with just proximitySurface, if the surface is deleted, we still want to send a leave event |
125 | QPointF surfacePosition; |
126 | uint distance = 0; |
127 | qreal pressure = 0; |
128 | qreal rotation = 0; |
129 | qreal xTilt = 0; |
130 | qreal yTilt = 0; |
131 | qreal slider = 0; |
132 | Qt::MouseButtons buttons = Qt::MouseButton::NoButton; // Actual buttons, down state -> left mouse is mapped inside the frame handler |
133 | //auto operator<=>(const Point&) const = default; // TODO: use this when upgrading to C++20 |
134 | bool operator==(const State &o) const; |
135 | } m_pending, m_applied; |
136 | }; |
137 | |
138 | // We don't actually use this, but need to handle the "removed" event to comply with the protocol |
139 | class Q_WAYLANDCLIENT_EXPORT QWaylandTabletPadV2 : public QObject, public QtWayland::zwp_tablet_pad_v2 |
140 | { |
141 | Q_OBJECT |
142 | public: |
143 | explicit QWaylandTabletPadV2(::zwp_tablet_pad_v2 *pad); |
144 | |
145 | protected: |
146 | // void zwp_tablet_pad_v2_group(struct ::zwp_tablet_pad_group_v2 *pad_group) override; |
147 | // void zwp_tablet_pad_v2_path(const QString &path) override; |
148 | // void zwp_tablet_pad_v2_buttons(uint32_t buttons) override; |
149 | // void zwp_tablet_pad_v2_done() override; |
150 | // void zwp_tablet_pad_v2_button(uint32_t time, uint32_t button, uint32_t state) override; |
151 | // void zwp_tablet_pad_v2_enter(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override; |
152 | // void zwp_tablet_pad_v2_leave(uint32_t serial, struct ::wl_surface *surface) override; |
153 | void zwp_tablet_pad_v2_removed() override; |
154 | }; |
155 | |
156 | } // namespace QtWaylandClient |
157 | |
158 | QT_END_NAMESPACE |
159 | |
160 | #endif // QWAYLANDTABLETV2_P_H |
161 | |