1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#include "qxcbatom.h"
40
41#include <QtCore/qglobal.h>
42
43#include <string.h>
44
45#include <algorithm>
46
47static const char *xcb_atomnames = {
48 // window-manager <-> client protocols
49 "WM_PROTOCOLS\0"
50 "WM_DELETE_WINDOW\0"
51 "WM_TAKE_FOCUS\0"
52 "_NET_WM_PING\0"
53 "_NET_WM_CONTEXT_HELP\0"
54 "_NET_WM_SYNC_REQUEST\0"
55 "_NET_WM_SYNC_REQUEST_COUNTER\0"
56 "MANAGER\0"
57 "_NET_SYSTEM_TRAY_OPCODE\0"
58
59 // ICCCM window state
60 "WM_STATE\0"
61 "WM_CHANGE_STATE\0"
62 "WM_CLASS\0"
63 "WM_NAME\0"
64
65 // Session management
66 "WM_CLIENT_LEADER\0"
67 "WM_WINDOW_ROLE\0"
68 "SM_CLIENT_ID\0"
69 "WM_CLIENT_MACHINE\0"
70
71 // Clipboard
72 "CLIPBOARD\0"
73 "INCR\0"
74 "TARGETS\0"
75 "MULTIPLE\0"
76 "TIMESTAMP\0"
77 "SAVE_TARGETS\0"
78 "CLIP_TEMPORARY\0"
79 "_QT_SELECTION\0"
80 "_QT_CLIPBOARD_SENTINEL\0"
81 "_QT_SELECTION_SENTINEL\0"
82 "CLIPBOARD_MANAGER\0"
83
84 "RESOURCE_MANAGER\0"
85
86 "_XSETROOT_ID\0"
87
88 "_QT_SCROLL_DONE\0"
89 "_QT_INPUT_ENCODING\0"
90
91 "_QT_CLOSE_CONNECTION\0"
92
93 "_MOTIF_WM_HINTS\0"
94
95 "DTWM_IS_RUNNING\0"
96 "ENLIGHTENMENT_DESKTOP\0"
97 "_DT_SAVE_MODE\0"
98 "_SGI_DESKS_MANAGER\0"
99
100 // EWMH (aka NETWM)
101 "_NET_SUPPORTED\0"
102 "_NET_VIRTUAL_ROOTS\0"
103 "_NET_WORKAREA\0"
104
105 "_NET_MOVERESIZE_WINDOW\0"
106 "_NET_WM_MOVERESIZE\0"
107
108 "_NET_WM_NAME\0"
109 "_NET_WM_ICON_NAME\0"
110 "_NET_WM_ICON\0"
111
112 "_NET_WM_PID\0"
113
114 "_NET_WM_WINDOW_OPACITY\0"
115
116 "_NET_WM_STATE\0"
117 "_NET_WM_STATE_ABOVE\0"
118 "_NET_WM_STATE_BELOW\0"
119 "_NET_WM_STATE_FULLSCREEN\0"
120 "_NET_WM_STATE_MAXIMIZED_HORZ\0"
121 "_NET_WM_STATE_MAXIMIZED_VERT\0"
122 "_NET_WM_STATE_MODAL\0"
123 "_NET_WM_STATE_STAYS_ON_TOP\0"
124 "_NET_WM_STATE_DEMANDS_ATTENTION\0"
125
126 "_NET_WM_USER_TIME\0"
127 "_NET_WM_USER_TIME_WINDOW\0"
128 "_NET_WM_FULL_PLACEMENT\0"
129
130 "_NET_WM_WINDOW_TYPE\0"
131 "_NET_WM_WINDOW_TYPE_DESKTOP\0"
132 "_NET_WM_WINDOW_TYPE_DOCK\0"
133 "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
134 "_NET_WM_WINDOW_TYPE_MENU\0"
135 "_NET_WM_WINDOW_TYPE_UTILITY\0"
136 "_NET_WM_WINDOW_TYPE_SPLASH\0"
137 "_NET_WM_WINDOW_TYPE_DIALOG\0"
138 "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
139 "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
140 "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
141 "_NET_WM_WINDOW_TYPE_NOTIFICATION\0"
142 "_NET_WM_WINDOW_TYPE_COMBO\0"
143 "_NET_WM_WINDOW_TYPE_DND\0"
144 "_NET_WM_WINDOW_TYPE_NORMAL\0"
145 "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0"
146
147 "_KDE_NET_WM_FRAME_STRUT\0"
148 "_NET_FRAME_EXTENTS\0"
149
150 "_NET_STARTUP_INFO\0"
151 "_NET_STARTUP_INFO_BEGIN\0"
152
153 "_NET_SUPPORTING_WM_CHECK\0"
154
155 "_NET_WM_CM_S0\0"
156
157 "_NET_SYSTEM_TRAY_VISUAL\0"
158
159 "_NET_ACTIVE_WINDOW\0"
160
161 // Property formats
162 "TEXT\0"
163 "UTF8_STRING\0"
164 "CARDINAL\0"
165
166 // xdnd
167 "XdndEnter\0"
168 "XdndPosition\0"
169 "XdndStatus\0"
170 "XdndLeave\0"
171 "XdndDrop\0"
172 "XdndFinished\0"
173 "XdndTypeList\0"
174 "XdndActionList\0"
175
176 "XdndSelection\0"
177
178 "XdndAware\0"
179 "XdndProxy\0"
180
181 "XdndActionCopy\0"
182 "XdndActionLink\0"
183 "XdndActionMove\0"
184 "XdndActionPrivate\0"
185
186 // Xkb
187 "_XKB_RULES_NAMES\0"
188
189 // XEMBED
190 "_XEMBED\0"
191 "_XEMBED_INFO\0"
192
193 // XInput2
194 "Button Left\0"
195 "Button Middle\0"
196 "Button Right\0"
197 "Button Wheel Up\0"
198 "Button Wheel Down\0"
199 "Button Horiz Wheel Left\0"
200 "Button Horiz Wheel Right\0"
201 "Abs MT Position X\0"
202 "Abs MT Position Y\0"
203 "Abs MT Touch Major\0"
204 "Abs MT Touch Minor\0"
205 "Abs MT Orientation\0"
206 "Abs MT Pressure\0"
207 "Abs MT Tracking ID\0"
208 "Max Contacts\0"
209 "Rel X\0"
210 "Rel Y\0"
211 // XInput2 tablet
212 "Abs X\0"
213 "Abs Y\0"
214 "Abs Pressure\0"
215 "Abs Tilt X\0"
216 "Abs Tilt Y\0"
217 "Abs Wheel\0"
218 "Abs Distance\0"
219 "Wacom Serial IDs\0"
220 "INTEGER\0"
221 "Rel Horiz Wheel\0"
222 "Rel Vert Wheel\0"
223 "Rel Horiz Scroll\0"
224 "Rel Vert Scroll\0"
225 "_XSETTINGS_SETTINGS\0"
226 "_COMPIZ_DECOR_PENDING\0"
227 "_COMPIZ_DECOR_REQUEST\0"
228 "_COMPIZ_DECOR_DELETE_PIXMAP\0"
229 "_COMPIZ_TOOLKIT_ACTION\0"
230 "_GTK_LOAD_ICONTHEMES\0"
231 "AT_SPI_BUS\0"
232 "EDID\0"
233 "EDID_DATA\0"
234 "XFree86_DDC_EDID1_RAWDATA\0"
235 // \0\0 terminates loop.
236};
237
238QXcbAtom::QXcbAtom()
239{
240}
241
242void QXcbAtom::initialize(xcb_connection_t *connection)
243{
244 initializeAllAtoms(connection);
245}
246
247void QXcbAtom::initializeAllAtoms(xcb_connection_t *connection) {
248 const char *names[QXcbAtom::NAtoms];
249 const char *ptr = xcb_atomnames;
250
251 int i = 0;
252 while (*ptr) {
253 names[i++] = ptr;
254 while (*ptr)
255 ++ptr;
256 ++ptr;
257 }
258
259 Q_ASSERT(i == QXcbAtom::NAtoms);
260
261 xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms];
262
263 Q_ASSERT(i == QXcbAtom::NAtoms);
264 for (i = 0; i < QXcbAtom::NAtoms; ++i)
265 cookies[i] = xcb_intern_atom(connection, false, strlen(names[i]), names[i]);
266
267 for (i = 0; i < QXcbAtom::NAtoms; ++i) {
268 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookies[i], 0);
269 m_allAtoms[i] = reply->atom;
270 free(reply);
271 }
272}
273
274QXcbAtom::Atom QXcbAtom::qatom(xcb_atom_t xatom) const
275{
276 return static_cast<QXcbAtom::Atom>(std::find(m_allAtoms, m_allAtoms + QXcbAtom::NAtoms, xatom) - m_allAtoms);
277}
278