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