From e5d0e1a339e39ac2fef5b5711d9ece12bb6c408a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 28 Jan 2015 10:14:56 +0100 Subject: [PATCH] Support getting XCursor by name So far all cursors were only resolved through Qt::CursorShape, but Qt::CursorShape is not a complete mapping of all cursors used inside KWin. E.g. killwindow uses the "pirate" cursor. This change keeps the cursors by name instead of Qt::CursorShape and thus allows us to use Cursor for resolving XCursors everywhere. --- cursor.cpp | 25 ++++++++++++++++++++----- cursor.h | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cursor.cpp b/cursor.cpp index f68437dc16..15caaa9a1d 100644 --- a/cursor.cpp +++ b/cursor.cpp @@ -157,11 +157,22 @@ xcb_cursor_t Cursor::getX11Cursor(Qt::CursorShape shape) return XCB_CURSOR_NONE; } +xcb_cursor_t Cursor::getX11Cursor(const QByteArray &name) +{ + Q_UNUSED(name) + return XCB_CURSOR_NONE; +} + xcb_cursor_t Cursor::x11Cursor(Qt::CursorShape shape) { return s_self->getX11Cursor(shape); } +xcb_cursor_t Cursor::x11Cursor(const QByteArray &name) +{ + return s_self->getX11Cursor(name); +} + void Cursor::doSetPos() { emit posChanged(m_pos); @@ -325,16 +336,20 @@ void X11Cursor::mousePolled() xcb_cursor_t X11Cursor::getX11Cursor(Qt::CursorShape shape) { - QHash::const_iterator it = m_cursors.constFind(shape); + return getX11Cursor(cursorName(shape)); +} + +xcb_cursor_t X11Cursor::getX11Cursor(const QByteArray &name) +{ + auto it = m_cursors.constFind(name); if (it != m_cursors.constEnd()) { return it.value(); } - return createCursor(shape); + return createCursor(name); } -xcb_cursor_t X11Cursor::createCursor(Qt::CursorShape shape) +xcb_cursor_t X11Cursor::createCursor(const QByteArray &name) { - const QByteArray name = cursorName(shape); if (name.isEmpty()) { return XCB_CURSOR_NONE; } @@ -345,7 +360,7 @@ xcb_cursor_t X11Cursor::createCursor(Qt::CursorShape shape) } xcb_cursor_t cursor = XcursorImageLoadCursor(display(), ximg); XcursorImageDestroy(ximg); - m_cursors.insert(shape, cursor); + m_cursors.insert(name, cursor); return cursor; } diff --git a/cursor.h b/cursor.h index 4bb3a3c1dd..5e2342fb2a 100644 --- a/cursor.h +++ b/cursor.h @@ -121,6 +121,11 @@ public: static void setPos(const QPoint &pos); static void setPos(int x, int y); static xcb_cursor_t x11Cursor(Qt::CursorShape shape); + /** + * Notice: if available always use the Qt::CursorShape variant to avoid cache duplicates for + * ambiguous cursor names in the non existing cursor name spcification + **/ + static xcb_cursor_t x11Cursor(const QByteArray &name); Q_SIGNALS: void posChanged(QPoint pos); @@ -146,6 +151,12 @@ protected: * mouse cursors. **/ virtual xcb_cursor_t getX11Cursor(Qt::CursorShape shape); + /** + * Called from @link x11Cursor to actually retrieve the X11 cursor. Base implementation returns + * a null cursor, an implementing subclass should implement this method if it can provide X11 + * mouse cursors. + **/ + virtual xcb_cursor_t getX11Cursor(const QByteArray &name); /** * Performs the actual warping of the cursor. **/ @@ -211,6 +222,7 @@ public: virtual ~X11Cursor(); protected: virtual xcb_cursor_t getX11Cursor(Qt::CursorShape shape); + xcb_cursor_t getX11Cursor(const QByteArray &name) override; virtual void doSetPos(); virtual void doGetPos(); virtual void doStartMousePolling(); @@ -228,8 +240,8 @@ private Q_SLOTS: void mousePolled(); private: X11Cursor(QObject *parent); - xcb_cursor_t createCursor(Qt::CursorShape shape); - QHash m_cursors; + xcb_cursor_t createCursor(const QByteArray &name); + QHash m_cursors; xcb_timestamp_t m_timeStamp; uint16_t m_buttonMask; QTimer *m_resetTimeStampTimer;