utils: Rename KXcursorTheme to CursorTheme

The KXcursorTheme type no longer with Xcursor only cursors, so rename it
to maintain more reasonable naming conventions.
This commit is contained in:
Vlad Zahorodnii 2024-08-04 21:00:15 +03:00
parent 266c6ee855
commit 68a621f95a
16 changed files with 231 additions and 233 deletions

View file

@ -14,7 +14,7 @@
#include "effect/effecthandler.h"
#include "options.h"
#include "pointer_input.h"
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
#include "virtualdesktops.h"
#include "wayland/seat.h"
#include "wayland_server.h"
@ -42,7 +42,7 @@ static PlatformCursorImage loadReferenceThemeCursor(const QByteArray &name)
{
const Cursor *pointerCursor = Cursors::self()->mouse();
const KXcursorTheme theme(pointerCursor->themeName(), pointerCursor->themeSize(), kwinApp()->devicePixelRatio());
const CursorTheme theme(pointerCursor->themeName(), pointerCursor->themeSize(), kwinApp()->devicePixelRatio());
if (theme.isEmpty()) {
return PlatformCursorImage();
}

View file

@ -586,6 +586,7 @@ install(FILES
install(FILES
utils/c_ptr.h
utils/common.h
utils/cursortheme.h
utils/damagejournal.h
utils/drm_format_helper.h
utils/edid.h
@ -604,7 +605,6 @@ install(FILES
utils/version.h
utils/vsyncmonitor.h
utils/xcbutils.h
utils/xcursortheme.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kwin/utils COMPONENT Devel)
install(FILES

View file

@ -65,12 +65,12 @@ void ShapeCursorSource::setShape(Qt::CursorShape shape)
setShape(CursorShape(shape).name());
}
KXcursorTheme ShapeCursorSource::theme() const
CursorTheme ShapeCursorSource::theme() const
{
return m_theme;
}
void ShapeCursorSource::setTheme(const KXcursorTheme &theme)
void ShapeCursorSource::setTheme(const CursorTheme &theme)
{
if (m_theme != theme) {
m_theme = theme;
@ -109,7 +109,7 @@ void ShapeCursorSource::selectSprite(int index)
if (m_currentSprite == index) {
return;
}
const KXcursorSprite &sprite = m_sprites[index];
const CursorSprite &sprite = m_sprites[index];
m_currentSprite = index;
m_image = sprite.data();
m_size = QSizeF(m_image.size()) / m_image.devicePixelRatio();

View file

@ -6,7 +6,7 @@
#pragma once
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
#include <QImage>
#include <QObject>
@ -58,17 +58,17 @@ public:
void setShape(const QByteArray &shape);
void setShape(Qt::CursorShape shape);
KXcursorTheme theme() const;
void setTheme(const KXcursorTheme &theme);
CursorTheme theme() const;
void setTheme(const CursorTheme &theme);
private:
void refresh();
void selectNextSprite();
void selectSprite(int index);
KXcursorTheme m_theme;
CursorTheme m_theme;
QByteArray m_shape;
QList<KXcursorSprite> m_sprites;
QList<CursorSprite> m_sprites;
QTimer m_delayTimer;
QImage m_image;
int m_currentSprite = -1;

View file

@ -18,7 +18,7 @@
namespace KWin
{
ShakeCursorItem::ShakeCursorItem(const KXcursorTheme &theme, Item *parent)
ShakeCursorItem::ShakeCursorItem(const CursorTheme &theme, Item *parent)
: Item(parent)
{
m_source = std::make_unique<ShapeCursorSource>();
@ -145,9 +145,9 @@ void ShakeCursorEffect::magnify(qreal magnification)
effects->hideCursor();
const qreal maxScale = ShakeCursorConfig::magnification() + 8 * ShakeCursorConfig::overMagnification();
const KXcursorTheme originalTheme = input()->pointer()->cursorTheme();
const CursorTheme originalTheme = input()->pointer()->cursorTheme();
if (m_cursorTheme.name() != originalTheme.name() || m_cursorTheme.size() != originalTheme.size() || m_cursorTheme.devicePixelRatio() != maxScale) {
m_cursorTheme = KXcursorTheme(originalTheme.name(), originalTheme.size(), maxScale);
m_cursorTheme = CursorTheme(originalTheme.name(), originalTheme.size(), maxScale);
}
m_cursorItem = std::make_unique<ShakeCursorItem>(m_cursorTheme, effects->scene()->overlayItem());

View file

@ -10,7 +10,7 @@
#include "input_event_spy.h"
#include "plugins/shakecursor/shakedetector.h"
#include "scene/cursoritem.h"
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
#include <QTimer>
#include <QVariantAnimation>
@ -27,7 +27,7 @@ class ShakeCursorItem : public Item
Q_OBJECT
public:
ShakeCursorItem(const KXcursorTheme &theme, Item *parent);
ShakeCursorItem(const CursorTheme &theme, Item *parent);
private:
void refresh();
@ -63,7 +63,7 @@ private:
Cursor *m_cursor;
std::unique_ptr<ShakeCursorItem> m_cursorItem;
KXcursorTheme m_cursorTheme;
CursorTheme m_cursorTheme;
qreal m_targetMagnification = 1.0;
qreal m_currentMagnification = 1.0;
};

View file

@ -79,7 +79,7 @@ PointerInputRedirection::PointerInputRedirection(InputRedirection *parent)
PointerInputRedirection::~PointerInputRedirection() = default;
KXcursorTheme PointerInputRedirection::cursorTheme() const
CursorTheme PointerInputRedirection::cursorTheme() const
{
return m_cursor->theme();
}
@ -1112,7 +1112,7 @@ WaylandCursorImage::WaylandCursorImage(QObject *parent)
connect(workspace(), &Workspace::outputsChanged, this, &WaylandCursorImage::updateCursorTheme);
}
KXcursorTheme WaylandCursorImage::theme() const
CursorTheme WaylandCursorImage::theme() const
{
return m_cursorTheme;
}
@ -1129,14 +1129,14 @@ void WaylandCursorImage::updateCursorTheme()
}
}
m_cursorTheme = KXcursorTheme(pointerCursor->themeName(), pointerCursor->themeSize(), targetDevicePixelRatio);
m_cursorTheme = CursorTheme(pointerCursor->themeName(), pointerCursor->themeSize(), targetDevicePixelRatio);
if (m_cursorTheme.isEmpty()) {
qCWarning(KWIN_CORE) << "Failed to load cursor theme" << pointerCursor->themeName();
m_cursorTheme = KXcursorTheme(Cursor::defaultThemeName(), Cursor::defaultThemeSize(), targetDevicePixelRatio);
m_cursorTheme = CursorTheme(Cursor::defaultThemeName(), Cursor::defaultThemeSize(), targetDevicePixelRatio);
if (m_cursorTheme.isEmpty()) {
qCWarning(KWIN_CORE) << "Failed to load cursor theme" << Cursor::defaultThemeName();
m_cursorTheme = KXcursorTheme(Cursor::fallbackThemeName(), Cursor::defaultThemeSize(), targetDevicePixelRatio);
m_cursorTheme = CursorTheme(Cursor::fallbackThemeName(), Cursor::defaultThemeSize(), targetDevicePixelRatio);
}
}
@ -1191,7 +1191,7 @@ void CursorImage::setSource(CursorSource *source)
Q_EMIT changed();
}
KXcursorTheme CursorImage::theme() const
CursorTheme CursorImage::theme() const
{
return m_waylandImage.theme();
}

View file

@ -12,7 +12,7 @@
#include "cursor.h"
#include "input.h"
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
#include <QElapsedTimer>
#include <QObject>
@ -48,7 +48,7 @@ public:
void init() override;
KXcursorTheme cursorTheme() const; // TODO: Make it a Cursor property
CursorTheme cursorTheme() const; // TODO: Make it a Cursor property
void updateAfterScreenChange();
bool supportsWarping() const;
@ -206,7 +206,7 @@ class WaylandCursorImage : public QObject
public:
explicit WaylandCursorImage(QObject *parent = nullptr);
KXcursorTheme theme() const;
CursorTheme theme() const;
Q_SIGNALS:
void themeChanged();
@ -214,7 +214,7 @@ Q_SIGNALS:
private:
void updateCursorTheme();
KXcursorTheme m_cursorTheme;
CursorTheme m_cursorTheme;
};
class CursorImage : public QObject
@ -229,7 +229,7 @@ public:
void setWindowSelectionCursor(const QByteArray &shape);
void removeWindowSelectionCursor();
KXcursorTheme theme() const;
CursorTheme theme() const;
CursorSource *source() const;
void setSource(CursorSource *source);

View file

@ -1,5 +1,6 @@
target_sources(kwin PRIVATE
common.cpp
cursortheme.cpp
drm_format_helper.cpp
edid.cpp
filedescriptor.cpp
@ -10,7 +11,6 @@ target_sources(kwin PRIVATE
subsurfacemonitor.cpp
udev.cpp
vsyncmonitor.cpp
xcursortheme.cpp
)
if (KWIN_BUILD_X11)
target_sources(kwin PRIVATE xcbutils.cpp)

View file

@ -4,7 +4,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
#include "utils/svgcursorreader.h"
#include "utils/xcursorreader.h"
@ -21,7 +21,7 @@
namespace KWin
{
class KXcursorSpritePrivate : public QSharedData
class CursorSpritePrivate : public QSharedData
{
public:
QImage data;
@ -29,35 +29,35 @@ public:
std::chrono::milliseconds delay;
};
struct KXcursorThemeXEntryInfo
struct CursorThemeXEntryInfo
{
QString path;
};
struct KXcursorThemeSvgEntryInfo
struct CursorThemeSvgEntryInfo
{
QString path;
};
using KXcursorThemeEntryInfo = std::variant<KXcursorThemeXEntryInfo,
KXcursorThemeSvgEntryInfo>;
using CursorThemeEntryInfo = std::variant<CursorThemeXEntryInfo,
CursorThemeSvgEntryInfo>;
class KXcursorThemeEntry
class CursorThemeEntry
{
public:
explicit KXcursorThemeEntry(const KXcursorThemeEntryInfo &info);
explicit CursorThemeEntry(const CursorThemeEntryInfo &info);
void load(int size, qreal devicePixelRatio);
KXcursorThemeEntryInfo info;
QList<KXcursorSprite> sprites;
CursorThemeEntryInfo info;
QList<CursorSprite> sprites;
};
class KXcursorThemePrivate : public QSharedData
class CursorThemePrivate : public QSharedData
{
public:
KXcursorThemePrivate();
KXcursorThemePrivate(const QString &themeName, int size, qreal devicePixelRatio);
CursorThemePrivate();
CursorThemePrivate(const QString &themeName, int size, qreal devicePixelRatio);
void discover(const QStringList &searchPaths);
void discoverXCursors(const QString &packagePath);
@ -67,83 +67,82 @@ public:
int size = 0;
qreal devicePixelRatio = 0;
QHash<QByteArray, std::shared_ptr<KXcursorThemeEntry>> registry;
QHash<QByteArray, std::shared_ptr<CursorThemeEntry>> registry;
};
KXcursorSprite::KXcursorSprite()
: d(new KXcursorSpritePrivate)
CursorSprite::CursorSprite()
: d(new CursorSpritePrivate)
{
}
KXcursorSprite::KXcursorSprite(const KXcursorSprite &other)
CursorSprite::CursorSprite(const CursorSprite &other)
: d(other.d)
{
}
KXcursorSprite::~KXcursorSprite()
CursorSprite::~CursorSprite()
{
}
KXcursorSprite &KXcursorSprite::operator=(const KXcursorSprite &other)
CursorSprite &CursorSprite::operator=(const CursorSprite &other)
{
d = other.d;
return *this;
}
KXcursorSprite::KXcursorSprite(const QImage &data, const QPoint &hotspot,
const std::chrono::milliseconds &delay)
: d(new KXcursorSpritePrivate)
CursorSprite::CursorSprite(const QImage &data, const QPoint &hotspot, const std::chrono::milliseconds &delay)
: d(new CursorSpritePrivate)
{
d->data = data;
d->hotspot = hotspot;
d->delay = delay;
}
QImage KXcursorSprite::data() const
QImage CursorSprite::data() const
{
return d->data;
}
QPoint KXcursorSprite::hotspot() const
QPoint CursorSprite::hotspot() const
{
return d->hotspot;
}
std::chrono::milliseconds KXcursorSprite::delay() const
std::chrono::milliseconds CursorSprite::delay() const
{
return d->delay;
}
KXcursorThemePrivate::KXcursorThemePrivate()
CursorThemePrivate::CursorThemePrivate()
{
}
KXcursorThemePrivate::KXcursorThemePrivate(const QString &themeName, int size, qreal devicePixelRatio)
CursorThemePrivate::CursorThemePrivate(const QString &themeName, int size, qreal devicePixelRatio)
: name(themeName)
, size(size)
, devicePixelRatio(devicePixelRatio)
{
}
KXcursorThemeEntry::KXcursorThemeEntry(const KXcursorThemeEntryInfo &info)
CursorThemeEntry::CursorThemeEntry(const CursorThemeEntryInfo &info)
: info(info)
{
}
void KXcursorThemeEntry::load(int size, qreal devicePixelRatio)
void CursorThemeEntry::load(int size, qreal devicePixelRatio)
{
if (!sprites.isEmpty()) {
return;
}
if (const auto raster = std::get_if<KXcursorThemeXEntryInfo>(&info)) {
if (const auto raster = std::get_if<CursorThemeXEntryInfo>(&info)) {
sprites = XCursorReader::load(raster->path, size, devicePixelRatio);
} else if (const auto svg = std::get_if<KXcursorThemeSvgEntryInfo>(&info)) {
} else if (const auto svg = std::get_if<CursorThemeSvgEntryInfo>(&info)) {
sprites = SvgCursorReader::load(svg->path, size, devicePixelRatio);
}
}
void KXcursorThemePrivate::discoverXCursors(const QString &packagePath)
void CursorThemePrivate::discoverXCursors(const QString &packagePath)
{
const QDir dir(packagePath);
QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
@ -165,13 +164,13 @@ void KXcursorThemePrivate::discoverXCursors(const QString &packagePath)
}
}
}
registry.insert(shape, std::make_shared<KXcursorThemeEntry>(KXcursorThemeXEntryInfo{
registry.insert(shape, std::make_shared<CursorThemeEntry>(CursorThemeXEntryInfo{
.path = entry.absoluteFilePath(),
}));
}
}
void KXcursorThemePrivate::discoverSvgCursors(const QString &packagePath)
void CursorThemePrivate::discoverSvgCursors(const QString &packagePath)
{
const QDir dir(packagePath);
QFileInfoList entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
@ -193,7 +192,7 @@ void KXcursorThemePrivate::discoverSvgCursors(const QString &packagePath)
}
}
}
registry.insert(shape, std::make_shared<KXcursorThemeEntry>(KXcursorThemeSvgEntryInfo{
registry.insert(shape, std::make_shared<CursorThemeEntry>(CursorThemeSvgEntryInfo{
.path = entry.absoluteFilePath(),
}));
}
@ -222,7 +221,7 @@ static QStringList defaultSearchPaths()
return paths;
}
void KXcursorThemePrivate::discover(const QStringList &searchPaths)
void CursorThemePrivate::discover(const QStringList &searchPaths)
{
const QStringList paths = !searchPaths.isEmpty() ? searchPaths : defaultSearchPaths();
@ -262,69 +261,69 @@ void KXcursorThemePrivate::discover(const QStringList &searchPaths)
}
}
KXcursorTheme::KXcursorTheme()
: d(new KXcursorThemePrivate)
CursorTheme::CursorTheme()
: d(new CursorThemePrivate)
{
}
KXcursorTheme::KXcursorTheme(const QString &themeName, int size, qreal devicePixelRatio, const QStringList &searchPaths)
: d(new KXcursorThemePrivate(themeName, size, devicePixelRatio))
CursorTheme::CursorTheme(const QString &themeName, int size, qreal devicePixelRatio, const QStringList &searchPaths)
: d(new CursorThemePrivate(themeName, size, devicePixelRatio))
{
d->discover(searchPaths);
}
KXcursorTheme::KXcursorTheme(const KXcursorTheme &other)
CursorTheme::CursorTheme(const CursorTheme &other)
: d(other.d)
{
}
KXcursorTheme::~KXcursorTheme()
CursorTheme::~CursorTheme()
{
}
KXcursorTheme &KXcursorTheme::operator=(const KXcursorTheme &other)
CursorTheme &CursorTheme::operator=(const CursorTheme &other)
{
d = other.d;
return *this;
}
bool KXcursorTheme::operator==(const KXcursorTheme &other)
bool CursorTheme::operator==(const CursorTheme &other)
{
return d == other.d;
}
bool KXcursorTheme::operator!=(const KXcursorTheme &other)
bool CursorTheme::operator!=(const CursorTheme &other)
{
return !(*this == other);
}
QString KXcursorTheme::name() const
QString CursorTheme::name() const
{
return d->name;
}
int KXcursorTheme::size() const
int CursorTheme::size() const
{
return d->size;
}
qreal KXcursorTheme::devicePixelRatio() const
qreal CursorTheme::devicePixelRatio() const
{
return d->devicePixelRatio;
}
bool KXcursorTheme::isEmpty() const
bool CursorTheme::isEmpty() const
{
return d->registry.isEmpty();
}
QList<KXcursorSprite> KXcursorTheme::shape(const QByteArray &name) const
QList<CursorSprite> CursorTheme::shape(const QByteArray &name) const
{
if (auto entry = d->registry.value(name)) {
entry->load(d->size, d->devicePixelRatio);
return entry->sprites;
}
return QList<KXcursorSprite>();
return QList<CursorSprite>();
}
} // namespace KWin

142
src/utils/cursortheme.h Normal file
View file

@ -0,0 +1,142 @@
/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <kwin_export.h>
#include <QImage>
#include <QList>
#include <QSharedDataPointer>
#include <chrono>
namespace KWin
{
class CursorSpritePrivate;
class CursorThemePrivate;
/**
* The CursorSprite class represents a single sprite in the cursor theme.
*/
class KWIN_EXPORT CursorSprite
{
public:
/**
* Constructs an empty CursorSprite.
*/
CursorSprite();
/**
* Constructs a copy of the CursorSprite object @a other.
*/
CursorSprite(const CursorSprite &other);
/**
* Constructs an CursorSprite with the specified @a data, @a hotspot, and @a delay.
*/
CursorSprite(const QImage &data, const QPoint &hotspot, const std::chrono::milliseconds &delay);
/**
* Destructs the CursorSprite object.
*/
~CursorSprite();
/**
* Assigns the value of @a other to the cursor sprite object.
*/
CursorSprite &operator=(const CursorSprite &other);
/**
* Returns the image for this sprite.
*/
QImage data() const;
/**
* Returns the hotspot for this sprite. (0, 0) corresponds to the upper left corner.
*
* The coordinates of the hotspot are in device independent pixels.
*/
QPoint hotspot() const;
/**
* Returns the time interval between this sprite and the next one, in milliseconds.
*/
std::chrono::milliseconds delay() const;
private:
QSharedDataPointer<CursorSpritePrivate> d;
};
/**
* The CursorTheme class represents a cursor theme.
*/
class KWIN_EXPORT CursorTheme
{
public:
/**
* Constructs an empty cursor theme.
*/
CursorTheme();
/**
* Loads the cursor theme with the given @ themeName and the desired @a size.
* The @a dpr specifies the desired scale factor. If no theme with the provided
* name exists, the cursor theme will be empty.
*
* @a searchPaths specifies where the cursor theme should be looked for.
*/
CursorTheme(const QString &theme, int size, qreal devicePixelRatio, const QStringList &searchPaths = QStringList());
/**
* Constructs a copy of the CursorTheme object @a other.
*/
CursorTheme(const CursorTheme &other);
/**
* Destructs the CursorTheme object.
*/
~CursorTheme();
/**
* Assigns the value of @a other to the cursor theme object.
*/
CursorTheme &operator=(const CursorTheme &other);
bool operator==(const CursorTheme &other);
bool operator!=(const CursorTheme &other);
/**
* The name of the requested cursor theme.
*/
QString name() const;
/**
* The size of the requested cursor theme.
*/
int size() const;
/**
* The scale factor of the requested cursor theme.
*/
qreal devicePixelRatio() const;
/**
* Returns @c true if the cursor theme is empty; otherwise returns @c false.
*/
bool isEmpty() const;
/**
* Returns the list of cursor sprites for the cursor with the given @a name.
*/
QList<CursorSprite> shape(const QByteArray &name) const;
private:
QSharedDataPointer<CursorThemePrivate> d;
};
} // namespace KWin

View file

@ -102,7 +102,7 @@ std::optional<SvgCursorMetaData> SvgCursorMetaData::parse(const QString &filePat
};
}
QList<KXcursorSprite> SvgCursorReader::load(const QString &containerPath, int desiredSize, qreal devicePixelRatio)
QList<CursorSprite> SvgCursorReader::load(const QString &containerPath, int desiredSize, qreal devicePixelRatio)
{
const QDir containerDir(containerPath);
@ -115,7 +115,7 @@ QList<KXcursorSprite> SvgCursorReader::load(const QString &containerPath, int de
const qreal scale = desiredSize / 24.0;
QList<KXcursorSprite> sprites;
QList<CursorSprite> sprites;
for (const SvgCursorMetaDataEntry &entry : metadata->entries) {
const QString filePath = containerDir.filePath(entry.fileName);
@ -134,7 +134,7 @@ QList<KXcursorSprite> SvgCursorReader::load(const QString &containerPath, int de
renderer.render(&painter, bounds);
painter.end();
sprites.append(KXcursorSprite(image, (entry.hotspot * scale).toPoint(), entry.delay));
sprites.append(CursorSprite(image, (entry.hotspot * scale).toPoint(), entry.delay));
}
return sprites;

View file

@ -6,7 +6,7 @@
#pragma once
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
namespace KWin
{
@ -14,7 +14,7 @@ namespace KWin
class SvgCursorReader
{
public:
static QList<KXcursorSprite> load(const QString &filePath, int desiredSize, qreal devicePixelRatio);
static QList<CursorSprite> load(const QString &filePath, int desiredSize, qreal devicePixelRatio);
};
} // namespace KWin

View file

@ -12,7 +12,7 @@
namespace KWin
{
QList<KXcursorSprite> XCursorReader::load(const QString &filePath, int desiredSize, qreal devicePixelRatio)
QList<CursorSprite> XCursorReader::load(const QString &filePath, int desiredSize, qreal devicePixelRatio)
{
QFile file(filePath);
if (!file.open(QFile::ReadOnly)) {
@ -40,7 +40,7 @@ QList<KXcursorSprite> XCursorReader::load(const QString &filePath, int desiredSi
return {};
}
QList<KXcursorSprite> sprites;
QList<CursorSprite> sprites;
for (int i = 0; i < images->nimage; ++i) {
const XcursorImage *nativeCursorImage = images->images[i];
const qreal scale = std::max(qreal(1), qreal(nativeCursorImage->size) / desiredSize);
@ -51,7 +51,7 @@ QList<KXcursorSprite> XCursorReader::load(const QString &filePath, int desiredSi
data.setDevicePixelRatio(scale);
memcpy(data.bits(), nativeCursorImage->pixels, data.sizeInBytes());
sprites.append(KXcursorSprite(data, hotspot / scale, delay));
sprites.append(CursorSprite(data, hotspot / scale, delay));
}
XcursorImagesDestroy(images);

View file

@ -6,7 +6,7 @@
#pragma once
#include "utils/xcursortheme.h"
#include "utils/cursortheme.h"
namespace KWin
{
@ -14,7 +14,7 @@ namespace KWin
class XCursorReader
{
public:
static QList<KXcursorSprite> load(const QString &filePath, int desiredSize, qreal devicePixelRatio);
static QList<CursorSprite> load(const QString &filePath, int desiredSize, qreal devicePixelRatio);
};
} // namespace KWin

View file

@ -1,143 +0,0 @@
/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <kwin_export.h>
#include <QImage>
#include <QList>
#include <QSharedDataPointer>
#include <chrono>
namespace KWin
{
class KXcursorSpritePrivate;
class KXcursorThemePrivate;
/**
* The KXcursorSprite class represents a single sprite in the Xcursor theme.
*/
class KWIN_EXPORT KXcursorSprite
{
public:
/**
* Constructs an empty XcursorSprite.
*/
KXcursorSprite();
/**
* Constructs a copy of the KXcursorSprite object @a other.
*/
KXcursorSprite(const KXcursorSprite &other);
/**
* Constructs an XcursorSprite with the specified @a data, @a hotspot, and @a delay.
*/
KXcursorSprite(const QImage &data, const QPoint &hotspot,
const std::chrono::milliseconds &delay);
/**
* Destructs the KXcursorSprite object.
*/
~KXcursorSprite();
/**
* Assigns the value of @a other to the Xcursor sprite object.
*/
KXcursorSprite &operator=(const KXcursorSprite &other);
/**
* Returns the image for this sprite.
*/
QImage data() const;
/**
* Returns the hotspot for this sprite. (0, 0) corresponds to the upper left corner.
*
* The coordinates of the hotspot are in device independent pixels.
*/
QPoint hotspot() const;
/**
* Returns the time interval between this sprite and the next one, in milliseconds.
*/
std::chrono::milliseconds delay() const;
private:
QSharedDataPointer<KXcursorSpritePrivate> d;
};
/**
* The KXcursorTheme class represents an Xcursor theme.
*/
class KWIN_EXPORT KXcursorTheme
{
public:
/**
* Constructs an empty Xcursor theme.
*/
KXcursorTheme();
/**
* Loads the Xcursor theme with the given @ themeName and the desired @a size.
* The @a dpr specifies the desired scale factor. If no theme with the provided
* name exists, the cursor theme will be empty.
*
* @a searchPaths specifies where the cursor theme should be looked for.
*/
KXcursorTheme(const QString &theme, int size, qreal devicePixelRatio, const QStringList &searchPaths = QStringList());
/**
* Constructs a copy of the KXcursorTheme object @a other.
*/
KXcursorTheme(const KXcursorTheme &other);
/**
* Destructs the KXcursorTheme object.
*/
~KXcursorTheme();
/**
* Assigns the value of @a other to the Xcursor theme object.
*/
KXcursorTheme &operator=(const KXcursorTheme &other);
bool operator==(const KXcursorTheme &other);
bool operator!=(const KXcursorTheme &other);
/**
* The name of the requested Xcursor theme.
*/
QString name() const;
/**
* The size of the requested Xcursor theme.
*/
int size() const;
/**
* The scale factor of the requested Xcursor theme.
*/
qreal devicePixelRatio() const;
/**
* Returns @c true if the Xcursor theme is empty; otherwise returns @c false.
*/
bool isEmpty() const;
/**
* Returns the list of cursor sprites for the cursor with the given @a name.
*/
QList<KXcursorSprite> shape(const QByteArray &name) const;
private:
QSharedDataPointer<KXcursorThemePrivate> d;
};
} // namespace KWin