| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 |
|
| 5 |
#ifndef QXCBCURSOR_H |
| 6 |
#define QXCBCURSOR_H |
| 7 |
|
| 8 |
#include <qpa/qplatformcursor.h> |
| 9 |
#include "qxcbscreen.h" |
| 10 |
|
| 11 |
QT_BEGIN_NAMESPACE |
| 12 |
|
| 13 |
#ifndef QT_NO_CURSOR |
| 14 |
|
| 15 |
struct QXcbCursorCacheKey |
| 16 |
{ |
| 17 |
explicit QXcbCursorCacheKey(const QCursor &c); |
| 18 |
explicit QXcbCursorCacheKey(Qt::CursorShape s) : shape(s), bitmapCacheKey(0), maskCacheKey(0) {} |
| 19 |
QXcbCursorCacheKey() : shape(Qt::CustomCursor), bitmapCacheKey(0), maskCacheKey(0) {} |
| 20 |
|
| 21 |
Qt::CursorShape shape; |
| 22 |
qint64 bitmapCacheKey; |
| 23 |
qint64 maskCacheKey; |
| 24 |
}; |
| 25 |
|
| 26 |
inline bool operator==(const QXcbCursorCacheKey &k1, const QXcbCursorCacheKey &k2) |
| 27 |
{ |
| 28 |
return k1.shape == k2.shape && k1.bitmapCacheKey == k2.bitmapCacheKey && k1.maskCacheKey == k2.maskCacheKey; |
| 29 |
} |
| 30 |
|
| 31 |
inline uint qHash(const QXcbCursorCacheKey &k, uint seed) Q_DECL_NOTHROW |
| 32 |
{ |
| 33 |
return (uint(k.shape) + uint(k.bitmapCacheKey) + uint(k.maskCacheKey)) ^ seed; |
| 34 |
} |
| 35 |
|
| 36 |
#endif // !QT_NO_CURSOR |
| 37 |
|
| 38 |
class QXcbCursor : public QXcbObject, public QPlatformCursor |
| 39 |
{ |
| 40 |
public: |
| 41 |
QXcbCursor(QXcbConnection *conn, QXcbScreen *screen); |
| 42 |
~QXcbCursor(); |
| 43 |
#ifndef QT_NO_CURSOR |
| 44 |
void changeCursor(QCursor *cursor, QWindow *widget) Q_DECL_OVERRIDE; |
| 45 |
#endif |
| 46 |
QPoint pos() const Q_DECL_OVERRIDE; |
| 47 |
void setPos(const QPoint &pos) Q_DECL_OVERRIDE; |
| 48 |
|
| 49 |
static void queryPointer(QXcbConnection *c, QXcbVirtualDesktop **virtualDesktop, QPoint *pos, int *keybMask = 0); |
| 50 |
|
| 51 |
#ifndef QT_NO_CURSOR |
| 52 |
xcb_cursor_t xcbCursor(const QCursor &c) const |
| 53 |
{ return m_cursorHash.value(QXcbCursorCacheKey(c), xcb_cursor_t(0)); } |
| 54 |
#endif |
| 55 |
|
| 56 |
private: |
| 57 |
#ifndef QT_NO_CURSOR |
| 58 |
typedef QHash<QXcbCursorCacheKey, xcb_cursor_t> CursorHash; |
| 59 |
|
| 60 |
xcb_cursor_t createFontCursor(int cshape); |
| 61 |
xcb_cursor_t createBitmapCursor(QCursor *cursor); |
| 62 |
xcb_cursor_t createNonStandardCursor(int cshape); |
| 63 |
#endif |
| 64 |
|
| 65 |
QXcbScreen *m_screen; |
| 66 |
#ifndef QT_NO_CURSOR |
| 67 |
CursorHash m_cursorHash; |
| 68 |
#endif |
| 69 |
#if defined(XCB_USE_XLIB) && !defined(QT_NO_LIBRARY) |
| 70 |
static void cursorThemePropertyChanged(QXcbVirtualDesktop *screen, |
| 71 |
const QByteArray &name, |
| 72 |
const QVariant &property, |
| 73 |
void *handle); |
| 74 |
#endif |
| 75 |
bool m_gtkCursorThemeInitialized; |
| 76 |
}; |
| 77 |
|
| 78 |
QT_END_NAMESPACE |
| 79 |
|
| 80 |
#endif |