File indexing completed on 2024-05-19 05:32:39
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 KWin 0018 { 0019 class PointerSurfaceCursorPrivate; 0020 class PointerSurfaceCursor; 0021 class PointerInterfacePrivate; 0022 class SeatInterface; 0023 class SurfaceInterface; 0024 0025 enum class PointerAxisSource; 0026 enum class PointerAxisRelativeDirection; 0027 enum class PointerButtonState : quint32; 0028 0029 using PointerCursor = std::variant<PointerSurfaceCursor *, QByteArray>; 0030 0031 /** 0032 * The PointerInterface class represents one or more input devices such as mice, which control 0033 * the pointer location. It corresponds to the Wayland interface @c wl_pointer. 0034 */ 0035 class KWIN_EXPORT PointerInterface : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 ~PointerInterface() override; 0041 0042 /** 0043 * Returns the focused pointer surface. Note that the returned value may be different 0044 * from SurfaceInterface::focusedSurfacePointerSurface() because this function returns 0045 * the effective focused surface. 0046 */ 0047 SurfaceInterface *focusedSurface() const; 0048 quint32 focusedSerial() const; 0049 0050 /** 0051 * Returns the seat to which this pointer belongs to. 0052 */ 0053 SeatInterface *seat() const; 0054 0055 /** 0056 * @returns The PointerInterface for the @p native resource. 0057 */ 0058 static PointerInterface *get(wl_resource *native); 0059 0060 void sendEnter(SurfaceInterface *surface, const QPointF &position, quint32 serial); 0061 void sendLeave(quint32 serial); 0062 void sendButton(quint32 button, PointerButtonState state, quint32 serial); 0063 void sendAxis(Qt::Orientation orientation, qreal delta, qint32 deltaV120, PointerAxisSource source, PointerAxisRelativeDirection direction); 0064 void sendMotion(const QPointF &position); 0065 void sendFrame(); 0066 0067 Q_SIGNALS: 0068 /** 0069 * This signal is emitted whenever the cursor surface changes. As long as there is no 0070 * any focused surface, the cursor cannot be changed. 0071 */ 0072 void cursorChanged(const PointerCursor &cursor); 0073 /** 0074 * This signal is emitted whenever the focused pointer surface changes. 0075 */ 0076 void focusedSurfaceChanged(); 0077 0078 private: 0079 explicit PointerInterface(SeatInterface *seat); 0080 std::unique_ptr<PointerInterfacePrivate> d; 0081 0082 friend class SeatInterfacePrivate; 0083 friend class PointerInterfacePrivate; 0084 }; 0085 0086 /** 0087 * @brief Class encapsulating a Cursor image. 0088 */ 0089 class KWIN_EXPORT PointerSurfaceCursor 0090 { 0091 public: 0092 PointerSurfaceCursor(); 0093 ~PointerSurfaceCursor(); 0094 0095 /** 0096 * The hotspot of the cursor image in surface-relative coordinates. 0097 */ 0098 QPointF hotspot() const; 0099 /** 0100 * The SurfaceInterface for the image content of the Cursor. 0101 */ 0102 SurfaceInterface *surface() const; 0103 0104 private: 0105 std::unique_ptr<PointerSurfaceCursorPrivate> d; 0106 friend class PointerInterfacePrivate; 0107 }; 0108 0109 } // namespace KWin