Don't assume SurfaceCursorSource has wl_shm buffer

The SurfaceCursorSource assumes that the cursor surface has a wl_shm
buffer attached to it, which is a bad assumption, as the client can
attach a buffer of any type to the surface. Furthermore, the cursor
surface can have custom transforms applied to it, for example a
wp_viewport, which current code fails to handle.
This commit is contained in:
Vlad Zahorodnii 2023-05-10 09:52:41 +03:00
parent dbce106031
commit 1541e35362
2 changed files with 8 additions and 23 deletions

View file

@ -6,7 +6,6 @@
#include "cursorsource.h"
#include "cursor.h"
#include "wayland/shmclientbuffer.h"
#include "wayland/surface_interface.h"
namespace KWin
@ -17,11 +16,6 @@ CursorSource::CursorSource(QObject *parent)
{
}
QImage CursorSource::image() const
{
return m_image;
}
QSizeF CursorSource::size() const
{
return m_size;
@ -39,6 +33,11 @@ ShapeCursorSource::ShapeCursorSource(QObject *parent)
connect(&m_delayTimer, &QTimer::timeout, this, &ShapeCursorSource::selectNextSprite);
}
QImage ShapeCursorSource::image() const
{
return m_image;
}
QByteArray ShapeCursorSource::shape() const
{
return m_shape;
@ -124,13 +123,6 @@ KWaylandServer::SurfaceInterface *SurfaceCursorSource::surface() const
void SurfaceCursorSource::refresh()
{
auto buffer = qobject_cast<KWaylandServer::ShmClientBuffer *>(m_surface->buffer());
if (buffer) {
m_image = buffer->data().copy();
m_image.setDevicePixelRatio(m_surface->bufferScale());
} else {
m_image = QImage();
}
m_size = m_surface->size();
Q_EMIT changed();
}
@ -154,18 +146,10 @@ void SurfaceCursorSource::update(KWaylandServer::SurfaceInterface *surface, cons
m_surface = surface;
if (m_surface) {
auto buffer = qobject_cast<KWaylandServer::ShmClientBuffer *>(surface->buffer());
if (buffer) {
m_image = buffer->data().copy();
m_image.setDevicePixelRatio(surface->bufferScale());
} else {
m_image = QImage();
}
m_size = surface->size();
connect(m_surface, &KWaylandServer::SurfaceInterface::committed, this, &SurfaceCursorSource::refresh);
} else {
m_image = QImage();
m_size = QSizeF(0, 0);
}
}

View file

@ -32,7 +32,6 @@ class KWIN_EXPORT CursorSource : public QObject
public:
explicit CursorSource(QObject *parent = nullptr);
QImage image() const;
QSizeF size() const;
QPointF hotspot() const;
@ -40,7 +39,6 @@ Q_SIGNALS:
void changed();
protected:
QImage m_image;
QSizeF m_size = QSizeF(0, 0);
QPointF m_hotspot;
};
@ -55,6 +53,8 @@ class KWIN_EXPORT ShapeCursorSource : public CursorSource
public:
explicit ShapeCursorSource(QObject *parent = nullptr);
QImage image() const;
QByteArray shape() const;
void setShape(const QByteArray &shape);
void setShape(Qt::CursorShape shape);
@ -71,6 +71,7 @@ private:
QByteArray m_shape;
QVector<KXcursorSprite> m_sprites;
QTimer m_delayTimer;
QImage m_image;
int m_currentSprite = -1;
};