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

0001 /*
0002     SPDX-FileCopyrightText: 2016 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 KWAYLAND_CLIENT_POINTERGESTURES_H
0007 #define KWAYLAND_CLIENT_POINTERGESTURES_H
0008 
0009 #include <QObject>
0010 #include <QPointer>
0011 
0012 #include "KWayland/Client/kwaylandclient_export.h"
0013 
0014 struct zwp_pointer_gestures_v1;
0015 struct zwp_pointer_gesture_swipe_v1;
0016 struct zwp_pointer_gesture_pinch_v1;
0017 
0018 class QSizeF;
0019 
0020 namespace KWayland
0021 {
0022 namespace Client
0023 {
0024 class EventQueue;
0025 class PointerPinchGesture;
0026 class Pointer;
0027 class Surface;
0028 class PointerSwipeGesture;
0029 
0030 /**
0031  * @short Wrapper for the zwp_pointer_gestures_v1 interface.
0032  *
0033  * This class provides a convenient wrapper for the zwp_pointer_gestures_v1 interface.
0034  *
0035  * To use this class one needs to interact with the Registry. There are two
0036  * possible ways to create the PointerGestures interface:
0037  * @code
0038  * PointerGestures *c = registry->createPointerGestures(name, version);
0039  * @endcode
0040  *
0041  * This creates the PointerGestures and sets it up directly. As an alternative this
0042  * can also be done in a more low level way:
0043  * @code
0044  * PointerGestures *c = new PointerGestures;
0045  * c->setup(registry->bindPointerGestures(name, version));
0046  * @endcode
0047  *
0048  * The PointerGestures can be used as a drop-in replacement for any zwp_pointer_gestures_v1
0049  * pointer as it provides matching cast operators.
0050  *
0051  * @see Registry
0052  * @see PointerSwipeGesture
0053  * @see PointerPinchGesture
0054  * @since 5.29
0055  **/
0056 class KWAYLANDCLIENT_EXPORT PointerGestures : public QObject
0057 {
0058     Q_OBJECT
0059 public:
0060     /**
0061      * Creates a new PointerGestures.
0062      * Note: after constructing the PointerGestures it is not yet valid and one needs
0063      * to call setup. In order to get a ready to use PointerGestures prefer using
0064      * Registry::createPointerGestures.
0065      **/
0066     explicit PointerGestures(QObject *parent = nullptr);
0067     ~PointerGestures() override;
0068 
0069     /**
0070      * Setup this PointerGestures to manage the @p pointergestures.
0071      * When using Registry::createPointerGestures there is no need to call this
0072      * method.
0073      **/
0074     void setup(zwp_pointer_gestures_v1 *pointergestures);
0075     /**
0076      * @returns @c true if managing a zwp_pointer_gestures_v1.
0077      **/
0078     bool isValid() const;
0079     /**
0080      * Releases the zwp_pointer_gestures_v1 interface.
0081      * After the interface has been released the PointerGestures instance is no
0082      * longer valid and can be setup with another zwp_pointer_gestures_v1 interface.
0083      **/
0084     void release();
0085     /**
0086      * Destroys the data held by this PointerGestures.
0087      * This method is supposed to be used when the connection to the Wayland
0088      * server goes away. If the connection is not valid anymore, it's not
0089      * possible to call release anymore as that calls into the Wayland
0090      * connection and the call would fail. This method cleans up the data, so
0091      * that the instance can be deleted or set up to a new zwp_pointer_gestures_v1 interface
0092      * once there is a new connection available.
0093      *
0094      * This method is automatically invoked when the Registry which created this
0095      * PointerGestures gets destroyed.
0096      * @endcode
0097      *
0098      * @see release
0099      **/
0100     void destroy();
0101 
0102     /**
0103      * Sets the @p queue to use for creating objects with this PointerGestures.
0104      **/
0105     void setEventQueue(EventQueue *queue);
0106     /**
0107      * @returns The event queue to use for creating objects with this PointerGestures.
0108      **/
0109     EventQueue *eventQueue();
0110 
0111     /**
0112      * Creates a PointerSwipeGesture for the given @p pointer with the @p parent.
0113      **/
0114     PointerSwipeGesture *createSwipeGesture(Pointer *pointer, QObject *parent = nullptr);
0115 
0116     /**
0117      * Creates a PointerPinchGesture for the given @p pointer with the @p parent.
0118      **/
0119     PointerPinchGesture *createPinchGesture(Pointer *pointer, QObject *parent = nullptr);
0120 
0121     operator zwp_pointer_gestures_v1 *();
0122     operator zwp_pointer_gestures_v1 *() const;
0123 
0124 Q_SIGNALS:
0125     /**
0126      * The corresponding global for this interface on the Registry got removed.
0127      *
0128      * This signal gets only emitted if the PointerGestures got created by
0129      * Registry::createPointerGestures
0130      **/
0131     void removed();
0132 
0133 private:
0134     class Private;
0135     QScopedPointer<Private> d;
0136 };
0137 
0138 /**
0139  * This class is a wrapper for the zwp_pointer_gesture_swipe_v1 protocol.
0140  *
0141  * A PointerSwipeGesture object notifies a client about a multi-finger swipe
0142  * gesture detected on an indirect input device such as a touchpad.
0143  * The gesture is usually initiated by multiple fingers moving in the
0144  * same direction but once initiated the direction may change.
0145  * The precise conditions of when such a gesture is detected are
0146  * implementation-dependent.
0147  *
0148  * A gesture consists of three stages: begin, update (optional) and end.
0149  * There cannot be multiple simultaneous pinch or swipe gestures on the
0150  * same pointer/seat, how compositors prevent these situations is
0151  * implementation-dependent.
0152  *
0153  * A gesture may be cancelled by the compositor or the hardware.
0154  * Clients should not consider performing permanent or irreversible
0155  * actions until the end of a gesture has been received.
0156  *
0157  * @see PointerGestures
0158  * @see PointerPinchGesture
0159  * @since 5.29
0160  **/
0161 class KWAYLANDCLIENT_EXPORT PointerSwipeGesture : public QObject
0162 {
0163     Q_OBJECT
0164 public:
0165     ~PointerSwipeGesture() override;
0166 
0167     /**
0168      * Setup this PointerSwipeGesture to manage the @p pointerswipegesture.
0169      * When using PointerGestures::createPointerSwipeGesture there is no need to call this
0170      * method.
0171      **/
0172     void setup(zwp_pointer_gesture_swipe_v1 *pointerswipegesture);
0173     /**
0174      * @returns @c true if managing a zwp_pointer_gesture_swipe_v1.
0175      **/
0176     bool isValid() const;
0177     /**
0178      * Releases the zwp_pointer_gesture_swipe_v1 interface.
0179      * After the interface has been released the PointerSwipeGesture instance is no
0180      * longer valid and can be setup with another zwp_pointer_gesture_swipe_v1 interface.
0181      **/
0182     void release();
0183     /**
0184      * Destroys the data held by this PointerSwipeGesture.
0185      * This method is supposed to be used when the connection to the Wayland
0186      * server goes away. If the connection is not valid anymore, it's not
0187      * possible to call release anymore as that calls into the Wayland
0188      * connection and the call would fail. This method cleans up the data, so
0189      * that the instance can be deleted or set up to a new zwp_pointer_gesture_swipe_v1 interface
0190      * once there is a new connection available.
0191      *
0192      * It is suggested to connect this method to ConnectionThread::connectionDied:
0193      * @code
0194      * connect(connection, &ConnectionThread::connectionDied, pointerswipegesture, &PointerSwipeGesture::destroy);
0195      * @endcode
0196      *
0197      * @see release
0198      **/
0199     void destroy();
0200 
0201     /**
0202      * The number of fingers taking part in this gesture.
0203      * If no gesture is in progress @c 0 is returned.
0204      **/
0205     quint32 fingerCount() const;
0206 
0207     /**
0208      * The Surface on which this gesture is performed.
0209      * If no gesture is in progress the returned pointer is null.
0210      **/
0211     QPointer<Surface> surface() const;
0212 
0213     operator zwp_pointer_gesture_swipe_v1 *();
0214     operator zwp_pointer_gesture_swipe_v1 *() const;
0215 
0216 Q_SIGNALS:
0217     /**
0218      * A gesture got started.
0219      * @param serial Unique serial for this start gesture event.
0220      * @param time Timestamp in milliseconds granularity
0221      * @see updated
0222      * @see ended
0223      * @see cancelled
0224      **/
0225     void started(quint32 serial, quint32 time);
0226 
0227     /**
0228      * A gesture got updated.
0229      * @param delta relative coordinates of the logical center of the gesture compared to the previous event
0230      * @param time Timestamp in milliseconds granularity
0231      * @see started
0232      * @see ended
0233      * @see cancelled
0234      **/
0235     void updated(const QSizeF &delta, quint32 time);
0236 
0237     /**
0238      * A gesture ended.
0239      *
0240      * @param serial Unique serial for this end gesture event.
0241      * @param time Timestamp in milliseconds granularity
0242      * @see started
0243      * @see updated
0244      * @see cancelled
0245      **/
0246     void ended(quint32 serial, quint32 time);
0247 
0248     /**
0249      * A gesture got cancelled by the Wayland compositor.
0250      *
0251      * @param serial Unique serial for this cancel gesture event.
0252      * @param time Timestamp in milliseconds granularity
0253      * @see started
0254      * @see updated
0255      * @see ended
0256      **/
0257     void cancelled(quint32 serial, quint32 time);
0258 
0259 private:
0260     friend class PointerGestures;
0261     explicit PointerSwipeGesture(QObject *parent = nullptr);
0262     class Private;
0263     QScopedPointer<Private> d;
0264 };
0265 
0266 /**
0267  * This class is a wrapper for the zwp_pointer_gesture_pinch_v1 protocol.
0268  *
0269  * A PointerPinchGesture object notifies a client about a multi-finger pinch
0270  * gesture detected on an indirect input device such as a touchpad.
0271  * The gesture is usually initiated by multiple fingers moving towards
0272  * each other or away from each other, or by two or more fingers rotating
0273  * around a logical center of gravity. The precise conditions of when
0274  * such a gesture is detected are implementation-dependent.
0275  *
0276  * A gesture consists of three stages: begin, update (optional) and end.
0277  * There cannot be multiple simultaneous pinch or swipe gestures on the
0278  * same pointer/seat, how compositors prevent these situations is
0279  * implementation-dependent.
0280  *
0281  * A gesture may be cancelled by the compositor or the hardware.
0282  * Clients should not consider performing permanent or irreversible
0283  * actions until the end of a gesture has been received.
0284  *
0285  * @see PointerGestures
0286  * @see PointerSwipeGesture
0287  * @since 5.29
0288  **/
0289 class KWAYLANDCLIENT_EXPORT PointerPinchGesture : public QObject
0290 {
0291     Q_OBJECT
0292 public:
0293     ~PointerPinchGesture() override;
0294 
0295     /**
0296      * Setup this PointerPinchGesture to manage the @p pointerpinchgesture.
0297      * When using PointerGestures::createPointerPinchGesture there is no need to call this
0298      * method.
0299      **/
0300     void setup(zwp_pointer_gesture_pinch_v1 *pointerpinchgesture);
0301     /**
0302      * @returns @c true if managing a zwp_pointer_gesture_pinch_v1.
0303      **/
0304     bool isValid() const;
0305     /**
0306      * Releases the zwp_pointer_gesture_pinch_v1 interface.
0307      * After the interface has been released the PointerPinchGesture instance is no
0308      * longer valid and can be setup with another zwp_pointer_gesture_pinch_v1 interface.
0309      **/
0310     void release();
0311     /**
0312      * Destroys the data held by this PointerPinchGesture.
0313      * This method is supposed to be used when the connection to the Wayland
0314      * server goes away. If the connection is not valid anymore, it's not
0315      * possible to call release anymore as that calls into the Wayland
0316      * connection and the call would fail. This method cleans up the data, so
0317      * that the instance can be deleted or set up to a new zwp_pointer_gesture_pinch_v1 interface
0318      * once there is a new connection available.
0319      *
0320      * It is suggested to connect this method to ConnectionThread::connectionDied:
0321      * @code
0322      * connect(connection, &ConnectionThread::connectionDied, pointerpinchgesture, &PointerPinchGesture::destroy);
0323      * @endcode
0324      *
0325      * @see release
0326      **/
0327     void destroy();
0328 
0329     /**
0330      * The number of fingers taking part in this gesture.
0331      * If no gesture is in progress @c 0 is returned.
0332      **/
0333     quint32 fingerCount() const;
0334 
0335     /**
0336      * The Surface on which this gesture is performed.
0337      * If no gesture is in progress the returned pointer is null.
0338      **/
0339     QPointer<Surface> surface() const;
0340 
0341     operator zwp_pointer_gesture_pinch_v1 *();
0342     operator zwp_pointer_gesture_pinch_v1 *() const;
0343 
0344 Q_SIGNALS:
0345     /**
0346      * A gesture got started.
0347      * @param serial Unique serial for this start gesture event.
0348      * @param time Timestamp in milliseconds granularity
0349      * @see updated
0350      * @see ended
0351      * @see cancelled
0352      **/
0353     void started(quint32 serial, quint32 time);
0354 
0355     /**
0356      * A gesture got updated.
0357      * @param delta relative coordinates of the logical center of the gesture compared to the previous event
0358      * @param scale an absolute scale compared to the start
0359      * @param rotation relative angle in degrees clockwise compared to the previous start or update event.
0360      * @param time Timestamp in milliseconds granularity
0361      * @see started
0362      * @see ended
0363      * @see cancelled
0364      **/
0365     void updated(const QSizeF &delta, qreal scale, qreal rotation, quint32 time);
0366 
0367     /**
0368      * A gesture ended.
0369      *
0370      * @param serial Unique serial for this end gesture event.
0371      * @param time Timestamp in milliseconds granularity
0372      * @see started
0373      * @see updated
0374      * @see cancelled
0375      **/
0376     void ended(quint32 serial, quint32 time);
0377 
0378     /**
0379      * A gesture got cancelled by the Wayland compositor.
0380      *
0381      * @param serial Unique serial for this cancel gesture event.
0382      * @param time Timestamp in milliseconds granularity
0383      * @see started
0384      * @see updated
0385      * @see ended
0386      **/
0387     void cancelled(quint32 serial, quint32 time);
0388 
0389 private:
0390     friend class PointerGestures;
0391     explicit PointerPinchGesture(QObject *parent = nullptr);
0392     class Private;
0393     QScopedPointer<Private> d;
0394 };
0395 
0396 }
0397 }
0398 
0399 #endif