From fd0d966652eeba82e666791f37ab8aacaba682e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 15 Oct 2014 14:29:26 +0200 Subject: [PATCH] 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. --- wayland_backend.cpp | 17 ++++++++++++----- wayland_backend.h | 8 ++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/wayland_backend.cpp b/wayland_backend.cpp index b184d3b0ae..a4106586d2 100644 --- a/wayland_backend.cpp +++ b/wayland_backend.cpp @@ -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(); } diff --git a/wayland_backend.h b/wayland_backend.h index be10291419..7fb413e1ee 100644 --- a/wayland_backend.h +++ b/wayland_backend.h @@ -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 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 m_cursors; WaylandBackend *m_backend; uint32_t m_installedCursor;