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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
X11CursorTracker::X11CursorTracker(wl_pointer *pointer, WaylandBackend *backend, QObject* parent)
|
X11CursorTracker::X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_pointer(pointer)
|
, m_seat(seat)
|
||||||
, m_backend(backend)
|
, m_backend(backend)
|
||||||
, m_cursor(wl_compositor_create_surface(backend->compositor()))
|
|
||||||
, m_enteredSerial(0)
|
|
||||||
, m_lastX11Cursor(0)
|
, m_lastX11Cursor(0)
|
||||||
{
|
{
|
||||||
Cursor::self()->startCursorTracking();
|
Cursor::self()->startCursorTracking();
|
||||||
|
@ -306,9 +304,6 @@ X11CursorTracker::~X11CursorTracker()
|
||||||
// Cursor might have been destroyed before Wayland backend gets destroyed
|
// Cursor might have been destroyed before Wayland backend gets destroyed
|
||||||
Cursor::self()->stopCursorTracking();
|
Cursor::self()->stopCursorTracking();
|
||||||
}
|
}
|
||||||
if (m_cursor) {
|
|
||||||
wl_surface_destroy(m_cursor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11CursorTracker::cursorChanged(uint32_t serial)
|
void X11CursorTracker::cursorChanged(uint32_t serial)
|
||||||
|
@ -342,15 +337,7 @@ void X11CursorTracker::installCursor(const CursorData& cursor)
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wl_pointer_set_cursor(m_pointer, m_enteredSerial, m_cursor, cursor.hotSpot().x(), cursor.hotSpot().y());
|
m_seat->installCursorImage(buffer, cursorImage.size(), cursor.hotSpot());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11CursorTracker::resetCursor()
|
void X11CursorTracker::resetCursor()
|
||||||
|
@ -511,6 +498,8 @@ WaylandSeat::WaylandSeat(wl_seat *seat, WaylandBackend *backend)
|
||||||
: m_seat(seat)
|
: m_seat(seat)
|
||||||
, m_pointer(NULL)
|
, m_pointer(NULL)
|
||||||
, m_keyboard(NULL)
|
, m_keyboard(NULL)
|
||||||
|
, m_cursor(NULL)
|
||||||
|
, m_enteredSerial(0)
|
||||||
, m_cursorTracker()
|
, m_cursorTracker()
|
||||||
, m_backend(backend)
|
, m_backend(backend)
|
||||||
{
|
{
|
||||||
|
@ -526,6 +515,9 @@ WaylandSeat::~WaylandSeat()
|
||||||
if (m_seat) {
|
if (m_seat) {
|
||||||
wl_seat_destroy(m_seat);
|
wl_seat_destroy(m_seat);
|
||||||
}
|
}
|
||||||
|
if (m_cursor) {
|
||||||
|
wl_surface_destroy(m_cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandSeat::destroyPointer()
|
void WaylandSeat::destroyPointer()
|
||||||
|
@ -550,7 +542,7 @@ void WaylandSeat::changed(uint32_t capabilities)
|
||||||
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && !m_pointer) {
|
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && !m_pointer) {
|
||||||
m_pointer = wl_seat_get_pointer(m_seat);
|
m_pointer = wl_seat_get_pointer(m_seat);
|
||||||
wl_pointer_add_listener(m_pointer, &s_pointerListener, this);
|
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)) {
|
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER)) {
|
||||||
destroyPointer();
|
destroyPointer();
|
||||||
}
|
}
|
||||||
|
@ -564,10 +556,7 @@ void WaylandSeat::changed(uint32_t capabilities)
|
||||||
|
|
||||||
void WaylandSeat::pointerEntered(uint32_t serial)
|
void WaylandSeat::pointerEntered(uint32_t serial)
|
||||||
{
|
{
|
||||||
if (m_cursorTracker.isNull()) {
|
m_enteredSerial = serial;
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_cursorTracker->setEnteredSerial(serial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandSeat::resetCursor()
|
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::s_self = 0;
|
||||||
WaylandBackend *WaylandBackend::create(QObject *parent)
|
WaylandBackend *WaylandBackend::create(QObject *parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace Wayland
|
||||||
{
|
{
|
||||||
class ShmPool;
|
class ShmPool;
|
||||||
class WaylandBackend;
|
class WaylandBackend;
|
||||||
|
class WaylandSeat;
|
||||||
|
|
||||||
class CursorData
|
class CursorData
|
||||||
{
|
{
|
||||||
|
@ -62,19 +63,16 @@ class X11CursorTracker : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit X11CursorTracker(wl_pointer *pointer, WaylandBackend *backend, QObject* parent = 0);
|
explicit X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent = 0);
|
||||||
virtual ~X11CursorTracker();
|
virtual ~X11CursorTracker();
|
||||||
void setEnteredSerial(uint32_t serial);
|
|
||||||
void resetCursor();
|
void resetCursor();
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void cursorChanged(uint32_t serial);
|
void cursorChanged(uint32_t serial);
|
||||||
private:
|
private:
|
||||||
void installCursor(const CursorData &cursor);
|
void installCursor(const CursorData &cursor);
|
||||||
wl_pointer *m_pointer;
|
WaylandSeat *m_seat;
|
||||||
QHash<uint32_t, CursorData> m_cursors;
|
QHash<uint32_t, CursorData> m_cursors;
|
||||||
WaylandBackend *m_backend;
|
WaylandBackend *m_backend;
|
||||||
wl_surface *m_cursor;
|
|
||||||
uint32_t m_enteredSerial;
|
|
||||||
uint32_t m_installedCursor;
|
uint32_t m_installedCursor;
|
||||||
uint32_t m_lastX11Cursor;
|
uint32_t m_lastX11Cursor;
|
||||||
};
|
};
|
||||||
|
@ -139,12 +137,15 @@ public:
|
||||||
wl_seat *seat();
|
wl_seat *seat();
|
||||||
void pointerEntered(uint32_t serial);
|
void pointerEntered(uint32_t serial);
|
||||||
void resetCursor();
|
void resetCursor();
|
||||||
|
void installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot);
|
||||||
private:
|
private:
|
||||||
void destroyPointer();
|
void destroyPointer();
|
||||||
void destroyKeyboard();
|
void destroyKeyboard();
|
||||||
wl_seat *m_seat;
|
wl_seat *m_seat;
|
||||||
wl_pointer *m_pointer;
|
wl_pointer *m_pointer;
|
||||||
wl_keyboard *m_keyboard;
|
wl_keyboard *m_keyboard;
|
||||||
|
wl_surface *m_cursor;
|
||||||
|
uint32_t m_enteredSerial;
|
||||||
QScopedPointer<X11CursorTracker> m_cursorTracker;
|
QScopedPointer<X11CursorTracker> m_cursorTracker;
|
||||||
WaylandBackend *m_backend;
|
WaylandBackend *m_backend;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue