File indexing completed on 2024-12-22 05:09:23
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_RELATIVEPOINTER_H 0007 #define KWAYLAND_CLIENT_RELATIVEPOINTER_H 0008 0009 #include <QObject> 0010 0011 #include "KWayland/Client/kwaylandclient_export.h" 0012 0013 struct zwp_relative_pointer_manager_v1; 0014 struct zwp_relative_pointer_v1; 0015 0016 namespace KWayland 0017 { 0018 namespace Client 0019 { 0020 class EventQueue; 0021 class Pointer; 0022 class RelativePointer; 0023 0024 /** 0025 * @short Wrapper for the zwp_relative_pointer_manager_v1 interface. 0026 * 0027 * This class provides a convenient wrapper for the zwp_relative_pointer_manager_v1 interface. 0028 * 0029 * To use this class one needs to interact with the Registry. There are two 0030 * possible ways to create the RelativePointerManager interface: 0031 * @code 0032 * RelativePointerManager *c = registry->createRelativePointerManagerUnstableV1(name, version); 0033 * @endcode 0034 * 0035 * This creates the RelativePointerManager and sets it up directly. As an alternative this 0036 * can also be done in a more low level way: 0037 * @code 0038 * RelativePointerManager *c = new RelativePointerManager; 0039 * c->setup(registry->RelativePointerManager(name, version)); 0040 * @endcode 0041 * 0042 * The RelativePointerManager can be used as a drop-in replacement for any zwp_relative_pointer_manager_v1 0043 * pointer as it provides matching cast operators. 0044 * 0045 * @see Registry 0046 * @since 5.28 0047 **/ 0048 class KWAYLANDCLIENT_EXPORT RelativePointerManager : public QObject 0049 { 0050 Q_OBJECT 0051 public: 0052 /** 0053 * Creates a new RelativePointerManager. 0054 * Note: after constructing the RelativePointerManager it is not yet valid and one needs 0055 * to call setup. In order to get a ready to use RelativePointerManager prefer using 0056 * Registry::createRelativePointerManagerUnstableV1. 0057 **/ 0058 explicit RelativePointerManager(QObject *parent = nullptr); 0059 ~RelativePointerManager() override; 0060 0061 /** 0062 * Setup this RelativePointerManagerUnstableV1 to manage the @p relativepointermanagerunstablev1. 0063 * When using Registry::createRelativePointerManagerUnstableV1 there is no need to call this 0064 * method. 0065 **/ 0066 void setup(zwp_relative_pointer_manager_v1 *relativepointermanagerunstablev1); 0067 /** 0068 * @returns @c true if managing a zwp_relative_pointer_manager_v1. 0069 **/ 0070 bool isValid() const; 0071 /** 0072 * Releases the zwp_relative_pointer_manager_v1 interface. 0073 * After the interface has been released the RelativePointerManagerUnstableV1 instance is no 0074 * longer valid and can be setup with another zwp_relative_pointer_manager_v1 interface. 0075 **/ 0076 void release(); 0077 /** 0078 * Destroys the data held by this RelativePointerManagerUnstableV1. 0079 * This method is supposed to be used when the connection to the Wayland 0080 * server goes away. If the connection is not valid anymore, it's not 0081 * possible to call release anymore as that calls into the Wayland 0082 * connection and the call would fail. This method cleans up the data, so 0083 * that the instance can be deleted or set up to a new zwp_relative_pointer_manager_v1 interface 0084 * once there is a new connection available. 0085 * 0086 * It is suggested to connect this method to ConnectionThread::connectionDied: 0087 * @code 0088 * connect(connection, &ConnectionThread::connectionDied, relativepointermanagerunstablev1, &RelativePointerManagerUnstableV1::destroy); 0089 * @endcode 0090 * 0091 * @see release 0092 **/ 0093 void destroy(); 0094 0095 /** 0096 * Sets the @p queue to use for creating objects with this RelativePointerManagerUnstableV1. 0097 **/ 0098 void setEventQueue(EventQueue *queue); 0099 /** 0100 * @returns The event queue to use for creating objects with this RelativePointerManagerUnstableV1. 0101 **/ 0102 EventQueue *eventQueue(); 0103 0104 /** 0105 * Creates a RelativePointer for the given @p pointer. 0106 **/ 0107 RelativePointer *createRelativePointer(Pointer *pointer, QObject *parent = nullptr); 0108 0109 operator zwp_relative_pointer_manager_v1 *(); 0110 operator zwp_relative_pointer_manager_v1 *() const; 0111 0112 Q_SIGNALS: 0113 /** 0114 * The corresponding global for this interface on the Registry got removed. 0115 * 0116 * This signal gets only emitted if the RelativePointerManagerUnstableV1 got created by 0117 * Registry::createRelativePointerManagerUnstableV1 0118 **/ 0119 void removed(); 0120 0121 private: 0122 class Private; 0123 QScopedPointer<Private> d; 0124 }; 0125 0126 /** 0127 * @short Wrapper for the zwp_relative_pointer_v1 interface. 0128 * 0129 * The RelativePointer is an extension to the Pointer used for emitting 0130 * relative pointer events. It shares the same focus as Pointer of the same Seat 0131 * and will only emit events when it has focus. 0132 * 0133 * @since 5.28 0134 **/ 0135 class KWAYLANDCLIENT_EXPORT RelativePointer : public QObject 0136 { 0137 Q_OBJECT 0138 public: 0139 ~RelativePointer() override; 0140 0141 /** 0142 * Setup this RelativePointerUnstableV1 to manage the @p relativepointerunstablev1. 0143 * When using RelativePointerManagerUnstableV1::createRelativePointerUnstableV1 there is no need to call this 0144 * method. 0145 **/ 0146 void setup(zwp_relative_pointer_v1 *relativepointerunstablev1); 0147 /** 0148 * @returns @c true if managing a zwp_relative_pointer_v1. 0149 **/ 0150 bool isValid() const; 0151 /** 0152 * Releases the zwp_relative_pointer_v1 interface. 0153 * After the interface has been released the RelativePointerUnstableV1 instance is no 0154 * longer valid and can be setup with another zwp_relative_pointer_v1 interface. 0155 **/ 0156 void release(); 0157 /** 0158 * Destroys the data held by this RelativePointerUnstableV1. 0159 * This method is supposed to be used when the connection to the Wayland 0160 * server goes away. If the connection is not valid anymore, it's not 0161 * possible to call release anymore as that calls into the Wayland 0162 * connection and the call would fail. This method cleans up the data, so 0163 * that the instance can be deleted or set up to a new zwp_relative_pointer_v1 interface 0164 * once there is a new connection available. 0165 * 0166 * This method is automatically invoked when the Registry which created this 0167 * RelativePointer gets destroyed. 0168 * 0169 * @see release 0170 **/ 0171 void destroy(); 0172 0173 operator zwp_relative_pointer_v1 *(); 0174 operator zwp_relative_pointer_v1 *() const; 0175 0176 Q_SIGNALS: 0177 /** 0178 * A relative motion event. 0179 * 0180 * A relative motion is in the same dimension as regular motion events, 0181 * except they do not represent an absolute position. For example, 0182 * moving a pointer from (x, y) to (x', y') would have the equivalent 0183 * relative motion (x' - x, y' - y). If a pointer motion caused the 0184 * absolute pointer position to be clipped by for example the edge of the 0185 * monitor, the relative motion is unaffected by the clipping and will 0186 * represent the unclipped motion. 0187 * 0188 * This signal also contains non-accelerated motion deltas (@p deltaNonAccelerated). 0189 * The non-accelerated delta is, when applicable, the regular pointer motion 0190 * delta as it was before having applied motion acceleration and other 0191 * transformations such as normalization. 0192 * 0193 * Note that the non-accelerated delta does not represent 'raw' events as 0194 * they were read from some device. Pointer motion acceleration is device- 0195 * and configuration-specific and non-accelerated deltas and accelerated 0196 * deltas may have the same value on some devices. 0197 * 0198 * Relative motions are not coupled to Pointer motion events, 0199 * and can be sent in combination with such events, but also independently. There may 0200 * also be scenarios where Pointer motion is sent, but there is no 0201 * relative motion. The order of an absolute and relative motion event 0202 * originating from the same physical motion is not guaranteed. 0203 * 0204 * @param delta Motion vector 0205 * @param deltaNonAccelerated non-accelerated motion vector 0206 * @param microseconds timestamp with microseconds granularity 0207 **/ 0208 void relativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 timestamp); 0209 0210 private: 0211 friend class RelativePointerManager; 0212 explicit RelativePointer(QObject *parent = nullptr); 0213 class Private; 0214 QScopedPointer<Private> d; 0215 }; 0216 0217 } 0218 } 0219 0220 #endif