Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.15.5/qxcbconnection_basic.h

raw
1 // Copyright (C) 2018 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 QXCBBASICCONNECTION_H
6 #define QXCBBASICCONNECTION_H
7
8 #include "qxcbatom.h"
9 #include "qxcbexport.h"
10
11 #include <QtCore/QPair>
12 #include <QtCore/QObject>
13 #include <QtCore/QByteArray>
14 #include <QtCore/QLoggingCategory>
15 #include <QtGui/private/qtguiglobal_p.h>
16
17 #include <xcb/xcb.h>
18
19 #include <memory>
20
21 QT_BEGIN_NAMESPACE
22
23 Q_DECLARE_LOGGING_CATEGORY(lcQpaXcb)
24
25 class Q_XCB_EXPORT QXcbBasicConnection : public QObject
26 {
27 Q_OBJECT
28 public:
29 QXcbBasicConnection(const char *displayName);
30 ~QXcbBasicConnection();
31
32 #if QT_CONFIG(xcb_xlib)
33 void *xlib_display() const { return m_xlibDisplay; }
34 #endif
35 const char *displayName() const { return m_displayName.constData(); }
36 int primaryScreenNumber() const { return m_primaryScreenNumber; }
37 xcb_connection_t *xcb_connection() const { return m_xcbConnection; }
38 bool isConnected() const {
39 return m_xcbConnection && !xcb_connection_has_error(m_xcbConnection);
40 }
41 const xcb_setup_t *setup() const { return m_setup; }
42
43 size_t maxRequestDataBytes(size_t requestSize) const;
44
45 inline xcb_atom_t atom(QXcbAtom::Atom qatom) const { return m_xcbAtom.atom(qatom); }
46 QXcbAtom::Atom qatom(xcb_atom_t atom) const { return m_xcbAtom.qatom(atom); }
47 xcb_atom_t internAtom(const char *name);
48 QByteArray atomName(xcb_atom_t atom);
49
50 bool hasXFixes() const { return m_hasXFixes; }
51 bool hasXShape() const { return m_hasXhape; }
52 bool hasXRandr() const { return m_hasXRandr; }
53 bool hasInputShape() const { return m_hasInputShape; }
54 bool hasXKB() const { return m_hasXkb; }
55 bool hasXRender(int major = -1, int minor = -1) const {
56 if (m_hasXRender && major != -1 && minor != -1)
57 return m_xrenderVersion >= qMakePair(major, minor);
58
59 return m_hasXRender;
60 }
61 bool hasXInput2() const { return m_xi2Enabled; }
62 bool hasShm() const { return m_hasShm; }
63 bool hasShmFd() const { return m_hasShmFd; }
64 bool hasXSync() const { return m_hasXSync; }
65 bool hasXinerama() const { return m_hasXinerama; }
66 bool hasBigRequest() const;
67
68 bool isAtLeastXI21() const { return m_xi2Enabled && m_xi2Minor >= 1; }
69 bool isAtLeastXI22() const { return m_xi2Enabled && m_xi2Minor >= 2; }
70 bool isXIEvent(xcb_generic_event_t *event) const;
71 bool isXIType(xcb_generic_event_t *event, uint16_t type) const;
72
73 bool isXFixesType(uint responseType, int eventType) const;
74 bool isXRandrType(uint responseType, int eventType) const;
75 bool isXkbType(uint responseType) const; // https://bugs.freedesktop.org/show_bug.cgi?id=51295
76
77 protected:
78 void initializeShm();
79 void initializeXFixes();
80 void initializeXRender();
81 void initializeXRandr();
82 void initializeXinerama();
83 void initializeXShape();
84 void initializeXKB();
85 void initializeXSync();
86 void initializeXInput2();
87
88 private:
89 #if QT_CONFIG(xcb_xlib)
90 void *m_xlibDisplay = nullptr;
91 #endif
92 QByteArray m_displayName;
93 xcb_connection_t *m_xcbConnection = nullptr;
94 int m_primaryScreenNumber = 0;
95 const xcb_setup_t *m_setup = nullptr;
96 QXcbAtom m_xcbAtom;
97
98 bool m_hasXFixes = false;
99 bool m_hasXinerama = false;
100 bool m_hasXhape = false;
101 bool m_hasInputShape;
102 bool m_hasXRandr = false;
103 bool m_hasXkb = false;
104 bool m_hasXRender = false;
105 bool m_hasShm = false;
106 bool m_hasShmFd = false;
107 bool m_hasXSync = false;
108
109 QPair<int, int> m_xrenderVersion;
110
111 bool m_xi2Enabled = false;
112 int m_xi2Minor = -1;
113 int m_xiOpCode = -1;
114 uint32_t m_xinputFirstEvent = 0;
115
116 uint32_t m_xfixesFirstEvent = 0;
117 uint32_t m_xrandrFirstEvent = 0;
118 uint32_t m_xkbFirstEvent = 0;
119
120 uint32_t m_maximumRequestLength = 0;
121 };
122
123 #define Q_XCB_REPLY_CONNECTION_ARG(connection, ...) connection
124
125 struct QStdFreeDeleter {
126 void operator()(void *p) const noexcept { return std::free(p); }
127 };
128
129 #define Q_XCB_REPLY(call, ...) \
130 std::unique_ptr<call##_reply_t, QStdFreeDeleter>( \
131 call##_reply(Q_XCB_REPLY_CONNECTION_ARG(__VA_ARGS__), call(__VA_ARGS__), nullptr) \
132 )
133
134 #define Q_XCB_REPLY_UNCHECKED(call, ...) \
135 std::unique_ptr<call##_reply_t, QStdFreeDeleter>( \
136 call##_reply(Q_XCB_REPLY_CONNECTION_ARG(__VA_ARGS__), call##_unchecked(__VA_ARGS__), nullptr) \
137 )
138
139 QT_END_NAMESPACE
140
141 #endif // QXCBBASICCONNECTION_H