File indexing completed on 2025-03-16 08:15:21
0001 /* 0002 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "utils/xcursortheme.h" 0010 0011 #include <QImage> 0012 #include <QObject> 0013 #include <QPoint> 0014 #include <QTimer> 0015 0016 namespace KWin 0017 { 0018 0019 class SurfaceInterface; 0020 0021 /** 0022 * The CursorSource class represents the contents of the Cursor. 0023 */ 0024 class KWIN_EXPORT CursorSource : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit CursorSource(QObject *parent = nullptr); 0030 0031 QSizeF size() const; 0032 QPointF hotspot() const; 0033 0034 Q_SIGNALS: 0035 void changed(); 0036 0037 protected: 0038 QSizeF m_size = QSizeF(0, 0); 0039 QPointF m_hotspot; 0040 }; 0041 0042 /** 0043 * The ShapeCursorSource class represents the contents of a shape in the cursor theme. 0044 */ 0045 class KWIN_EXPORT ShapeCursorSource : public CursorSource 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 explicit ShapeCursorSource(QObject *parent = nullptr); 0051 0052 QImage image() const; 0053 0054 QByteArray shape() const; 0055 void setShape(const QByteArray &shape); 0056 void setShape(Qt::CursorShape shape); 0057 0058 KXcursorTheme theme() const; 0059 void setTheme(const KXcursorTheme &theme); 0060 0061 private: 0062 void refresh(); 0063 void selectNextSprite(); 0064 void selectSprite(int index); 0065 0066 KXcursorTheme m_theme; 0067 QByteArray m_shape; 0068 QList<KXcursorSprite> m_sprites; 0069 QTimer m_delayTimer; 0070 QImage m_image; 0071 int m_currentSprite = -1; 0072 }; 0073 0074 /** 0075 * The SurfaceCursorSource class repsents the contents of a cursor backed by a wl_surface. 0076 */ 0077 class KWIN_EXPORT SurfaceCursorSource : public CursorSource 0078 { 0079 Q_OBJECT 0080 0081 public: 0082 explicit SurfaceCursorSource(QObject *parent = nullptr); 0083 0084 SurfaceInterface *surface() const; 0085 0086 public Q_SLOTS: 0087 void update(SurfaceInterface *surface, const QPointF &hotspot); 0088 0089 private: 0090 void refresh(); 0091 void reset(); 0092 0093 SurfaceInterface *m_surface = nullptr; 0094 }; 0095 0096 } // namespace KWin