File indexing completed on 2024-02-18 16:19:54

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 <QPointer>
0015 #include <QTimer>
0016 
0017 namespace KWaylandServer
0018 {
0019 class SurfaceInterface;
0020 }
0021 
0022 namespace KWin
0023 {
0024 
0025 /**
0026  * The CursorSource class represents the contents of the Cursor.
0027  */
0028 class KWIN_EXPORT CursorSource : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit CursorSource(QObject *parent = nullptr);
0034 
0035     QImage image() const;
0036     QSize size() const;
0037     QPoint hotspot() const;
0038 
0039 Q_SIGNALS:
0040     void changed();
0041 
0042 protected:
0043     QImage m_image;
0044     QSize m_size = QSize(0, 0);
0045     QPoint m_hotspot;
0046 };
0047 
0048 /**
0049  * The ImageCursorSource class represents a static raster cursor pixmap.
0050  */
0051 class KWIN_EXPORT ImageCursorSource : public CursorSource
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056     explicit ImageCursorSource(QObject *parent = nullptr);
0057 
0058 public Q_SLOTS:
0059     void update(const QImage &image, const QPoint &hotspot);
0060 };
0061 
0062 /**
0063  * The ShapeCursorSource class represents the contents of a shape in the cursor theme.
0064  */
0065 class KWIN_EXPORT ShapeCursorSource : public CursorSource
0066 {
0067     Q_OBJECT
0068 
0069 public:
0070     explicit ShapeCursorSource(QObject *parent = nullptr);
0071 
0072     QByteArray shape() const;
0073     void setShape(const QByteArray &shape);
0074     void setShape(Qt::CursorShape shape);
0075 
0076     KXcursorTheme theme() const;
0077     void setTheme(const KXcursorTheme &theme);
0078 
0079 private:
0080     void refresh();
0081     void selectNextSprite();
0082     void selectSprite(int index);
0083 
0084     KXcursorTheme m_theme;
0085     QByteArray m_shape;
0086     QVector<KXcursorSprite> m_sprites;
0087     QTimer m_delayTimer;
0088     int m_currentSprite = -1;
0089 };
0090 
0091 /**
0092  * The SurfaceCursorSource class repsents the contents of a cursor backed by a wl_surface.
0093  */
0094 class KWIN_EXPORT SurfaceCursorSource : public CursorSource
0095 {
0096     Q_OBJECT
0097 
0098 public:
0099     explicit SurfaceCursorSource(QObject *parent = nullptr);
0100 
0101     KWaylandServer::SurfaceInterface *surface() const;
0102 
0103 public Q_SLOTS:
0104     void update(KWaylandServer::SurfaceInterface *surface, const QPoint &hotspot);
0105 
0106 private:
0107     QPointer<KWaylandServer::SurfaceInterface> m_surface;
0108 };
0109 
0110 } // namespace KWin