File indexing completed on 2024-05-19 16:35:24

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2020 Adrien Faveraux <ad1rie3@hotmail.fr>
0004     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 #pragma once
0009 
0010 #include "kwin_export.h"
0011 
0012 #include <QObject>
0013 #include <memory>
0014 
0015 struct wl_resource;
0016 
0017 namespace KWaylandServer
0018 {
0019 class CursorPrivate;
0020 class Cursor;
0021 class PointerInterfacePrivate;
0022 class SeatInterface;
0023 class SurfaceInterface;
0024 
0025 enum class PointerAxisSource;
0026 enum class PointerButtonState : quint32;
0027 
0028 /**
0029  * The PointerInterface class represents one or more input devices such as mice, which control
0030  * the pointer location. It corresponds to the Wayland interface @c wl_pointer.
0031  */
0032 class KWIN_EXPORT PointerInterface : public QObject
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     ~PointerInterface() override;
0038 
0039     /**
0040      * Returns the focused pointer surface. Note that the returned value may be different
0041      * from SurfaceInterface::focusedSurfacePointerSurface() because this function returns
0042      * the effective focused surface.
0043      */
0044     SurfaceInterface *focusedSurface() const;
0045 
0046     Cursor *cursor() const;
0047 
0048     /**
0049      * Returns the seat to which this pointer belongs to.
0050      */
0051     SeatInterface *seat() const;
0052 
0053     /**
0054      * @returns The PointerInterface for the @p native resource.
0055      */
0056     static PointerInterface *get(wl_resource *native);
0057 
0058     void sendEnter(SurfaceInterface *surface, const QPointF &position, quint32 serial);
0059     void sendLeave(quint32 serial);
0060     void sendButton(quint32 button, PointerButtonState state, quint32 serial);
0061     void sendAxis(Qt::Orientation orientation, qreal delta, qint32 deltaV120, PointerAxisSource source);
0062     void sendMotion(const QPointF &position);
0063     void sendFrame();
0064 
0065 Q_SIGNALS:
0066     /**
0067      * This signal is emitted whenever the cursor surface changes. As long as there is no
0068      * any focused surface, the cursor cannot be changed.
0069      */
0070     void cursorChanged();
0071     /**
0072      * This signal is emitted whenever the focused pointer surface changes.
0073      */
0074     void focusedSurfaceChanged();
0075 
0076 private:
0077     explicit PointerInterface(SeatInterface *seat);
0078     std::unique_ptr<PointerInterfacePrivate> d;
0079 
0080     friend class SeatInterfacePrivate;
0081     friend class PointerInterfacePrivate;
0082 };
0083 
0084 /**
0085  * @brief Class encapsulating a Cursor image.
0086  */
0087 class KWIN_EXPORT Cursor : public QObject
0088 {
0089     Q_OBJECT
0090 
0091 public:
0092     virtual ~Cursor();
0093     /**
0094      * The hotspot of the cursor image in surface-relative coordinates.
0095      */
0096     QPoint hotspot() const;
0097     /**
0098      * The entered serial when the Cursor got set.
0099      */
0100     quint32 enteredSerial() const;
0101     /**
0102      * The PointerInterface this Cursor belongs to.
0103      */
0104     PointerInterface *pointer() const;
0105     /**
0106      * The SurfaceInterface for the image content of the Cursor.
0107      */
0108     SurfaceInterface *surface() const;
0109 
0110 Q_SIGNALS:
0111     void hotspotChanged();
0112     void enteredSerialChanged();
0113     void surfaceChanged();
0114     void changed();
0115 
0116 private:
0117     std::unique_ptr<CursorPrivate> d;
0118     friend class PointerInterfacePrivate;
0119     explicit Cursor(PointerInterface *parent);
0120 };
0121 
0122 } // namespace KWaylandServer