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 <QtCore/QTimer>
26#include <QtGui/QPointingDevice>
27#include <QtGui/QInputDevice>
28
29QT_BEGIN_NAMESPACE
30
31namespace QtWaylandClient {
32
33class QWaylandDisplay;
34class QWaylandInputDevice;
35class QWaylandSurface;
36
37class QWaylandTabletSeatV2;
38class QWaylandTabletV2;
39class QWaylandTabletToolV2;
40class QWaylandTabletPadV2;
41
42#if QT_CONFIG(cursor)
43class QWaylandCursorTheme;
44class QWaylandCursorShape;
45template <typename T>
46class CursorSurface;
47#endif
48
49class Q_WAYLANDCLIENT_EXPORT QWaylandTabletManagerV2 : public QtWayland::zwp_tablet_manager_v2
50{
51public:
52 explicit QWaylandTabletManagerV2(QWaylandDisplay *display, uint id, uint version);
53 ~QWaylandTabletManagerV2() override;
54};
55
56class Q_WAYLANDCLIENT_EXPORT QWaylandTabletSeatV2 : public QObject, public QtWayland::zwp_tablet_seat_v2
57{
58 Q_OBJECT
59public:
60 explicit QWaylandTabletSeatV2(QWaylandTabletManagerV2 *manager, QWaylandInputDevice *seat);
61 ~QWaylandTabletSeatV2() override;
62
63 QWaylandInputDevice *seat() const { return m_seat; }
64
65 void updateCursor();
66 void toolRemoved(QWaylandTabletToolV2 *tool);
67
68protected:
69 void zwp_tablet_seat_v2_tablet_added(struct ::zwp_tablet_v2 *id) override;
70 void zwp_tablet_seat_v2_tool_added(struct ::zwp_tablet_tool_v2 *id) override;
71 void zwp_tablet_seat_v2_pad_added(struct ::zwp_tablet_pad_v2 *id) override;
72
73private:
74 QWaylandInputDevice *m_seat;
75 QList<QWaylandTabletV2 *> m_tablets;
76 QList<QWaylandTabletToolV2 *> m_tools;
77 QList<QWaylandTabletToolV2 *> m_deadTools;
78 QList<QWaylandTabletPadV2 *> m_pads;
79};
80
81class Q_WAYLANDCLIENT_EXPORT QWaylandTabletV2 : public QPointingDevice, public QtWayland::zwp_tablet_v2
82{
83 Q_OBJECT
84public:
85 explicit QWaylandTabletV2(::zwp_tablet_v2 *tablet, const QString &seatName);
86
87protected:
88 // callbacks which act as setters
89 void zwp_tablet_v2_name(const QString &name) override;
90 void zwp_tablet_v2_id(uint32_t vid, uint32_t pid) override;
91 void zwp_tablet_v2_path(const QString &path) override;
92 void zwp_tablet_v2_done() override;
93 void zwp_tablet_v2_removed() override;
94};
95
96class Q_WAYLANDCLIENT_EXPORT QWaylandTabletToolV2 : public QPointingDevice, public QtWayland::zwp_tablet_tool_v2
97{
98 Q_OBJECT
99public:
100 QWaylandTabletToolV2(QWaylandTabletSeatV2 *tabletSeat, ::zwp_tablet_tool_v2 *tool);
101 ~QWaylandTabletToolV2() override;
102
103 void updateCursor();
104
105protected:
106 void zwp_tablet_tool_v2_type(uint32_t tool_type) override;
107 void zwp_tablet_tool_v2_hardware_serial(uint32_t hardware_serial_hi, uint32_t hardware_serial_lo) override;
108 void zwp_tablet_tool_v2_hardware_id_wacom(uint32_t hardware_id_hi, uint32_t hardware_id_lo) override;
109 void zwp_tablet_tool_v2_capability(uint32_t capability) override;
110 void zwp_tablet_tool_v2_done() override;
111 void zwp_tablet_tool_v2_removed() override;
112 void zwp_tablet_tool_v2_proximity_in(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override;
113 void zwp_tablet_tool_v2_proximity_out() override;
114 void zwp_tablet_tool_v2_down(uint32_t serial) override;
115 void zwp_tablet_tool_v2_up() override;
116 void zwp_tablet_tool_v2_motion(wl_fixed_t x, wl_fixed_t y) override;
117 void zwp_tablet_tool_v2_pressure(uint32_t pressure) override;
118 void zwp_tablet_tool_v2_distance(uint32_t distance) override;
119 void zwp_tablet_tool_v2_tilt(wl_fixed_t tilt_x, wl_fixed_t tilt_y) override;
120 void zwp_tablet_tool_v2_rotation(wl_fixed_t degrees) override;
121 void zwp_tablet_tool_v2_slider(int32_t position) override;
122// void zwp_tablet_tool_v2_wheel(wl_fixed_t degrees, int32_t clicks) override;
123 void zwp_tablet_tool_v2_button(uint32_t serial, uint32_t button, uint32_t state) override;
124 void zwp_tablet_tool_v2_frame(uint32_t time) override;
125
126private:
127#if QT_CONFIG(cursor)
128 int idealCursorScale() const;
129 void updateCursorTheme();
130 void cursorTimerCallback();
131 void cursorFrameCallback();
132 CursorSurface<QWaylandTabletToolV2> *getOrCreateCursorSurface();
133#endif
134
135 QWaylandTabletSeatV2 *m_tabletSeat;
136
137 // Static state (sent before done event)
138 QPointingDevice::PointerType m_pointerType = QPointingDevice::PointerType::Unknown;
139 QInputDevice::DeviceType m_tabletDevice = QInputDevice::DeviceType::Unknown;
140 zwp_tablet_tool_v2::type m_toolType = type_pen;
141 bool m_hasRotation = false;
142 quint64 m_uid = 0;
143
144 uint32_t mEnterSerial = 0;
145#if QT_CONFIG(cursor)
146 struct
147 {
148 QScopedPointer<QWaylandCursorShape> shape;
149 QWaylandCursorTheme *theme = nullptr;
150 int themeBufferScale = 0;
151 QScopedPointer<CursorSurface<QWaylandTabletToolV2>> surface;
152 QTimer frameTimer;
153 bool gotFrameCallback = false;
154 bool gotTimerCallback = false;
155 } mCursor;
156#endif
157
158 // Accumulated state (applied on frame event)
159 struct State {
160 bool down = false;
161 QPointer<QWaylandSurface> proximitySurface;
162 bool enteredSurface = false; // Not enough with just proximitySurface, if the surface is deleted, we still want to send a leave event
163 QPointF surfacePosition;
164 uint distance = 0;
165 qreal pressure = 0;
166 qreal rotation = 0;
167 qreal xTilt = 0;
168 qreal yTilt = 0;
169 qreal slider = 0;
170 Qt::MouseButtons buttons = Qt::MouseButton::NoButton; // Actual buttons, down state -> left mouse is mapped inside the frame handler
171 //auto operator<=>(const Point&) const = default; // TODO: use this when upgrading to C++20
172 bool operator==(const State &o) const;
173 } m_pending, m_applied;
174
175 template <typename T>
176 friend class CursorSurface;
177};
178
179class Q_WAYLANDCLIENT_EXPORT QWaylandTabletPadV2 : public QPointingDevice, public QtWayland::zwp_tablet_pad_v2
180{
181 Q_OBJECT
182public:
183 explicit QWaylandTabletPadV2(::zwp_tablet_pad_v2 *pad);
184
185protected:
186// void zwp_tablet_pad_v2_group(struct ::zwp_tablet_pad_group_v2 *pad_group) override;
187 void zwp_tablet_pad_v2_path(const QString &path) override;
188 void zwp_tablet_pad_v2_buttons(uint32_t buttons) override;
189 void zwp_tablet_pad_v2_done() override;
190// void zwp_tablet_pad_v2_button(uint32_t time, uint32_t button, uint32_t state) override;
191// void zwp_tablet_pad_v2_enter(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override;
192// void zwp_tablet_pad_v2_leave(uint32_t serial, struct ::wl_surface *surface) override;
193 void zwp_tablet_pad_v2_removed() override;
194};
195
196} // namespace QtWaylandClient
197
198QT_END_NAMESPACE
199
200#endif // QWAYLANDTABLETV2_P_H
201

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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