Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qxcbcursor.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#pragma once
6
7#include <qpa/qplatformcursor.h>
8#include "qxcbscreen.h"
9#include <xcb/xcb_cursor.h>
10
11#include <QtCore/QCache>
12
13QT_BEGIN_NAMESPACE
14
15#ifndef QT_NO_CURSOR
16
17struct QXcbCursorCacheKey
18{
19 explicit QXcbCursorCacheKey(const QCursor &c);
20 explicit QXcbCursorCacheKey(Qt::CursorShape s) : shape(s), bitmapCacheKey(0), maskCacheKey(0) {}
21 QXcbCursorCacheKey() : shape(Qt::CustomCursor), bitmapCacheKey(0), maskCacheKey(0) {}
22
23 Qt::CursorShape shape;
24 qint64 bitmapCacheKey;
25 qint64 maskCacheKey;
26 union {
27 qint64 hashKey;
28 struct {
29 qint32 x;
30 qint32 y;
31 };
32 } hotspotCacheKey;
33};
34
35inline bool operator==(const QXcbCursorCacheKey &k1, const QXcbCursorCacheKey &k2)
36{
37 return k1.shape == k2.shape &&
38 k1.bitmapCacheKey == k2.bitmapCacheKey &&
39 k1.maskCacheKey == k2.maskCacheKey &&
40 k1.hotspotCacheKey.hashKey == k2.hotspotCacheKey.hashKey;
41}
42
43inline size_t qHash(const QXcbCursorCacheKey &k, size_t seed) noexcept
44{
45 return (size_t(k.shape) + size_t(k.bitmapCacheKey) + size_t(k.maskCacheKey)) ^ seed;
46}
47
48#endif // !QT_NO_CURSOR
49
51{
52public:
53 QXcbCursor(QXcbConnection *conn, QXcbScreen *screen);
54 ~QXcbCursor();
55#ifndef QT_NO_CURSOR
56 void changeCursor(QCursor *cursor, QWindow *window) override;
57#endif
58 QPoint pos() const override;
59 void setPos(const QPoint &pos) override;
60
61 QSize size() const override;
62
63 void updateContext();
64
65 static void queryPointer(QXcbConnection *c, QXcbVirtualDesktop **virtualDesktop, QPoint *pos, int *keybMask = nullptr);
66
67#ifndef QT_NO_CURSOR
68 xcb_cursor_t xcbCursor(const QCursor &c) const
69 { return m_cursorHash.value(QXcbCursorCacheKey(c), xcb_cursor_t(0)); }
70#endif
71
72private:
73
74#ifndef QT_NO_CURSOR
75 typedef QHash<QXcbCursorCacheKey, xcb_cursor_t> CursorHash;
76
77 struct CachedCursor
78 {
79 explicit CachedCursor(xcb_connection_t *conn, xcb_cursor_t c)
80 : cursor(c), connection(conn) {}
81 ~CachedCursor() { xcb_free_cursor(connection, cursor); }
82 xcb_cursor_t cursor;
83 xcb_connection_t *connection;
84 };
85 typedef QCache<QXcbCursorCacheKey, CachedCursor> BitmapCursorCache;
86
87 xcb_cursor_t createFontCursor(int cshape);
88 xcb_cursor_t createBitmapCursor(QCursor *cursor);
89 xcb_cursor_t createNonStandardCursor(int cshape);
90#endif
91
92 QXcbScreen *m_screen;
93 xcb_cursor_context_t *m_cursorContext;
94#ifndef QT_NO_CURSOR
95 CursorHash m_cursorHash;
96 BitmapCursorCache m_bitmapCache;
97#endif
98 static void cursorThemePropertyChanged(QXcbVirtualDesktop *screen,
99 const QByteArray &name,
100 const QVariant &property,
101 void *handle);
102 bool m_callbackForPropertyRegistered;
103};
104
105QT_END_NAMESPACE
Definition qlist.h:80
void updateContext()
xcb_cursor_t xcbCursor(const QCursor &c) const
Definition qxcbcursor.h:68
void changeCursor(QCursor *cursor, QWindow *window) override
This method is called by Qt whenever the cursor graphic should be changed.
QPoint pos() const override
QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
static void queryPointer(QXcbConnection *c, QXcbVirtualDesktop **virtualDesktop, QPoint *pos, int *keybMask=nullptr)
void setPos(const QPoint &pos) override
QSize size() const override
Returns the size of the cursor, in native pixels.
void requestSystemTrayWindowDock(xcb_window_t window) const
void notifyManagerClientMessageEvent(const xcb_client_message_event_t *)
void handleDestroyNotifyEvent(const xcb_destroy_notify_event_t *) override
QXcbWMSupport(QXcbConnection *c)
const QList< xcb_window_t > & virtualRoots() const
bool isSupportedByWM(xcb_atom_t atom) const
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define HANDLE_KEYBOARD_EVENT(event_t, handler)
const char * xcb_protocol_request_codes[]
#define CASE_PRINT_AND_RETURN(name)
static Qt::MouseButtons translateMouseButtons(int s)
const char * xcb_errors[]
#define PRINT_AND_RETURN(name)
#define XI_PRINT_AND_RETURN(name)
#define XI_CASE_PRINT_AND_RETURN(name)
#define HANDLE_PLATFORM_WINDOW_EVENT(event_t, windowMember, handler)
#define Q_XCB_REPLY(call,...)
bool operator==(const QXcbCursorCacheKey &k1, const QXcbCursorCacheKey &k2)
Definition qxcbcursor.h:35
size_t qHash(const QXcbCursorCacheKey &k, size_t seed) noexcept
Definition qxcbcursor.h:43