| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2001 Ellis Whitehead <ellis@kde.org> |
| 3 | |
| 4 | Win32 port: |
| 5 | SPDX-FileCopyrightText: 2004 Jarosław Staniek <staniek@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 8 | */ |
| 9 | |
| 10 | #ifndef _KKEYSERVER_H |
| 11 | #define _KKEYSERVER_H |
| 12 | |
| 13 | #include <kwindowsystem_export.h> |
| 14 | |
| 15 | #include <X11/Xlib.h> |
| 16 | #include <fixx11h.h> |
| 17 | #include <qglobal.h> |
| 18 | #include <xcb/xcb.h> |
| 19 | |
| 20 | class QString; |
| 21 | |
| 22 | /*! |
| 23 | * \namespace KKeyServer |
| 24 | * \inmodule KWindowSystem |
| 25 | * |
| 26 | * \brief A collection of functions for the conversion of key presses and |
| 27 | * their modifiers from the window system specific format |
| 28 | * to the generic format and vice-versa. |
| 29 | */ |
| 30 | namespace KKeyServer |
| 31 | { |
| 32 | /*! |
| 33 | * Converts the mask of ORed KKey::ModFlag modifiers to a |
| 34 | * user-readable string. |
| 35 | * |
| 36 | * \a mod the mask of ORed KKey::ModFlag modifiers |
| 37 | * |
| 38 | * Returns the user-readable string (in English) |
| 39 | */ |
| 40 | KWINDOWSYSTEM_EXPORT QString modToStringUser(uint mod); |
| 41 | |
| 42 | /*! |
| 43 | * Converts the modifier given as user-readable string (in English) |
| 44 | * to KKey::ModFlag modifier, or 0. |
| 45 | * \internal |
| 46 | */ |
| 47 | KWINDOWSYSTEM_EXPORT uint stringUserToMod(const QString &mod); |
| 48 | |
| 49 | /*! |
| 50 | * Test if the shift modifier should be recorded for a given key. |
| 51 | * |
| 52 | * For example, if shift+5 produces '%' Qt wants ctrl+shift+5 recorded as ctrl+% and |
| 53 | * in that case this function would return false. |
| 54 | * |
| 55 | * \since 4.7.1 |
| 56 | */ |
| 57 | KWINDOWSYSTEM_EXPORT bool isShiftAsModifierAllowed(int keyQt); |
| 58 | |
| 59 | static const int MODE_SWITCH = 0x2000; |
| 60 | |
| 61 | /*! |
| 62 | * Initialises the values to return for the mod*() functions below. |
| 63 | * Called automatically by those functions if not already initialized. |
| 64 | */ |
| 65 | KWINDOWSYSTEM_EXPORT bool initializeMods(); |
| 66 | |
| 67 | /*! |
| 68 | * Returns true if the current keyboard layout supports the Meta key. |
| 69 | * Specifically, whether the Super or Meta keys are assigned to an X modifier. |
| 70 | * Returns true if the keyboard has a Meta key |
| 71 | * \sa modXMeta() |
| 72 | */ |
| 73 | KWINDOWSYSTEM_EXPORT bool keyboardHasMetaKey(); |
| 74 | |
| 75 | /*! |
| 76 | * Returns the X11 Shift modifier mask/flag. |
| 77 | * \sa accelModMaskX() |
| 78 | */ |
| 79 | KWINDOWSYSTEM_EXPORT uint modXShift(); |
| 80 | |
| 81 | /*! |
| 82 | * Returns the X11 Lock modifier mask/flag. |
| 83 | * \sa accelModMaskX() |
| 84 | */ |
| 85 | KWINDOWSYSTEM_EXPORT uint modXLock(); |
| 86 | |
| 87 | /*! |
| 88 | * Returns the X11 Ctrl modifier mask/flag. |
| 89 | * \sa accelModMaskX() |
| 90 | */ |
| 91 | KWINDOWSYSTEM_EXPORT uint modXCtrl(); |
| 92 | |
| 93 | /*! |
| 94 | * Returns the X11 Alt (Mod1) modifier mask/flag. |
| 95 | * \sa accelModMaskX() |
| 96 | */ |
| 97 | KWINDOWSYSTEM_EXPORT uint modXAlt(); |
| 98 | |
| 99 | /*! |
| 100 | * Returns the X11 Win (Mod3) modifier mask/flag. |
| 101 | * \sa keyboardHasWinKey() |
| 102 | * \sa accelModMaskX() |
| 103 | */ |
| 104 | KWINDOWSYSTEM_EXPORT uint modXMeta(); |
| 105 | |
| 106 | /*! |
| 107 | * Returns the X11 NumLock modifier mask/flag. |
| 108 | * \sa accelModMaskX() |
| 109 | */ |
| 110 | KWINDOWSYSTEM_EXPORT uint modXNumLock(); |
| 111 | |
| 112 | /*! |
| 113 | * Returns the X11 ScrollLock modifier mask/flag. |
| 114 | * \sa accelModMaskX() |
| 115 | */ |
| 116 | KWINDOWSYSTEM_EXPORT uint modXScrollLock(); |
| 117 | |
| 118 | /*! |
| 119 | * Returns the X11 Mode_switch modifier mask/flag. |
| 120 | * \sa accelModMaskX() |
| 121 | */ |
| 122 | KWINDOWSYSTEM_EXPORT uint modXModeSwitch(); |
| 123 | |
| 124 | /*! |
| 125 | * Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and |
| 126 | * Win (if available). |
| 127 | * \sa modXShift() |
| 128 | * \sa modXLock() |
| 129 | * \sa modXCtrl() |
| 130 | * \sa modXAlt() |
| 131 | * \sa modXNumLock() |
| 132 | * \sa modXWin() |
| 133 | * \sa modXScrollLock() |
| 134 | */ |
| 135 | KWINDOWSYSTEM_EXPORT uint accelModMaskX(); |
| 136 | |
| 137 | #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0) |
| 138 | /*! |
| 139 | * Extracts the symbol from the given Qt key and |
| 140 | * converts it to an X11 symbol + modifiers. |
| 141 | * |
| 142 | * \a keyQt the qt key code |
| 143 | * |
| 144 | * \a sym if successful, the symbol will be written here |
| 145 | * |
| 146 | * Returns true if successful, false otherwise |
| 147 | * |
| 148 | * \deprecated[6.0] |
| 149 | * |
| 150 | * Use keyQtToSymXs(keyQt) |
| 151 | */ |
| 152 | KWINDOWSYSTEM_EXPORT |
| 153 | KWINDOWSYSTEM_DEPRECATED_VERSION(6, 0, "Use keyQtToSymXs(int keyQt)" ) |
| 154 | bool keyQtToSymX(int keyQt, int *sym); |
| 155 | #endif |
| 156 | |
| 157 | /*! |
| 158 | * Extracts the symbols from the given Qt key and |
| 159 | * converts it to an X11 symbol + modifiers. |
| 160 | * |
| 161 | * \a keyQt the qt key code |
| 162 | * |
| 163 | * Returns the symbols; emtpy if unsuccessful |
| 164 | */ |
| 165 | KWINDOWSYSTEM_EXPORT QList<int> keyQtToSymXs(int keyQt); |
| 166 | |
| 167 | #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0) |
| 168 | /*! |
| 169 | * Extracts the code from the given Qt key. |
| 170 | * |
| 171 | * \a keyQt the qt key code |
| 172 | * |
| 173 | * \a keyCode if successful, the symbol will be written here |
| 174 | * |
| 175 | * Returns true if successful, false otherwise |
| 176 | * |
| 177 | * \deprecated[6.0] Use keyQtToCodeXs(keyQt) |
| 178 | */ |
| 179 | KWINDOWSYSTEM_EXPORT |
| 180 | KWINDOWSYSTEM_DEPRECATED_VERSION(6, 0, "Use keyQtToCodeXs(int keyQt)" ) |
| 181 | bool keyQtToCodeX(int keyQt, int *keyCode); |
| 182 | #endif |
| 183 | |
| 184 | /*! |
| 185 | * Extracts the codes from the given Qt key. |
| 186 | * |
| 187 | * \a keyQt the qt key code |
| 188 | * |
| 189 | * \a return the codes; empty if unsuccessful |
| 190 | */ |
| 191 | KWINDOWSYSTEM_EXPORT QList<int> keyQtToCodeXs(int keyQt); |
| 192 | |
| 193 | /*! |
| 194 | * Extracts the modifiers from the given Qt key and |
| 195 | * converts them in a mask of X11 modifiers. |
| 196 | * |
| 197 | * \a keyQt the qt key code |
| 198 | * |
| 199 | * \a mod if successful, the modifiers will be written here |
| 200 | * |
| 201 | * Returns true if successful, false otherwise |
| 202 | */ |
| 203 | KWINDOWSYSTEM_EXPORT bool keyQtToModX(int keyQt, uint *mod); |
| 204 | |
| 205 | /*! |
| 206 | * Converts the given symbol and modifier combination to a Qt key code. |
| 207 | * |
| 208 | * \a keySym the X key symbol |
| 209 | * |
| 210 | * \a modX the mask of X11 modifiers |
| 211 | * |
| 212 | * \a keyQt if successful, the qt key code will be written here |
| 213 | * |
| 214 | * Returns true if successful, false otherwise |
| 215 | */ |
| 216 | KWINDOWSYSTEM_EXPORT bool symXModXToKeyQt(uint32_t keySym, uint16_t modX, int *keyQt); |
| 217 | |
| 218 | /*! |
| 219 | * Converts the mask of ORed X11 modifiers to |
| 220 | * a mask of ORed Qt key code modifiers. |
| 221 | * |
| 222 | * \a modX the mask of X11 modifiers |
| 223 | * |
| 224 | * \a modQt the mask of Qt key code modifiers will be written here |
| 225 | * if successful |
| 226 | * |
| 227 | * Returns true if successful, false otherwise |
| 228 | */ |
| 229 | KWINDOWSYSTEM_EXPORT bool modXToQt(uint modX, int *modQt); |
| 230 | |
| 231 | /*! |
| 232 | * Converts an X keypress event into a Qt key + modifier code |
| 233 | * |
| 234 | * \a e the X11 keypress event |
| 235 | * |
| 236 | * \a keyModQt the Qt keycode and mask of Qt key code modifiers will be written here |
| 237 | * if successful |
| 238 | * |
| 239 | * Returns true if successful, false otherwise |
| 240 | */ |
| 241 | KWINDOWSYSTEM_EXPORT bool xEventToQt(XEvent *e, int *keyModQt); |
| 242 | |
| 243 | /*! |
| 244 | * Converts an XCB keypress event into a Qt key + modifier code |
| 245 | * |
| 246 | * \a e the XCB keypress event |
| 247 | * |
| 248 | * \a keyModQt the Qt keycode and mask of Qt key code modifiers will be written here |
| 249 | * if successful |
| 250 | * |
| 251 | * Returns true if successful, false otherwise |
| 252 | */ |
| 253 | KWINDOWSYSTEM_EXPORT bool xcbKeyPressEventToQt(xcb_generic_event_t *e, int *keyModQt); |
| 254 | /*! |
| 255 | * Overloaded method for convenience. |
| 256 | */ |
| 257 | KWINDOWSYSTEM_EXPORT bool xcbKeyPressEventToQt(xcb_key_press_event_t *e, int *keyModQt); |
| 258 | |
| 259 | }; // namespace KKeyServer |
| 260 | |
| 261 | #endif // !_KKEYSERVER_H |
| 262 | |