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

0001 /*
0002     SPDX-FileCopyrightText: 2014 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_POINTER_H
0007 #define WAYLAND_POINTER_H
0008 
0009 #include <QObject>
0010 #include <QPoint>
0011 
0012 #include "KWayland/Client/kwaylandclient_export.h"
0013 
0014 struct wl_pointer;
0015 
0016 namespace KWayland
0017 {
0018 namespace Client
0019 {
0020 class Surface;
0021 
0022 /**
0023  * @short Wrapper for the wl_pointer interface.
0024  *
0025  * This class is a convenient wrapper for the wl_pointer interface.
0026  *
0027  * To create an instance use Seat::createPointer.
0028  *
0029  * @see Seat
0030  **/
0031 class KWAYLANDCLIENT_EXPORT Pointer : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     enum class ButtonState {
0036         Released,
0037         Pressed,
0038     };
0039     enum class Axis {
0040         Vertical,
0041         Horizontal,
0042     };
0043     enum class AxisSource {
0044         Wheel,
0045         Finger,
0046         Continuous,
0047         WheelTilt,
0048     };
0049     explicit Pointer(QObject *parent = nullptr);
0050     ~Pointer() override;
0051 
0052     /**
0053      * @returns @c true if managing a wl_pointer.
0054      **/
0055     bool isValid() const;
0056     /**
0057      * Setup this Pointer to manage the @p pointer.
0058      * When using Seat::createPointer there is no need to call this
0059      * method.
0060      **/
0061     void setup(wl_pointer *pointer);
0062     /**
0063      * Releases the wl_pointer interface.
0064      * After the interface has been released the Pointer instance is no
0065      * longer valid and can be setup with another wl_pointer interface.
0066      *
0067      * This method is automatically invoked when the Seat which created this
0068      * Pointer gets released.
0069      **/
0070     void release();
0071     /**
0072      * Destroys the data held by this Pointer.
0073      * This method is supposed to be used when the connection to the Wayland
0074      * server goes away. If the connection is not valid anymore, it's not
0075      * possible to call release anymore as that calls into the Wayland
0076      * connection and the call would fail. This method cleans up the data, so
0077      * that the instance can be deleted or set up to a new wl_pointer interface
0078      * once there is a new connection available.
0079      *
0080      * This method is automatically invoked when the Seat which created this
0081      * Pointer gets destroyed.
0082      *
0083      * @see release
0084      **/
0085     void destroy();
0086 
0087     /**
0088      * Sets the cursor image for this Pointer.
0089      *
0090      * This has only an effect if a Surface of the same client is focused.
0091      *
0092      * @param surface The Surface pointing to the image data, if @c null the cursor will be hidden
0093      * @param hotspot The hotspot of the cursor image
0094      * @see hideCursor
0095      * @since 5.3
0096      **/
0097     void setCursor(Surface *surface, const QPoint &hotspot = QPoint());
0098     /**
0099      * Hides the cursor. Same as calling setCursor with @c null for surface.
0100      * @see setCursor
0101      * @since 5.3
0102      **/
0103     void hideCursor();
0104 
0105     /**
0106      * @returns The Surface the Pointer is on, may be @c null.
0107      **/
0108     Surface *enteredSurface() const;
0109     /**
0110      * @overload
0111      **/
0112     Surface *enteredSurface();
0113 
0114     operator wl_pointer *();
0115     operator wl_pointer *() const;
0116 
0117 Q_SIGNALS:
0118     /**
0119      * Notification that this seat's pointer is focused on a certain surface.
0120      *
0121      * When an seat's focus enters a surface, the pointer image is undefined
0122      * and a client should respond to this event by setting an appropriate pointer
0123      * image with the set_cursor request.
0124      *
0125      * @param serial The serial for this enter
0126      * @param relativeToSurface Coordinates relative to the upper-left corner of the Surface.
0127      **/
0128     void entered(quint32 serial, const QPointF &relativeToSurface);
0129     /**
0130      * Notification that this seat's pointer is no longer focused on a certain surface.
0131      *
0132      * The leave notification is sent before the enter notification for the new focus.
0133      *
0134      * @param serial The serial of this leave event
0135      **/
0136     void left(quint32 serial);
0137     /**
0138      * Notification of pointer location change.
0139      *
0140      * @param relativeToSurface  Coordinates relative to the upper-left corner of the entered Surface.
0141      * @param time timestamp with millisecond granularity
0142      **/
0143     void motion(const QPointF &relativeToSurface, quint32 time);
0144     /**
0145      * Mouse button click and release notifications.
0146      *
0147      * The location of the click is given by the last motion or enter event.
0148      *
0149      * @param serial The serial of this button state change
0150      * @param time timestamp with millisecond granularity, with an undefined base.
0151      * @param button The button which got changed
0152      * @param state @c Released or @c Pressed
0153      **/
0154     void buttonStateChanged(quint32 serial, quint32 time, quint32 button, KWayland::Client::Pointer::ButtonState state);
0155     /**
0156      * Scroll and other axis notifications.
0157      *
0158      * @param time timestamp with millisecond granularity
0159      * @param axis @c Vertical or @c Horizontal
0160      * @param delta
0161      **/
0162     void axisChanged(quint32 time, KWayland::Client::Pointer::Axis axis, qreal delta);
0163     /**
0164      * Indicates the source of scroll and other axes.
0165      *
0166      * @since 5.59
0167      **/
0168     void axisSourceChanged(KWayland::Client::Pointer::AxisSource source);
0169     /**
0170      * Discrete step information for scroll and other axes.
0171      *
0172      * @since 5.59
0173      **/
0174     void axisDiscreteChanged(KWayland::Client::Pointer::Axis axis, qint32 discreteDelta);
0175     /**
0176      * Stop notification for scroll and other axes.
0177      *
0178      * @since 5.59
0179      **/
0180     void axisStopped(quint32 time, KWayland::Client::Pointer::Axis axis);
0181 
0182     /**
0183      * Indicates the end of a set of events that logically belong together.
0184      * A client is expected to accumulate the data in all events within the
0185      * frame before proceeding.
0186      * @since 5.45
0187      **/
0188     void frame();
0189 
0190 private:
0191     class Private;
0192     QScopedPointer<Private> d;
0193 };
0194 
0195 }
0196 }
0197 
0198 Q_DECLARE_METATYPE(KWayland::Client::Pointer::ButtonState)
0199 Q_DECLARE_METATYPE(KWayland::Client::Pointer::Axis)
0200 Q_DECLARE_METATYPE(KWayland::Client::Pointer::AxisSource)
0201 
0202 #endif