1 /********************************************************************
2 Copyright 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
3 
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11 
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #ifndef WAYLAND_SERVER_TABLET_INTERFACE_H
21 #define WAYLAND_SERVER_TABLET_INTERFACE_H
22 
23 #include <KWayland/Server/kwaylandserver_export.h>
24 #include <QVector>
25 
26 #include "resource.h"
27 
28 namespace KWayland
29 {
30 namespace Server
31 {
32 class TabletSeatInterface;
33 class Display;
34 class SeatInterface;
35 class SurfaceInterface;
36 class TabletInterface;
37 class TabletCursor;
38 
39 /**
40  * This is an implementation of wayland-protocols/unstable/tablet/tablet-unstable-v2.xml
41  *
42  * This class is just the means to get a @class TabletSeatInterface, which is
43  * the class that will have all of the information we need.
44  *
45  * @since 5.69
46  */
47 
48 class KWAYLANDSERVER_EXPORT TabletManagerInterface : public QObject
49 {
50     Q_OBJECT
51 public:
52     ~TabletManagerInterface() override;
53 
54     TabletSeatInterface *seat(SeatInterface *seat) const;
55 
56 private:
57     friend class Display;
58     explicit TabletManagerInterface(Display *d, QObject *parent);
59     class Private;
60     QScopedPointer<Private> d;
61 };
62 
63 class KWAYLANDSERVER_EXPORT TabletToolInterface : public QObject
64 {
65     Q_OBJECT
66 public:
67     ~TabletToolInterface() override;
68 
69     enum Type {
70         Pen = 0x140, ///< Pen
71         Eraser = 0x141, ///< Eraser
72         Brush = 0x142, ///< Brush
73         Pencil = 0x143, ///< Pencil
74         Airbrush = 0x144, ///< Airbrush
75         Finger = 0x145, ///< Finger
76         Mouse = 0x146, ///< Mouse
77         Lens = 0x147, ///< Lens
78         Totem,
79     };
80     Q_ENUM(Type)
81 
82     enum Capability {
83         Tilt = 1, ///< Tilt axeis
84         Pressure = 2, ///< Pressure axis
85         Distance = 3, ///< Distance axis
86         Rotation = 4, ///< Z-rotation axis
87         Slider = 5, ///< Slider axis
88         Wheel = 6, ///< Wheel axis
89     };
90     Q_ENUM(Capability)
91 
92     /**
93      * Sets the surface the events will be sent to.
94      *
95      * Make sure the surface supports being sent events to.
96      *
97      * @see TabletInterface::isSurfaceSupported
98      */
99     void setCurrentSurface(SurfaceInterface *surface);
100     bool isClientSupported() const;
101 
102     void sendRemoved();
103     void sendProximityIn(TabletInterface *tablet);
104     void sendProximityOut();
105     void sendUp();
106     void sendDown();
107     void sendPressure(quint32 pressure);
108     void sendDistance(quint32 distance);
109     void sendTilt(qreal degreesX, qreal degreesY);
110     void sendRotation(qreal degrees);
111     void sendSlider(qint32 position);
112     void sendWheel(qint32 degrees, qint32 clicks);
113     void sendButton(quint32 button, bool pressed);
114     void sendFrame(quint32 time);
115     void sendMotion(const QPointF &pos);
116 
117 Q_SIGNALS:
118     void cursorChanged(TabletCursor *cursor) const;
119 
120 private:
121     friend class TabletSeatInterface;
122     explicit TabletToolInterface(Display *display,
123                                  Type type,
124                                  quint32 hsh,
125                                  quint32 hsl,
126                                  quint32 hih,
127                                  quint32 hil,
128                                  const QVector<Capability> &capability,
129                                  QObject *parent);
130     class Private;
131     QScopedPointer<Private> d;
132 };
133 
134 class KWAYLANDSERVER_EXPORT TabletCursor : public QObject
135 {
136     Q_OBJECT
137 public:
138     ~TabletCursor() override;
139     QPoint hotspot() const;
140     quint32 enteredSerial() const;
141     SurfaceInterface *surface() const;
142 
143 Q_SIGNALS:
144     void changed();
145 
146 private:
147     friend class TabletToolInterface;
148     TabletCursor();
149     class Private;
150     const QScopedPointer<Private> d;
151 };
152 
153 class KWAYLANDSERVER_EXPORT TabletInterface : public QObject
154 {
155     Q_OBJECT
156 public:
157     ~TabletInterface() override;
158 
159     /**
160      * @returns true if the surface has been bound to the tablet.
161      */
162     bool isSurfaceSupported(SurfaceInterface *surface) const;
163 
164     void sendRemoved();
165 
166 private:
167     friend class TabletSeatInterface;
168     friend class TabletToolInterface;
169     explicit TabletInterface(quint32 vendorId, quint32 productId, const QString &name, const QStringList &paths, QObject *parent);
170     class Private;
171     QScopedPointer<Private> d;
172 };
173 
174 class KWAYLANDSERVER_EXPORT TabletSeatInterface : public QObject
175 {
176     Q_OBJECT
177 public:
178     ~TabletSeatInterface() override;
179 
180     TabletInterface *addTablet(quint32 vendorId, quint32 productId, const QString &sysname, const QString &name, const QStringList &paths);
181     TabletToolInterface *
182     addTool(TabletToolInterface::Type type, quint64 hardwareSerial, quint64 hardwareId, const QVector<TabletToolInterface::Capability> &capabilities);
183 
184     TabletToolInterface *toolByHardwareId(quint64 hardwareId) const;
185     TabletToolInterface *toolByHardwareSerial(quint64 hardwareSerial) const;
186     TabletInterface *tabletByName(const QString &sysname) const;
187 
188     void removeTablet(const QString &sysname);
189 
190 private:
191     friend class TabletManagerInterface;
192     explicit TabletSeatInterface(Display *display, QObject *parent);
193     class Private;
194     QScopedPointer<Private> d;
195 };
196 
197 }
198 }
199 
200 Q_DECLARE_METATYPE(KWayland::Server::TabletSeatInterface *)
201 
202 #endif
203