1// Copyright (C) 2018 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#include "qxcbatom.h"
4
5#include <QtCore/qglobal.h>
6
7#include <string.h>
8
9#include <algorithm>
10
11static const char *xcb_atomnames = {
12 // window-manager <-> client protocols
13 "WM_PROTOCOLS\0"
14 "WM_DELETE_WINDOW\0"
15 "WM_TAKE_FOCUS\0"
16 "_NET_WM_PING\0"
17 "_NET_WM_CONTEXT_HELP\0"
18 "_NET_WM_SYNC_REQUEST\0"
19 "_NET_WM_SYNC_REQUEST_COUNTER\0"
20 "MANAGER\0"
21 "_NET_SYSTEM_TRAY_OPCODE\0"
22
23 // ICCCM window state
24 "WM_STATE\0"
25 "WM_CHANGE_STATE\0"
26 "WM_CLASS\0"
27 "WM_NAME\0"
28
29 // Session management
30 "WM_CLIENT_LEADER\0"
31 "WM_WINDOW_ROLE\0"
32 "SM_CLIENT_ID\0"
33 "WM_CLIENT_MACHINE\0"
34
35 // Clipboard
36 "CLIPBOARD\0"
37 "INCR\0"
38 "TARGETS\0"
39 "MULTIPLE\0"
40 "TIMESTAMP\0"
41 "SAVE_TARGETS\0"
42 "CLIP_TEMPORARY\0"
43 "_QT_SELECTION\0"
44 "_QT_CLIPBOARD_SENTINEL\0"
45 "_QT_SELECTION_SENTINEL\0"
46 "CLIPBOARD_MANAGER\0"
47
48 "RESOURCE_MANAGER\0"
49
50 "_XSETROOT_ID\0"
51
52 "_QT_SCROLL_DONE\0"
53 "_QT_INPUT_ENCODING\0"
54
55 "_QT_CLOSE_CONNECTION\0"
56
57 "_QT_GET_TIMESTAMP\0"
58
59 "_MOTIF_WM_HINTS\0"
60
61 "DTWM_IS_RUNNING\0"
62 "ENLIGHTENMENT_DESKTOP\0"
63 "_DT_SAVE_MODE\0"
64 "_SGI_DESKS_MANAGER\0"
65
66 // EWMH (aka NETWM)
67 "_NET_SUPPORTED\0"
68 "_NET_VIRTUAL_ROOTS\0"
69 "_NET_WORKAREA\0"
70
71 "_NET_MOVERESIZE_WINDOW\0"
72 "_NET_WM_MOVERESIZE\0"
73
74 "_NET_WM_NAME\0"
75 "_NET_WM_ICON_NAME\0"
76 "_NET_WM_ICON\0"
77
78 "_NET_WM_PID\0"
79
80 "_NET_WM_WINDOW_OPACITY\0"
81
82 "_NET_WM_STATE\0"
83 "_NET_WM_STATE_ABOVE\0"
84 "_NET_WM_STATE_BELOW\0"
85 "_NET_WM_STATE_FULLSCREEN\0"
86 "_NET_WM_STATE_MAXIMIZED_HORZ\0"
87 "_NET_WM_STATE_MAXIMIZED_VERT\0"
88 "_NET_WM_STATE_MODAL\0"
89 "_NET_WM_STATE_STAYS_ON_TOP\0"
90 "_NET_WM_STATE_DEMANDS_ATTENTION\0"
91 "_NET_WM_STATE_HIDDEN\0"
92
93 "_NET_WM_USER_TIME\0"
94 "_NET_WM_USER_TIME_WINDOW\0"
95 "_NET_WM_FULL_PLACEMENT\0"
96
97 "_NET_WM_WINDOW_TYPE\0"
98 "_NET_WM_WINDOW_TYPE_DESKTOP\0"
99 "_NET_WM_WINDOW_TYPE_DOCK\0"
100 "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
101 "_NET_WM_WINDOW_TYPE_MENU\0"
102 "_NET_WM_WINDOW_TYPE_UTILITY\0"
103 "_NET_WM_WINDOW_TYPE_SPLASH\0"
104 "_NET_WM_WINDOW_TYPE_DIALOG\0"
105 "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
106 "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
107 "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
108 "_NET_WM_WINDOW_TYPE_NOTIFICATION\0"
109 "_NET_WM_WINDOW_TYPE_COMBO\0"
110 "_NET_WM_WINDOW_TYPE_DND\0"
111 "_NET_WM_WINDOW_TYPE_NORMAL\0"
112 "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0"
113
114 "_KDE_NET_WM_FRAME_STRUT\0"
115 "_NET_FRAME_EXTENTS\0"
116
117 "_NET_STARTUP_INFO\0"
118 "_NET_STARTUP_INFO_BEGIN\0"
119 "_NET_STARTUP_ID\0"
120
121 "_NET_SUPPORTING_WM_CHECK\0"
122
123 "_NET_WM_CM_S0\0"
124
125 "_NET_SYSTEM_TRAY_VISUAL\0"
126
127 "_NET_ACTIVE_WINDOW\0"
128
129 // Property formats
130 "TEXT\0"
131 "UTF8_STRING\0"
132 "CARDINAL\0"
133
134 // xdnd
135 "XdndEnter\0"
136 "XdndPosition\0"
137 "XdndStatus\0"
138 "XdndLeave\0"
139 "XdndDrop\0"
140 "XdndFinished\0"
141 "XdndTypeList\0"
142 "XdndActionList\0"
143
144 "XdndSelection\0"
145
146 "XdndAware\0"
147 "XdndProxy\0"
148
149 "XdndActionCopy\0"
150 "XdndActionLink\0"
151 "XdndActionMove\0"
152 "XdndActionAsk\0"
153 "XdndActionPrivate\0"
154
155 // Xkb
156 "_XKB_RULES_NAMES\0"
157
158 // XEMBED
159 "_XEMBED\0"
160 "_XEMBED_INFO\0"
161
162 // XInput2
163 "Button Left\0"
164 "Button Middle\0"
165 "Button Right\0"
166 "Button Wheel Up\0"
167 "Button Wheel Down\0"
168 "Button Horiz Wheel Left\0"
169 "Button Horiz Wheel Right\0"
170 "Abs MT Position X\0"
171 "Abs MT Position Y\0"
172 "Abs MT Touch Major\0"
173 "Abs MT Touch Minor\0"
174 "Abs MT Orientation\0"
175 "Abs MT Pressure\0"
176 "Abs MT Tracking ID\0"
177 "Max Contacts\0"
178 "Rel X\0"
179 "Rel Y\0"
180 // XInput2 tablet
181 "Abs X\0"
182 "Abs Y\0"
183 "Abs Pressure\0"
184 "Abs Tilt X\0"
185 "Abs Tilt Y\0"
186 "Abs Wheel\0"
187 "Abs Distance\0"
188 "Wacom Serial IDs\0"
189 "INTEGER\0"
190 "Rel Horiz Wheel\0"
191 "Rel Vert Wheel\0"
192 "Rel Horiz Scroll\0"
193 "Rel Vert Scroll\0"
194 "_XSETTINGS_SETTINGS\0"
195 "_COMPIZ_DECOR_PENDING\0"
196 "_COMPIZ_DECOR_REQUEST\0"
197 "_COMPIZ_DECOR_DELETE_PIXMAP\0"
198 "_COMPIZ_TOOLKIT_ACTION\0"
199 "_GTK_LOAD_ICONTHEMES\0"
200 "AT_SPI_BUS\0"
201 "EDID\0"
202 "EDID_DATA\0"
203 "XFree86_DDC_EDID1_RAWDATA\0"
204 "_ICC_PROFILE\0"
205 // \0\0 terminates loop.
206};
207
208QXcbAtom::QXcbAtom()
209{
210}
211
212void QXcbAtom::initialize(xcb_connection_t *connection)
213{
214 initializeAllAtoms(connection);
215}
216
217void QXcbAtom::initializeAllAtoms(xcb_connection_t *connection) {
218 const char *name = xcb_atomnames;
219 size_t name_len;
220 int i = 0;
221 xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms];
222
223 while ((name_len = strlen(s: name)) != 0) {
224 cookies[i] = xcb_intern_atom(c: connection, only_if_exists: false, name_len, name);
225 ++i;
226 name += name_len + 1; // jump over the \0
227 }
228
229 Q_ASSERT(i == QXcbAtom::NAtoms);
230
231 for (i = 0; i < QXcbAtom::NAtoms; ++i) {
232 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(c: connection, cookie: cookies[i], e: nullptr);
233 if (reply) {
234 m_allAtoms[i] = reply->atom;
235 free(ptr: reply);
236 }
237 }
238}
239
240QXcbAtom::Atom QXcbAtom::qatom(xcb_atom_t xatom) const
241{
242 return static_cast<QXcbAtom::Atom>(std::find(first: m_allAtoms, last: m_allAtoms + QXcbAtom::NAtoms, val: xatom) - m_allAtoms);
243}
244

source code of qtbase/src/plugins/platforms/xcb/qxcbatom.cpp