Move installing cursor image form X11CursorTracker to WaylandSeat
This allows to install cursor images also from other parts.
This commit is contained in:
parent
7523c1e7d7
commit
8b1040f78d
2 changed files with 30 additions and 26 deletions
|
@ -288,12 +288,10 @@ bool CursorData::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
X11CursorTracker::X11CursorTracker(wl_pointer *pointer, WaylandBackend *backend, QObject* parent)
|
||||
X11CursorTracker::X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_pointer(pointer)
|
||||
, m_seat(seat)
|
||||
, m_backend(backend)
|
||||
, m_cursor(wl_compositor_create_surface(backend->compositor()))
|
||||
, m_enteredSerial(0)
|
||||
, m_lastX11Cursor(0)
|
||||
{
|
||||
Cursor::self()->startCursorTracking();
|
||||
|
@ -306,9 +304,6 @@ X11CursorTracker::~X11CursorTracker()
|
|||
// Cursor might have been destroyed before Wayland backend gets destroyed
|
||||
Cursor::self()->stopCursorTracking();
|
||||
}
|
||||
if (m_cursor) {
|
||||
wl_surface_destroy(m_cursor);
|
||||
}
|
||||
}
|
||||
|
||||
void X11CursorTracker::cursorChanged(uint32_t serial)
|
||||
|
@ -342,15 +337,7 @@ void X11CursorTracker::installCursor(const CursorData& cursor)
|
|||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
wl_pointer_set_cursor(m_pointer, m_enteredSerial, m_cursor, cursor.hotSpot().x(), cursor.hotSpot().y());
|
||||
wl_surface_attach(m_cursor, buffer, 0, 0);
|
||||
wl_surface_damage(m_cursor, 0, 0, cursorImage.width(), cursorImage.height());
|
||||
wl_surface_commit(m_cursor);
|
||||
}
|
||||
|
||||
void X11CursorTracker::setEnteredSerial(uint32_t serial)
|
||||
{
|
||||
m_enteredSerial = serial;
|
||||
m_seat->installCursorImage(buffer, cursorImage.size(), cursor.hotSpot());
|
||||
}
|
||||
|
||||
void X11CursorTracker::resetCursor()
|
||||
|
@ -511,6 +498,8 @@ WaylandSeat::WaylandSeat(wl_seat *seat, WaylandBackend *backend)
|
|||
: m_seat(seat)
|
||||
, m_pointer(NULL)
|
||||
, m_keyboard(NULL)
|
||||
, m_cursor(NULL)
|
||||
, m_enteredSerial(0)
|
||||
, m_cursorTracker()
|
||||
, m_backend(backend)
|
||||
{
|
||||
|
@ -526,6 +515,9 @@ WaylandSeat::~WaylandSeat()
|
|||
if (m_seat) {
|
||||
wl_seat_destroy(m_seat);
|
||||
}
|
||||
if (m_cursor) {
|
||||
wl_surface_destroy(m_cursor);
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandSeat::destroyPointer()
|
||||
|
@ -550,7 +542,7 @@ void WaylandSeat::changed(uint32_t capabilities)
|
|||
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && !m_pointer) {
|
||||
m_pointer = wl_seat_get_pointer(m_seat);
|
||||
wl_pointer_add_listener(m_pointer, &s_pointerListener, this);
|
||||
m_cursorTracker.reset(new X11CursorTracker(m_pointer, m_backend));
|
||||
m_cursorTracker.reset(new X11CursorTracker(this, m_backend));
|
||||
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER)) {
|
||||
destroyPointer();
|
||||
}
|
||||
|
@ -564,10 +556,7 @@ void WaylandSeat::changed(uint32_t capabilities)
|
|||
|
||||
void WaylandSeat::pointerEntered(uint32_t serial)
|
||||
{
|
||||
if (m_cursorTracker.isNull()) {
|
||||
return;
|
||||
}
|
||||
m_cursorTracker->setEnteredSerial(serial);
|
||||
m_enteredSerial = serial;
|
||||
}
|
||||
|
||||
void WaylandSeat::resetCursor()
|
||||
|
@ -577,6 +566,20 @@ void WaylandSeat::resetCursor()
|
|||
}
|
||||
}
|
||||
|
||||
void WaylandSeat::installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotSpot)
|
||||
{
|
||||
if (!m_pointer) {
|
||||
return;
|
||||
}
|
||||
if (!m_cursor) {
|
||||
m_cursor = wl_compositor_create_surface(m_backend->compositor());
|
||||
}
|
||||
wl_pointer_set_cursor(m_pointer, m_enteredSerial, m_cursor, hotSpot.x(), hotSpot.y());
|
||||
wl_surface_attach(m_cursor, image, 0, 0);
|
||||
wl_surface_damage(m_cursor, 0, 0, size.width(), size.height());
|
||||
wl_surface_commit(m_cursor);
|
||||
}
|
||||
|
||||
WaylandBackend *WaylandBackend::s_self = 0;
|
||||
WaylandBackend *WaylandBackend::create(QObject *parent)
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace Wayland
|
|||
{
|
||||
class ShmPool;
|
||||
class WaylandBackend;
|
||||
class WaylandSeat;
|
||||
|
||||
class CursorData
|
||||
{
|
||||
|
@ -62,19 +63,16 @@ class X11CursorTracker : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit X11CursorTracker(wl_pointer *pointer, WaylandBackend *backend, QObject* parent = 0);
|
||||
explicit X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent = 0);
|
||||
virtual ~X11CursorTracker();
|
||||
void setEnteredSerial(uint32_t serial);
|
||||
void resetCursor();
|
||||
private Q_SLOTS:
|
||||
void cursorChanged(uint32_t serial);
|
||||
private:
|
||||
void installCursor(const CursorData &cursor);
|
||||
wl_pointer *m_pointer;
|
||||
WaylandSeat *m_seat;
|
||||
QHash<uint32_t, CursorData> m_cursors;
|
||||
WaylandBackend *m_backend;
|
||||
wl_surface *m_cursor;
|
||||
uint32_t m_enteredSerial;
|
||||
uint32_t m_installedCursor;
|
||||
uint32_t m_lastX11Cursor;
|
||||
};
|
||||
|
@ -139,12 +137,15 @@ public:
|
|||
wl_seat *seat();
|
||||
void pointerEntered(uint32_t serial);
|
||||
void resetCursor();
|
||||
void installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot);
|
||||
private:
|
||||
void destroyPointer();
|
||||
void destroyKeyboard();
|
||||
wl_seat *m_seat;
|
||||
wl_pointer *m_pointer;
|
||||
wl_keyboard *m_keyboard;
|
||||
wl_surface *m_cursor;
|
||||
uint32_t m_enteredSerial;
|
||||
QScopedPointer<X11CursorTracker> m_cursorTracker;
|
||||
WaylandBackend *m_backend;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue