Add CursorSource size getter

CursorSource::size() provides a way to get the size of the attached
cursor source without actually looking into its contents.
This commit is contained in:
Vlad Zahorodnii 2022-12-21 18:30:27 +00:00
parent d8da7a4eaa
commit bcdb2ff57c
3 changed files with 17 additions and 5 deletions

View file

@ -175,10 +175,7 @@ bool Cursor::isOnOutput(Output *output) const
if (Cursors::self()->isCursorHidden()) {
return false;
}
if (!geometry().intersects(output->geometry())) {
return false;
}
return !image().isNull();
return geometry().intersects(output->geometry());
}
QImage Cursor::image() const
@ -204,7 +201,11 @@ QRect Cursor::geometry() const
QRect Cursor::rect() const
{
return QRect(QPoint(0, 0), image().size() / image().devicePixelRatio());
if (Q_UNLIKELY(!m_source)) {
return QRect();
} else {
return QRect(QPoint(0, 0), m_source->size());
}
}
QPoint Cursor::pos()

View file

@ -22,6 +22,11 @@ QImage CursorSource::image() const
return m_image;
}
QSize CursorSource::size() const
{
return m_size;
}
QPoint CursorSource::hotspot() const
{
return m_hotspot;
@ -35,6 +40,7 @@ ImageCursorSource::ImageCursorSource(QObject *parent)
void ImageCursorSource::update(const QImage &image, const QPoint &hotspot)
{
m_image = image;
m_size = image.size() / image.devicePixelRatio();
m_hotspot = hotspot;
Q_EMIT changed();
}
@ -111,6 +117,7 @@ void ShapeCursorSource::selectSprite(int index)
const KXcursorSprite &sprite = m_sprites[index];
m_currentSprite = index;
m_image = sprite.data();
m_size = m_image.size() / m_image.devicePixelRatio();
m_hotspot = sprite.hotspot();
if (sprite.delay().count() && m_sprites.size() > 1) {
m_delayTimer.start(sprite.delay());
@ -132,6 +139,7 @@ void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, cons
{
if (!surface) {
m_image = QImage();
m_size = QSize(0, 0);
m_hotspot = QPoint();
m_surface = nullptr;
} else {
@ -142,6 +150,7 @@ void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, cons
} else {
m_image = QImage();
}
m_size = surface->size().toSize();
m_hotspot = hotspot;
m_surface = surface;
}

View file

@ -33,6 +33,7 @@ public:
explicit CursorSource(QObject *parent = nullptr);
QImage image() const;
QSize size() const;
QPoint hotspot() const;
Q_SIGNALS:
@ -40,6 +41,7 @@ Q_SIGNALS:
protected:
QImage m_image;
QSize m_size = QSize(0, 0);
QPoint m_hotspot;
};