Debian Codegraph @

xcb/libqt6xcbqpa-dev/6.4.2/qxcbcursor.h

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