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

source code of kwindowsystem/src/kkeyserver.h