File indexing completed on 2024-12-22 05:09:25

0001 /*
0002     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #ifndef WAYLAND_TOUCH_H
0007 #define WAYLAND_TOUCH_H
0008 
0009 #include <QObject>
0010 #include <QPoint>
0011 
0012 #include "KWayland/Client/kwaylandclient_export.h"
0013 
0014 struct wl_touch;
0015 
0016 namespace KWayland
0017 {
0018 namespace Client
0019 {
0020 class Surface;
0021 class Touch;
0022 
0023 /**
0024  * TODO
0025  */
0026 class KWAYLANDCLIENT_EXPORT TouchPoint
0027 {
0028 public:
0029     virtual ~TouchPoint();
0030 
0031     /**
0032      * Unique in the scope of all TouchPoints currently being down.
0033      * As soon as the TouchPoint is now longer down another TouchPoint
0034      * might get assigned the id.
0035      **/
0036     qint32 id() const;
0037     /**
0038      * The serial when the down event happened.
0039      **/
0040     quint32 downSerial() const;
0041     /**
0042      * The serial when the up event happened.
0043      **/
0044     quint32 upSerial() const;
0045     /**
0046      * Most recent timestamp
0047      **/
0048     quint32 time() const;
0049     /**
0050      * All timestamps, references the positions.
0051      * That is each position has a timestamp.
0052      **/
0053     QList<quint32> timestamps() const;
0054     /**
0055      * Most recent position
0056      **/
0057     QPointF position() const;
0058     /**
0059      * All positions this TouchPoint had, updated with each move.
0060      **/
0061     QList<QPointF> positions() const;
0062     /**
0063      * The Surface this TouchPoint happened on.
0064      **/
0065     QPointer<Surface> surface() const;
0066     /**
0067      * @c true if currently down, @c false otherwise.
0068      **/
0069     bool isDown() const;
0070 
0071 private:
0072     friend class Touch;
0073     explicit TouchPoint();
0074     class Private;
0075     QScopedPointer<Private> d;
0076 };
0077 
0078 /**
0079  * @short Wrapper for the wl_touch interface.
0080  *
0081  * This class is a convenient wrapper for the wl_touch interface.
0082  *
0083  * To create an instance use Seat::createTouch.
0084  *
0085  * @see Seat
0086  **/
0087 class KWAYLANDCLIENT_EXPORT Touch : public QObject
0088 {
0089     Q_OBJECT
0090 public:
0091     explicit Touch(QObject *parent = nullptr);
0092     ~Touch() override;
0093 
0094     /**
0095      * @returns @c true if managing a wl_pointer.
0096      **/
0097     bool isValid() const;
0098     /**
0099      * Setup this Touch to manage the @p touch.
0100      * When using Seat::createTouch there is no need to call this
0101      * method.
0102      **/
0103     void setup(wl_touch *touch);
0104     /**
0105      * Releases the wl_touch interface.
0106      * After the interface has been released the Touch instance is no
0107      * longer valid and can be setup with another wl_touch interface.
0108      *
0109      * This method is automatically invoked when the Seat which created this
0110      * Touch gets released.
0111      **/
0112     void release();
0113     /**
0114      * Destroys the data held by this Touch.
0115      * This method is supposed to be used when the connection to the Wayland
0116      * server goes away. If the connection is not valid anymore, it's not
0117      * possible to call release anymore as that calls into the Wayland
0118      * connection and the call would fail. This method cleans up the data, so
0119      * that the instance can be deleted or set up to a new wl_touch interface
0120      * once there is a new connection available.
0121      *
0122      * This method is automatically invoked when the Seat which created this
0123      * Touch gets destroyed.
0124      *
0125      * @see release
0126      **/
0127     void destroy();
0128 
0129     /**
0130      * The TouchPoints of the latest touch event sequence.
0131      * Only valid till the next touch event sequence is started
0132      **/
0133     QList<TouchPoint *> sequence() const;
0134 
0135     operator wl_touch *();
0136     operator wl_touch *() const;
0137 
0138 Q_SIGNALS:
0139     /**
0140      * A new touch sequence is started. The previous sequence is discarded.
0141      * @param startPoint The first point which started the sequence
0142      **/
0143     void sequenceStarted(KWayland::Client::TouchPoint *startPoint);
0144     /**
0145      * Sent if the compositor decides the touch stream is a global
0146      * gesture.
0147      **/
0148     void sequenceCanceled();
0149     /**
0150      * Emitted once all touch points are no longer down.
0151      **/
0152     void sequenceEnded();
0153     /**
0154      * Indicates the end of a contact point list.
0155      **/
0156     void frameEnded();
0157     /**
0158      * TouchPoint @p point got added to the sequence.
0159      **/
0160     void pointAdded(KWayland::Client::TouchPoint *point);
0161     /**
0162      * TouchPoint @p point is no longer down.
0163      * A new TouchPoint might reuse the Id of the @p point.
0164      **/
0165     void pointRemoved(KWayland::Client::TouchPoint *point);
0166     /**
0167      * TouchPoint @p point moved.
0168      **/
0169     void pointMoved(KWayland::Client::TouchPoint *point);
0170 
0171 private:
0172     class Private;
0173     QScopedPointer<Private> d;
0174 };
0175 
0176 }
0177 }
0178 
0179 Q_DECLARE_METATYPE(KWayland::Client::TouchPoint *)
0180 
0181 #endif