File indexing completed on 2024-05-19 16:35:29
0001 /* 0002 SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #pragma once 0007 0008 #include "kwin_export.h" 0009 0010 #include <QObject> 0011 #include <QVector> 0012 #include <memory> 0013 0014 namespace KWaylandServer 0015 { 0016 class ClientConnection; 0017 class Display; 0018 class SeatInterface; 0019 class SurfaceInterface; 0020 class TabletCursorV2; 0021 class TabletCursorV2Private; 0022 class TabletManagerV2InterfacePrivate; 0023 class TabletSeatV2Interface; 0024 class TabletSeatV2InterfacePrivate; 0025 class TabletToolV2InterfacePrivate; 0026 class TabletV2Interface; 0027 class TabletV2InterfacePrivate; 0028 class TabletPadV2Interface; 0029 class TabletPadV2InterfacePrivate; 0030 class TabletPadRingV2Interface; 0031 class TabletPadRingV2InterfacePrivate; 0032 class TabletPadStripV2Interface; 0033 class TabletPadStripV2InterfacePrivate; 0034 class TabletPadGroupV2Interface; 0035 class TabletPadGroupV2InterfacePrivate; 0036 0037 /** 0038 * This is an implementation of wayland-protocols/unstable/tablet/tablet-unstable-v2.xml 0039 * 0040 * This class is just the means to get a @class TabletSeatInterface, which is 0041 * the class that will have all of the information we need. 0042 */ 0043 0044 class KWIN_EXPORT TabletManagerV2Interface : public QObject 0045 { 0046 Q_OBJECT 0047 public: 0048 explicit TabletManagerV2Interface(Display *d, QObject *parent); 0049 virtual ~TabletManagerV2Interface(); 0050 0051 TabletSeatV2Interface *seat(SeatInterface *seat) const; 0052 0053 private: 0054 std::unique_ptr<TabletManagerV2InterfacePrivate> d; 0055 }; 0056 0057 class KWIN_EXPORT TabletToolV2Interface : public QObject 0058 { 0059 Q_OBJECT 0060 public: 0061 virtual ~TabletToolV2Interface(); 0062 0063 enum Type { 0064 Pen = 0x140, ///< Pen 0065 Eraser = 0x141, ///< Eraser 0066 Brush = 0x142, ///< Brush 0067 Pencil = 0x143, ///< Pencil 0068 Airbrush = 0x144, ///< Airbrush 0069 Finger = 0x145, ///< Finger 0070 Mouse = 0x146, ///< Mouse 0071 Lens = 0x147, ///< Lens 0072 Totem 0073 }; 0074 Q_ENUM(Type) 0075 0076 enum Capability { 0077 Tilt = 1, ///< Tilt axeis 0078 Pressure = 2, ///< Pressure axis 0079 Distance = 3, ///< Distance axis 0080 Rotation = 4, ///< Z-rotation axis 0081 Slider = 5, ///< Slider axis 0082 Wheel = 6, ///< Wheel axis 0083 }; 0084 Q_ENUM(Capability) 0085 0086 bool hasCapability(Capability capability) const; 0087 0088 /** 0089 * Sets the surface the events will be sent to. 0090 * 0091 * Make sure the surface supports being sent events to. 0092 * 0093 * @see TabletV2Interface::isSurfaceSupported 0094 */ 0095 void setCurrentSurface(SurfaceInterface *surface); 0096 bool isClientSupported() const; 0097 0098 void sendProximityIn(TabletV2Interface *tablet); 0099 void sendProximityOut(); 0100 void sendUp(); 0101 void sendDown(); 0102 void sendPressure(quint32 pressure); 0103 void sendDistance(quint32 distance); 0104 void sendTilt(qreal degreesX, qreal degreesY); 0105 void sendRotation(qreal degrees); 0106 void sendSlider(qint32 position); 0107 void sendWheel(qint32 degrees, qint32 clicks); 0108 void sendButton(quint32 button, bool pressed); 0109 void sendFrame(quint32 time); 0110 void sendMotion(const QPointF &pos); 0111 0112 Q_SIGNALS: 0113 void cursorChanged(TabletCursorV2 *cursor) const; 0114 0115 private: 0116 friend class TabletSeatV2InterfacePrivate; 0117 friend class TabletSeatV2Interface; 0118 explicit TabletToolV2Interface(Display *display, 0119 Type type, 0120 quint32 hsh, 0121 quint32 hsl, 0122 quint32 hih, 0123 quint32 hil, 0124 const QVector<Capability> &capability); 0125 std::unique_ptr<TabletToolV2InterfacePrivate> d; 0126 }; 0127 0128 class KWIN_EXPORT TabletCursorV2 : public QObject 0129 { 0130 Q_OBJECT 0131 public: 0132 ~TabletCursorV2() override; 0133 QPoint hotspot() const; 0134 quint32 enteredSerial() const; 0135 SurfaceInterface *surface() const; 0136 0137 Q_SIGNALS: 0138 void changed(); 0139 0140 private: 0141 TabletCursorV2(); 0142 const std::unique_ptr<TabletCursorV2Private> d; 0143 friend class TabletToolV2InterfacePrivate; 0144 }; 0145 0146 class KWIN_EXPORT TabletPadV2Interface : public QObject 0147 { 0148 Q_OBJECT 0149 public: 0150 virtual ~TabletPadV2Interface(); 0151 0152 TabletPadRingV2Interface *ring(uint at) const; 0153 TabletPadStripV2Interface *strip(uint at) const; 0154 void sendButton(std::chrono::microseconds time, quint32 button, bool pressed); 0155 0156 void setCurrentSurface(SurfaceInterface *surface, TabletV2Interface *tablet); 0157 SurfaceInterface *currentSurface() const; 0158 0159 Q_SIGNALS: 0160 void feedback(KWaylandServer::ClientConnection *client, quint32 button, const QString &description, quint32 serial); 0161 0162 private: 0163 friend class TabletSeatV2Interface; 0164 friend class TabletSeatV2InterfacePrivate; 0165 explicit TabletPadV2Interface(const QString &path, 0166 quint32 buttons, 0167 quint32 rings, 0168 quint32 strips, 0169 quint32 modes, 0170 quint32 currentMode, 0171 Display *display, 0172 TabletSeatV2Interface *parent); 0173 std::unique_ptr<TabletPadV2InterfacePrivate> d; 0174 }; 0175 0176 class KWIN_EXPORT TabletPadRingV2Interface : public QObject 0177 { 0178 Q_OBJECT 0179 public: 0180 virtual ~TabletPadRingV2Interface(); 0181 0182 enum Source { 0183 SourceFinger = 1, // finger 0184 }; 0185 Q_ENUM(Source) 0186 0187 void sendSource(Source source); 0188 void sendAngle(qreal angle); 0189 void sendStop(); 0190 void sendFrame(quint32 time); 0191 0192 private: 0193 friend class TabletPadGroupV2Interface; 0194 friend class TabletPadV2InterfacePrivate; 0195 friend class TabletSeatV2InterfacePrivate; 0196 explicit TabletPadRingV2Interface(TabletPadV2Interface *parent); 0197 std::unique_ptr<TabletPadRingV2InterfacePrivate> d; 0198 }; 0199 0200 class KWIN_EXPORT TabletPadStripV2Interface : public QObject 0201 { 0202 Q_OBJECT 0203 public: 0204 virtual ~TabletPadStripV2Interface(); 0205 0206 enum Source { 0207 SourceFinger = 1, // finger 0208 }; 0209 0210 void sendSource(Source source); 0211 void sendPosition(quint32 position); 0212 void sendFrame(quint32 time); 0213 void sendStop(); 0214 0215 private: 0216 friend class TabletPadGroupV2Interface; 0217 friend class TabletPadV2InterfacePrivate; 0218 friend class TabletSeatV2InterfacePrivate; 0219 explicit TabletPadStripV2Interface(TabletPadV2Interface *parent); 0220 std::unique_ptr<TabletPadStripV2InterfacePrivate> d; 0221 }; 0222 0223 class KWIN_EXPORT TabletPadGroupV2Interface : public QObject 0224 { 0225 Q_OBJECT 0226 public: 0227 virtual ~TabletPadGroupV2Interface(); 0228 0229 void sendModeSwitch(quint32 time, quint32 serial, quint32 mode); 0230 0231 private: 0232 friend class TabletPadV2Interface; 0233 friend class TabletPadV2InterfacePrivate; 0234 friend class TabletSeatV2InterfacePrivate; 0235 explicit TabletPadGroupV2Interface(quint32 currentMode, TabletPadV2Interface *parent); 0236 std::unique_ptr<TabletPadGroupV2InterfacePrivate> d; 0237 }; 0238 0239 class KWIN_EXPORT TabletV2Interface : public QObject 0240 { 0241 Q_OBJECT 0242 public: 0243 virtual ~TabletV2Interface(); 0244 0245 /** 0246 * @returns true if the surface has been bound to the tablet. 0247 */ 0248 bool isSurfaceSupported(SurfaceInterface *surface) const; 0249 0250 TabletPadV2Interface *pad() const; 0251 0252 private: 0253 friend class TabletSeatV2Interface; 0254 friend class TabletSeatV2InterfacePrivate; 0255 friend class TabletPadV2Interface; 0256 friend class TabletToolV2Interface; 0257 explicit TabletV2Interface(quint32 vendorId, quint32 productId, const QString &name, const QStringList &paths, QObject *parent); 0258 std::unique_ptr<TabletV2InterfacePrivate> d; 0259 }; 0260 0261 class KWIN_EXPORT TabletSeatV2Interface : public QObject 0262 { 0263 Q_OBJECT 0264 public: 0265 virtual ~TabletSeatV2Interface(); 0266 0267 TabletV2Interface *addTablet(quint32 vendorId, quint32 productId, const QString &sysname, const QString &name, const QStringList &paths); 0268 TabletPadV2Interface *addTabletPad(const QString &sysname, 0269 const QString &name, 0270 const QStringList &paths, 0271 quint32 buttons, 0272 quint32 rings, 0273 quint32 strips, 0274 quint32 modes, 0275 quint32 currentMode, 0276 TabletV2Interface *tablet); 0277 TabletToolV2Interface * 0278 addTool(TabletToolV2Interface::Type type, quint64 hardwareSerial, quint64 hardwareId, const QVector<TabletToolV2Interface::Capability> &capabilities, const QString &deviceSysName); 0279 0280 TabletToolV2Interface *toolByHardwareId(quint64 hardwareId) const; 0281 TabletToolV2Interface *toolByHardwareSerial(quint64 hardwareSerial, TabletToolV2Interface::Type type) const; 0282 TabletPadV2Interface *padByName(const QString &sysname) const; 0283 0284 void removeDevice(const QString &sysname); 0285 0286 bool isClientSupported(ClientConnection *client) const; 0287 0288 private: 0289 friend class TabletManagerV2InterfacePrivate; 0290 explicit TabletSeatV2Interface(Display *display, QObject *parent); 0291 std::unique_ptr<TabletSeatV2InterfacePrivate> d; 0292 }; 0293 0294 } 0295 0296 Q_DECLARE_METATYPE(KWaylandServer::TabletSeatV2Interface *)