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.
This commit is contained in:
Martin Gräßlin 2015-01-28 10:14:56 +01:00
parent 65fe7e6fc2
commit e5d0e1a339
2 changed files with 34 additions and 7 deletions

View file

@ -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<Qt::CursorShape, xcb_cursor_t>::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;
}

View file

@ -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<Qt::CursorShape, xcb_cursor_t > m_cursors;
xcb_cursor_t createCursor(const QByteArray &name);
QHash<QByteArray, xcb_cursor_t > m_cursors;
xcb_timestamp_t m_timeStamp;
uint16_t m_buttonMask;
QTimer *m_resetTimeStampTimer;