| 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 | |
| 47 | static 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 | "_NET_WM_STATE_HIDDEN\0" |
| 126 | |
| 127 | "_NET_WM_USER_TIME\0" |
| 128 | "_NET_WM_USER_TIME_WINDOW\0" |
| 129 | "_NET_WM_FULL_PLACEMENT\0" |
| 130 | |
| 131 | "_NET_WM_WINDOW_TYPE\0" |
| 132 | "_NET_WM_WINDOW_TYPE_DESKTOP\0" |
| 133 | "_NET_WM_WINDOW_TYPE_DOCK\0" |
| 134 | "_NET_WM_WINDOW_TYPE_TOOLBAR\0" |
| 135 | "_NET_WM_WINDOW_TYPE_MENU\0" |
| 136 | "_NET_WM_WINDOW_TYPE_UTILITY\0" |
| 137 | "_NET_WM_WINDOW_TYPE_SPLASH\0" |
| 138 | "_NET_WM_WINDOW_TYPE_DIALOG\0" |
| 139 | "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0" |
| 140 | "_NET_WM_WINDOW_TYPE_POPUP_MENU\0" |
| 141 | "_NET_WM_WINDOW_TYPE_TOOLTIP\0" |
| 142 | "_NET_WM_WINDOW_TYPE_NOTIFICATION\0" |
| 143 | "_NET_WM_WINDOW_TYPE_COMBO\0" |
| 144 | "_NET_WM_WINDOW_TYPE_DND\0" |
| 145 | "_NET_WM_WINDOW_TYPE_NORMAL\0" |
| 146 | "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0" |
| 147 | |
| 148 | "_KDE_NET_WM_FRAME_STRUT\0" |
| 149 | "_NET_FRAME_EXTENTS\0" |
| 150 | |
| 151 | "_NET_STARTUP_INFO\0" |
| 152 | "_NET_STARTUP_INFO_BEGIN\0" |
| 153 | |
| 154 | "_NET_SUPPORTING_WM_CHECK\0" |
| 155 | |
| 156 | "_NET_WM_CM_S0\0" |
| 157 | |
| 158 | "_NET_SYSTEM_TRAY_VISUAL\0" |
| 159 | |
| 160 | "_NET_ACTIVE_WINDOW\0" |
| 161 | |
| 162 | // Property formats |
| 163 | "TEXT\0" |
| 164 | "UTF8_STRING\0" |
| 165 | "CARDINAL\0" |
| 166 | |
| 167 | // xdnd |
| 168 | "XdndEnter\0" |
| 169 | "XdndPosition\0" |
| 170 | "XdndStatus\0" |
| 171 | "XdndLeave\0" |
| 172 | "XdndDrop\0" |
| 173 | "XdndFinished\0" |
| 174 | "XdndTypeList\0" |
| 175 | "XdndActionList\0" |
| 176 | |
| 177 | "XdndSelection\0" |
| 178 | |
| 179 | "XdndAware\0" |
| 180 | "XdndProxy\0" |
| 181 | |
| 182 | "XdndActionCopy\0" |
| 183 | "XdndActionLink\0" |
| 184 | "XdndActionMove\0" |
| 185 | "XdndActionAsk\0" |
| 186 | "XdndActionPrivate\0" |
| 187 | |
| 188 | // Xkb |
| 189 | "_XKB_RULES_NAMES\0" |
| 190 | |
| 191 | // XEMBED |
| 192 | "_XEMBED\0" |
| 193 | "_XEMBED_INFO\0" |
| 194 | |
| 195 | // XInput2 |
| 196 | "Button Left\0" |
| 197 | "Button Middle\0" |
| 198 | "Button Right\0" |
| 199 | "Button Wheel Up\0" |
| 200 | "Button Wheel Down\0" |
| 201 | "Button Horiz Wheel Left\0" |
| 202 | "Button Horiz Wheel Right\0" |
| 203 | "Abs MT Position X\0" |
| 204 | "Abs MT Position Y\0" |
| 205 | "Abs MT Touch Major\0" |
| 206 | "Abs MT Touch Minor\0" |
| 207 | "Abs MT Orientation\0" |
| 208 | "Abs MT Pressure\0" |
| 209 | "Abs MT Tracking ID\0" |
| 210 | "Max Contacts\0" |
| 211 | "Rel X\0" |
| 212 | "Rel Y\0" |
| 213 | // XInput2 tablet |
| 214 | "Abs X\0" |
| 215 | "Abs Y\0" |
| 216 | "Abs Pressure\0" |
| 217 | "Abs Tilt X\0" |
| 218 | "Abs Tilt Y\0" |
| 219 | "Abs Wheel\0" |
| 220 | "Abs Distance\0" |
| 221 | "Wacom Serial IDs\0" |
| 222 | "INTEGER\0" |
| 223 | "Rel Horiz Wheel\0" |
| 224 | "Rel Vert Wheel\0" |
| 225 | "Rel Horiz Scroll\0" |
| 226 | "Rel Vert Scroll\0" |
| 227 | "_XSETTINGS_SETTINGS\0" |
| 228 | "_COMPIZ_DECOR_PENDING\0" |
| 229 | "_COMPIZ_DECOR_REQUEST\0" |
| 230 | "_COMPIZ_DECOR_DELETE_PIXMAP\0" |
| 231 | "_COMPIZ_TOOLKIT_ACTION\0" |
| 232 | "_GTK_LOAD_ICONTHEMES\0" |
| 233 | "AT_SPI_BUS\0" |
| 234 | "EDID\0" |
| 235 | "EDID_DATA\0" |
| 236 | "XFree86_DDC_EDID1_RAWDATA\0" |
| 237 | // \0\0 terminates loop. |
| 238 | }; |
| 239 | |
| 240 | QXcbAtom::QXcbAtom() |
| 241 | { |
| 242 | } |
| 243 | |
| 244 | void QXcbAtom::initialize(xcb_connection_t *connection) |
| 245 | { |
| 246 | initializeAllAtoms(connection); |
| 247 | } |
| 248 | |
| 249 | void QXcbAtom::initializeAllAtoms(xcb_connection_t *connection) { |
| 250 | const char *names[QXcbAtom::NAtoms]; |
| 251 | const char *ptr = xcb_atomnames; |
| 252 | |
| 253 | int i = 0; |
| 254 | while (*ptr) { |
| 255 | names[i++] = ptr; |
| 256 | while (*ptr) |
| 257 | ++ptr; |
| 258 | ++ptr; |
| 259 | } |
| 260 | |
| 261 | Q_ASSERT(i == QXcbAtom::NAtoms); |
| 262 | |
| 263 | xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms]; |
| 264 | |
| 265 | Q_ASSERT(i == QXcbAtom::NAtoms); |
| 266 | for (i = 0; i < QXcbAtom::NAtoms; ++i) |
| 267 | cookies[i] = xcb_intern_atom(c: connection, only_if_exists: false, name_len: strlen(s: names[i]), name: names[i]); |
| 268 | |
| 269 | for (i = 0; i < QXcbAtom::NAtoms; ++i) { |
| 270 | xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(c: connection, cookie: cookies[i], e: nullptr); |
| 271 | m_allAtoms[i] = reply->atom; |
| 272 | free(ptr: reply); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | QXcbAtom::Atom QXcbAtom::qatom(xcb_atom_t xatom) const |
| 277 | { |
| 278 | return static_cast<QXcbAtom::Atom>(std::find(first: m_allAtoms, last: m_allAtoms + QXcbAtom::NAtoms, val: xatom) - m_allAtoms); |
| 279 | } |
| 280 | |