File indexing completed on 2024-05-12 05:32:30

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