1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2019 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the plugins of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QWAYLANDTABLETV2_P_H 41 #define QWAYLANDTABLETV2_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <QtWaylandClient/private/qwayland-tablet-unstable-v2.h> 55 56 #include <QtWaylandClient/private/qtwaylandclientglobal_p.h> 57 58 #include <QtGui/QTabletEvent> 59 #include <QtCore/QObject> 60 #include <QtCore/QPointer> 61 #include <QtCore/QPointF> 62 63 QT_BEGIN_NAMESPACE 64 65 namespace QtWaylandClient { 66 67 class QWaylandDisplay; 68 class QWaylandInputDevice; 69 class QWaylandSurface; 70 71 class QWaylandTabletSeatV2; 72 class QWaylandTabletV2; 73 class QWaylandTabletToolV2; 74 class QWaylandTabletPadV2; 75 76 class Q_WAYLAND_CLIENT_EXPORT QWaylandTabletManagerV2 : public QtWayland::zwp_tablet_manager_v2 77 { 78 public: 79 explicit QWaylandTabletManagerV2(QWaylandDisplay *display, uint id, uint version); 80 QWaylandTabletSeatV2 *createTabletSeat(QWaylandInputDevice *seat); 81 }; 82 83 class Q_WAYLAND_CLIENT_EXPORT QWaylandTabletSeatV2 : public QObject, public QtWayland::zwp_tablet_seat_v2 84 { 85 Q_OBJECT 86 public: 87 explicit QWaylandTabletSeatV2(QWaylandTabletManagerV2 *manager, QWaylandInputDevice *seat); 88 ~QWaylandTabletSeatV2() override; 89 90 protected: 91 void zwp_tablet_seat_v2_tablet_added(struct ::zwp_tablet_v2 *id) override; 92 void zwp_tablet_seat_v2_tool_added(struct ::zwp_tablet_tool_v2 *id) override; 93 void zwp_tablet_seat_v2_pad_added(struct ::zwp_tablet_pad_v2 *id) override; 94 95 private: 96 QVector<QWaylandTabletV2 *> m_tablets; 97 QVector<QWaylandTabletToolV2 *> m_tools; 98 QVector<QWaylandTabletPadV2 *> m_pads; 99 }; 100 101 class Q_WAYLAND_CLIENT_EXPORT QWaylandTabletV2 : public QObject, public QtWayland::zwp_tablet_v2 102 { 103 Q_OBJECT 104 public: 105 explicit QWaylandTabletV2(::zwp_tablet_v2 *tablet); 106 107 protected: 108 // void zwp_tablet_v2_name(const QString &name) override; 109 // void zwp_tablet_v2_id(uint32_t vid, uint32_t pid) override; 110 // void zwp_tablet_v2_path(const QString &path) override; 111 // void zwp_tablet_v2_done() override; 112 void zwp_tablet_v2_removed() override; 113 }; 114 115 class Q_WAYLAND_CLIENT_EXPORT QWaylandTabletToolV2 : public QObject, public QtWayland::zwp_tablet_tool_v2 116 { 117 Q_OBJECT 118 public: 119 explicit QWaylandTabletToolV2(::zwp_tablet_tool_v2 *tool); 120 121 protected: 122 void zwp_tablet_tool_v2_type(uint32_t tool_type) override; 123 void zwp_tablet_tool_v2_hardware_serial(uint32_t hardware_serial_hi, uint32_t hardware_serial_lo) override; 124 // void zwp_tablet_tool_v2_hardware_id_wacom(uint32_t hardware_id_hi, uint32_t hardware_id_lo) override; 125 void zwp_tablet_tool_v2_capability(uint32_t capability) override; 126 void zwp_tablet_tool_v2_done() override; 127 void zwp_tablet_tool_v2_removed() override; 128 void zwp_tablet_tool_v2_proximity_in(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override; 129 void zwp_tablet_tool_v2_proximity_out() override; 130 void zwp_tablet_tool_v2_down(uint32_t serial) override; 131 void zwp_tablet_tool_v2_up() override; 132 void zwp_tablet_tool_v2_motion(wl_fixed_t x, wl_fixed_t y) override; 133 void zwp_tablet_tool_v2_pressure(uint32_t pressure) override; 134 void zwp_tablet_tool_v2_distance(uint32_t distance) override; 135 void zwp_tablet_tool_v2_tilt(wl_fixed_t tilt_x, wl_fixed_t tilt_y) override; 136 void zwp_tablet_tool_v2_rotation(wl_fixed_t degrees) override; 137 void zwp_tablet_tool_v2_slider(int32_t position) override; 138 // void zwp_tablet_tool_v2_wheel(wl_fixed_t degrees, int32_t clicks) override; 139 void zwp_tablet_tool_v2_button(uint32_t serial, uint32_t button, uint32_t state) override; 140 void zwp_tablet_tool_v2_frame(uint32_t time) override; 141 142 private: 143 144 // Static state (sent before done event) 145 QTabletEvent::PointerType m_pointerType = QTabletEvent::PointerType::UnknownPointer; 146 QTabletEvent::TabletDevice m_tabletDevice = QTabletEvent::TabletDevice::NoDevice; 147 type m_toolType = type_pen; 148 bool m_hasRotation = false; 149 quint64 m_uid = 0; 150 151 // Accumulated state (applied on frame event) 152 struct State { 153 bool down = false; 154 QPointer<QWaylandSurface> proximitySurface; 155 bool enteredSurface = false; // Not enough with just proximitySurface, if the surface is deleted, we still want to send a leave event 156 QPointF surfacePosition; 157 uint distance = 0; 158 qreal pressure = 0; 159 qreal rotation = 0; 160 qreal xTilt = 0; 161 qreal yTilt = 0; 162 qreal slider = 0; 163 Qt::MouseButtons buttons = Qt::MouseButton::NoButton; // Actual buttons, down state -> left mouse is mapped inside the frame handler 164 //auto operator<=>(const Point&) const = default; // TODO: use this when upgrading to C++20 165 bool operator==(const State &o) const; 166 } m_pending, m_applied; 167 }; 168 169 // We don't actually use this, but need to handle the "removed" event to comply with the protocol 170 class Q_WAYLAND_CLIENT_EXPORT QWaylandTabletPadV2 : public QObject, public QtWayland::zwp_tablet_pad_v2 171 { 172 Q_OBJECT 173 public: 174 explicit QWaylandTabletPadV2(::zwp_tablet_pad_v2 *pad); 175 176 protected: 177 // void zwp_tablet_pad_v2_group(struct ::zwp_tablet_pad_group_v2 *pad_group) override; 178 // void zwp_tablet_pad_v2_path(const QString &path) override; 179 // void zwp_tablet_pad_v2_buttons(uint32_t buttons) override; 180 // void zwp_tablet_pad_v2_done() override; 181 // void zwp_tablet_pad_v2_button(uint32_t time, uint32_t button, uint32_t state) override; 182 // void zwp_tablet_pad_v2_enter(uint32_t serial, struct ::zwp_tablet_v2 *tablet, struct ::wl_surface *surface) override; 183 // void zwp_tablet_pad_v2_leave(uint32_t serial, struct ::wl_surface *surface) override; 184 void zwp_tablet_pad_v2_removed() override; 185 }; 186 187 } // namespace QtWaylandClient 188 189 QT_END_NAMESPACE 190 191 #endif // QWAYLANDTABLETV2_P_H 192