X11CursorTracker emits signal when a new cursor image needs to be installed

This means the X11CursorTracker is no longer bound to the WaylandSeat.
Instead the WaylandSeat just connects to the signal emitted by the
X11CursorTracker. This allows to use the X11CursorTracker also in cases
where we don't use a Seat for setting the cursor image.
This commit is contained in:
Martin Gräßlin 2014-10-15 14:29:26 +02:00
parent 752de2d888
commit fd0d966652
2 changed files with 18 additions and 7 deletions

View file

@ -86,9 +86,8 @@ bool CursorData::init()
return true;
}
X11CursorTracker::X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent)
X11CursorTracker::X11CursorTracker(WaylandBackend *backend, QObject* parent)
: QObject(parent)
, m_seat(seat)
, m_backend(backend)
, m_lastX11Cursor(0)
{
@ -131,11 +130,11 @@ void X11CursorTracker::cursorChanged(uint32_t serial)
void X11CursorTracker::installCursor(const CursorData& cursor)
{
const QImage &cursorImage = cursor.cursor();
auto buffer = m_backend->shmPool()->createBuffer(cursorImage).toStrongRef();
auto buffer = m_backend->shmPool()->createBuffer(cursorImage);
if (!buffer) {
return;
}
m_seat->installCursorImage(buffer->buffer(), cursorImage.size(), cursor.hotSpot());
emit cursorImageChanged(buffer, cursorImage.size(), cursor.hotSpot());
}
void X11CursorTracker::resetCursor()
@ -234,7 +233,15 @@ WaylandSeat::WaylandSeat(wl_seat *seat, WaylandBackend *backend)
input()->processPointerAxis(toAxis(), delta, time);
}
);
m_cursorTracker.reset(new X11CursorTracker(this, m_backend));
m_cursorTracker.reset(new X11CursorTracker(m_backend));
connect(m_cursorTracker.data(), &X11CursorTracker::cursorImageChanged, this,
[this](Buffer::Ptr image, const QSize &size, const QPoint &hotspot) {
if (image.isNull()) {
return;
}
installCursorImage(image.toStrongRef()->buffer(), size, hotspot);
}
);
} else {
destroyPointer();
}

View file

@ -39,6 +39,7 @@ namespace KWayland
{
namespace Client
{
class Buffer;
class ShmPool;
class Compositor;
class ConnectionThread;
@ -83,14 +84,17 @@ class X11CursorTracker : public QObject
{
Q_OBJECT
public:
explicit X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent = 0);
explicit X11CursorTracker(WaylandBackend *backend, QObject* parent = 0);
virtual ~X11CursorTracker();
void resetCursor();
Q_SIGNALS:
void cursorImageChanged(QWeakPointer<KWayland::Client::Buffer> image, const QSize &size, const QPoint &hotSpot);
private Q_SLOTS:
void cursorChanged(uint32_t serial);
private:
void installCursor(const CursorData &cursor);
WaylandSeat *m_seat;
QHash<uint32_t, CursorData> m_cursors;
WaylandBackend *m_backend;
uint32_t m_installedCursor;