From bcdb2ff57c69502059267e86d3814801d737e456 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 21 Dec 2022 18:30:27 +0000 Subject: [PATCH] Add CursorSource size getter CursorSource::size() provides a way to get the size of the attached cursor source without actually looking into its contents. --- src/cursor.cpp | 11 ++++++----- src/cursorsource.cpp | 9 +++++++++ src/cursorsource.h | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/cursor.cpp b/src/cursor.cpp index bd13fe4d7e..fc8d099d10 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -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() diff --git a/src/cursorsource.cpp b/src/cursorsource.cpp index a0edcd476d..c02a04abc5 100644 --- a/src/cursorsource.cpp +++ b/src/cursorsource.cpp @@ -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; } diff --git a/src/cursorsource.h b/src/cursorsource.h index 701e8e0f62..9fe65a2896 100644 --- a/src/cursorsource.h +++ b/src/cursorsource.h @@ -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; };