KWindowSystem

kkeyserver.cpp
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#include "kkeyserver.h"
11
12#include "kwindowsystem_xcb_debug.h"
13
14#include <private/qtx11extras_p.h>
15
16#define XK_MISCELLANY
17#define XK_XKB_KEYS
18#include <X11/X.h>
19#include <X11/Xlib.h>
20#include <X11/Xutil.h>
21#include <X11/keysymdef.h>
22#include <xcb/xcb_keysyms.h>
23#define X11_ONLY(arg) arg, // allows to omit an argument
24
25#include <QCoreApplication>
26
27namespace KKeyServer
28{
29//---------------------------------------------------------------------
30// Array Structures
31//---------------------------------------------------------------------
32
33struct ModInfo {
34 int modQt;
35 const char *psName;
36 QString *sLabel; // this struct is used in static objects, so must use a pointer here.
37};
38
39//---------------------------------------------------------------------
40// Arrays
41//---------------------------------------------------------------------
42
43// Key names with this context are extracted elsewhere,
44// no need for I18N_NOOP2's here.
45#define KEYCTXT "keyboard-key-name"
46static ModInfo g_rgModInfo[4] = {
47 {Qt::SHIFT, "Shift", nullptr},
48 {Qt::CTRL, "Ctrl", nullptr},
49 {Qt::ALT, "Alt", nullptr},
50 {Qt::META, "Meta", nullptr},
51};
52
53//---------------------------------------------------------------------
54// Initialization
55//---------------------------------------------------------------------
56static bool g_bInitializedKKeyLabels;
57static bool g_bMacLabels;
58
59static void intializeKKeyLabels()
60{
61 g_rgModInfo[0].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[0].psName), KEYCTXT));
62 g_rgModInfo[1].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[1].psName), KEYCTXT));
63 g_rgModInfo[2].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[2].psName), KEYCTXT));
64 g_rgModInfo[3].sLabel = new QString(QCoreApplication::translate("KKeyServer", (g_rgModInfo[3].psName), KEYCTXT));
65 g_bMacLabels = (*g_rgModInfo[2].sLabel == QLatin1String("Command"));
66 g_bInitializedKKeyLabels = true;
67}
68
69//---------------------------------------------------------------------
70// Public functions
71//---------------------------------------------------------------------
72
73static QString modToString(uint mod, bool bUserSpace)
74{
75 if (bUserSpace && !g_bInitializedKKeyLabels) {
76 intializeKKeyLabels();
77 }
78
79 QString s;
80 for (int i = 3; i >= 0; i--) {
81 if (mod & g_rgModInfo[i].modQt) {
82 if (!s.isEmpty()) {
83 s += QLatin1Char('+');
84 }
85 s += (bUserSpace) ? *g_rgModInfo[i].sLabel : QLatin1String(g_rgModInfo[i].psName);
86 }
87 }
88 return s;
89}
90
92{
93 return modToString(mod, true);
94}
95
96uint stringUserToMod(const QString &mod)
97{
98 for (int i = 3; i >= 0; i--) {
99 if (mod.toLower() == g_rgModInfo[i].sLabel->toLower()) {
100 return g_rgModInfo[i].modQt;
101 }
102 }
103 return 0;
104}
105
107{
108 // remove any modifiers
109 keyQt &= ~Qt::KeyboardModifierMask;
110
111 // Shift only works as a modifier with certain keys. It's not possible
112 // to enter the SHIFT+5 key sequence for me because this is handled as
113 // '%' by qt on my keyboard.
114 // The working keys are all hardcoded here :-(
115 if (keyQt >= Qt::Key_F1 && keyQt <= Qt::Key_F35) {
116 return true;
117 }
118
119 // Returns false if not a unicode code point
120 if (QChar::isLetter(keyQt)) {
121 return true;
122 }
123
124 switch (keyQt) {
125 case Qt::Key_Return:
126 case Qt::Key_Space:
128 case Qt::Key_Tab:
129 case Qt::Key_Backtab:
130 case Qt::Key_Escape:
131 case Qt::Key_Print:
133 case Qt::Key_Pause:
134 case Qt::Key_PageUp:
135 case Qt::Key_PageDown:
136 case Qt::Key_Insert:
137 case Qt::Key_Delete:
138 case Qt::Key_Home:
139 case Qt::Key_End:
140 case Qt::Key_Up:
141 case Qt::Key_Down:
142 case Qt::Key_Left:
143 case Qt::Key_Right:
144 case Qt::Key_Enter:
145 case Qt::Key_SysReq:
146 case Qt::Key_CapsLock:
147 case Qt::Key_NumLock:
148 case Qt::Key_Help:
149 case Qt::Key_Back:
150 case Qt::Key_Forward:
151 case Qt::Key_Stop:
152 case Qt::Key_Refresh:
155 case Qt::Key_OpenUrl:
156 case Qt::Key_HomePage:
157 case Qt::Key_Search:
160 case Qt::Key_VolumeUp:
162 case Qt::Key_BassUp:
163 case Qt::Key_BassDown:
164 case Qt::Key_TrebleUp:
175 case Qt::Key_Memo:
176 case Qt::Key_ToDoList:
177 case Qt::Key_Calendar:
180 case Qt::Key_Standby:
186 case Qt::Key_PowerOff:
187 case Qt::Key_WakeUp:
188 case Qt::Key_Eject:
190 case Qt::Key_WWW:
191 case Qt::Key_Sleep:
193 case Qt::Key_Shop:
194 case Qt::Key_History:
196 case Qt::Key_HotLinks:
198 case Qt::Key_Finance:
204 case Qt::Key_Book:
205 case Qt::Key_CD:
206 case Qt::Key_Clear:
208 case Qt::Key_Close:
209 case Qt::Key_Copy:
210 case Qt::Key_Cut:
211 case Qt::Key_Display:
212 case Qt::Key_DOS:
214 case Qt::Key_Excel:
215 case Qt::Key_Explorer:
216 case Qt::Key_Game:
217 case Qt::Key_Go:
218 case Qt::Key_iTouch:
219 case Qt::Key_LogOff:
220 case Qt::Key_Market:
221 case Qt::Key_Meeting:
222 case Qt::Key_MenuKB:
223 case Qt::Key_MenuPB:
224 case Qt::Key_MySites:
225 case Qt::Key_News:
227 case Qt::Key_Option:
228 case Qt::Key_Paste:
229 case Qt::Key_Phone:
230 case Qt::Key_Reply:
231 case Qt::Key_Reload:
235 case Qt::Key_Save:
236 case Qt::Key_Send:
237 case Qt::Key_Spell:
239 case Qt::Key_Support:
240 case Qt::Key_TaskPane:
241 case Qt::Key_Terminal:
242 case Qt::Key_Tools:
243 case Qt::Key_Travel:
244 case Qt::Key_Video:
245 case Qt::Key_Word:
246 case Qt::Key_Xfer:
247 case Qt::Key_ZoomIn:
248 case Qt::Key_ZoomOut:
249 case Qt::Key_Away:
251 case Qt::Key_WebCam:
253 case Qt::Key_Pictures:
254 case Qt::Key_Music:
255 case Qt::Key_Battery:
257 case Qt::Key_WLAN:
258 case Qt::Key_UWB:
262 case Qt::Key_Subtitle:
264 case Qt::Key_Time:
265 case Qt::Key_Select:
266 case Qt::Key_View:
267 case Qt::Key_TopMenu:
268 case Qt::Key_Suspend:
270 case Qt::Key_Launch0:
271 case Qt::Key_Launch1:
272 case Qt::Key_Launch2:
273 case Qt::Key_Launch3:
274 case Qt::Key_Launch4:
275 case Qt::Key_Launch5:
276 case Qt::Key_Launch6:
277 case Qt::Key_Launch7:
278 case Qt::Key_Launch8:
279 case Qt::Key_Launch9:
280 case Qt::Key_LaunchA:
281 case Qt::Key_LaunchB:
282 case Qt::Key_LaunchC:
283 case Qt::Key_LaunchD:
284 case Qt::Key_LaunchE:
285 case Qt::Key_LaunchF:
286 return true;
287
288 default:
289 return false;
290 }
291}
292
293// #define KKEYSERVER_DEBUG 1
294
295//---------------------------------------------------------------------
296// Data Structures
297//---------------------------------------------------------------------
298
299struct Mod {
300 int m_mod;
301};
302
303//---------------------------------------------------------------------
304// Array Structures
305//---------------------------------------------------------------------
306
307struct X11ModInfo {
308 int modQt;
309 int modX;
310};
311
312struct SymVariation {
313 uint sym, symVariation;
314 bool bActive;
315};
316
317struct SymName {
318 uint sym;
319 const char *psName;
320};
321
322struct TransKey {
323 int keySymQt;
324 uint keySymX;
325};
326
327//---------------------------------------------------------------------
328// Arrays
329//---------------------------------------------------------------------
330// clang-format off
331
332static X11ModInfo g_rgX11ModInfo[4] = {
333 { Qt::SHIFT, X11_ONLY(ShiftMask) },
334 { Qt::CTRL, X11_ONLY(ControlMask) },
335 { Qt::ALT, X11_ONLY(Mod1Mask) },
336 { Qt::META, X11_ONLY(Mod4Mask) }
337};
338
339// These are the X equivalents to the Qt keycodes 0x1000 - 0x1026
340static const TransKey g_rgQtToSymX[] = {
341 { Qt::Key_Escape, XK_Escape },
342 { Qt::Key_Tab, XK_Tab },
343 { Qt::Key_Backtab, XK_ISO_Left_Tab },
344 { Qt::Key_Backspace, XK_BackSpace },
345 { Qt::Key_Return, XK_Return },
346 { Qt::Key_Insert, XK_Insert },
347 { Qt::Key_Delete, XK_Delete },
348 { Qt::Key_Pause, XK_Pause },
349#ifdef sun
350 { Qt::Key_Print, XK_F22 },
351#else
352 { Qt::Key_Print, XK_Print },
353#endif
354 { Qt::Key_SysReq, XK_Sys_Req },
355 { Qt::Key_Home, XK_Home },
356 { Qt::Key_End, XK_End },
357 { Qt::Key_Left, XK_Left },
358 { Qt::Key_Up, XK_Up },
359 { Qt::Key_Right, XK_Right },
360 { Qt::Key_Down, XK_Down },
361 { Qt::Key_PageUp, XK_Prior },
362 { Qt::Key_PageDown, XK_Next },
363 { Qt::Key_Shift, XK_Shift_L },
364 { Qt::Key_Shift, XK_Shift_R },
365 { Qt::Key_Shift, XK_Shift_Lock },
366 { Qt::Key_Control, XK_Control_L },
367 { Qt::Key_Control, XK_Control_R },
368 { Qt::Key_Meta, XK_Meta_L },
369 { Qt::Key_Meta, XK_Meta_R },
370 { Qt::Key_Alt, XK_Alt_L },
371 { Qt::Key_Alt, XK_Alt_R },
372 { Qt::Key_CapsLock, XK_Caps_Lock },
373 { Qt::Key_NumLock, XK_Num_Lock },
374 { Qt::Key_ScrollLock, XK_Scroll_Lock },
375 { Qt::Key_F1, XK_F1 },
376 { Qt::Key_F2, XK_F2 },
377 { Qt::Key_F3, XK_F3 },
378 { Qt::Key_F4, XK_F4 },
379 { Qt::Key_F5, XK_F5 },
380 { Qt::Key_F6, XK_F6 },
381 { Qt::Key_F7, XK_F7 },
382 { Qt::Key_F8, XK_F8 },
383 { Qt::Key_F9, XK_F9 },
384 { Qt::Key_F10, XK_F10 },
385 { Qt::Key_F11, XK_F11 },
386 { Qt::Key_F12, XK_F12 },
387 { Qt::Key_F13, XK_F13 },
388 { Qt::Key_F14, XK_F14 },
389 { Qt::Key_F15, XK_F15 },
390 { Qt::Key_F16, XK_F16 },
391 { Qt::Key_F17, XK_F17 },
392 { Qt::Key_F18, XK_F18 },
393 { Qt::Key_F19, XK_F19 },
394 { Qt::Key_F20, XK_F20 },
395 { Qt::Key_F21, XK_F21 },
396 { Qt::Key_F22, XK_F22 },
397 { Qt::Key_F23, XK_F23 },
398 { Qt::Key_F24, XK_F24 },
399 { Qt::Key_F25, XK_F25 },
400 { Qt::Key_F26, XK_F26 },
401 { Qt::Key_F27, XK_F27 },
402 { Qt::Key_F28, XK_F28 },
403 { Qt::Key_F29, XK_F29 },
404 { Qt::Key_F30, XK_F30 },
405 { Qt::Key_F31, XK_F31 },
406 { Qt::Key_F32, XK_F32 },
407 { Qt::Key_F33, XK_F33 },
408 { Qt::Key_F34, XK_F34 },
409 { Qt::Key_F35, XK_F35 },
410 { Qt::Key_Super_L, XK_Super_L },
411 { Qt::Key_Super_R, XK_Super_R },
412 { Qt::Key_Menu, XK_Menu },
413 { Qt::Key_Hyper_L, XK_Hyper_L },
414 { Qt::Key_Hyper_R, XK_Hyper_R },
415 { Qt::Key_Help, XK_Help },
416 //{ Qt::Key_Direction_L, XK_Direction_L }, These keys don't exist in X11
417 //{ Qt::Key_Direction_R, XK_Direction_R },
418
419 { Qt::Key_Space, XK_KP_Space },
420 { Qt::Key_Tab, XK_KP_Tab },
421 { Qt::Key_Enter, XK_KP_Enter },
422 { Qt::Key_Home, XK_KP_Home },
423 { Qt::Key_Left, XK_KP_Left },
424 { Qt::Key_Up, XK_KP_Up },
425 { Qt::Key_Right, XK_KP_Right },
426 { Qt::Key_Down, XK_KP_Down },
427 { Qt::Key_PageUp, XK_KP_Prior },
428 { Qt::Key_PageDown, XK_KP_Next },
429 { Qt::Key_End, XK_KP_End },
430 { Qt::Key_Clear, XK_KP_Begin },
431 { Qt::Key_Insert, XK_KP_Insert },
432 { Qt::Key_Delete, XK_KP_Delete },
433 { Qt::Key_Equal, XK_KP_Equal },
434 { Qt::Key_Asterisk, XK_KP_Multiply },
435 { Qt::Key_Plus, XK_KP_Add },
436 { Qt::Key_Comma, XK_KP_Separator },
437 { Qt::Key_Minus, XK_KP_Subtract },
438 { Qt::Key_Period, XK_KP_Decimal },
439 { Qt::Key_Slash, XK_KP_Divide },
440
441// the next lines are taken on 01/2024 from X.org (X11/XF86keysym.h), defining some special
442// multimedia keys. They are included here as not every system has them.
443#define XF86XK_ModeLock 0x1008ff01 /* Mode Switch Lock */
444
445/* Backlight controls. */
446#define XF86XK_MonBrightnessUp 0x1008ff02 /* Monitor/panel brightness */
447#define XF86XK_MonBrightnessDown 0x1008ff03 /* Monitor/panel brightness */
448#define XF86XK_KbdLightOnOff 0x1008ff04 /* Keyboards may be lit */
449#define XF86XK_KbdBrightnessUp 0x1008ff05 /* Keyboards may be lit */
450#define XF86XK_KbdBrightnessDown 0x1008ff06 /* Keyboards may be lit */
451#define XF86XK_MonBrightnessCycle 0x1008ff07 /* Monitor/panel brightness */
452
453/*
454 * Keys found on some "Internet" keyboards.
455 */
456#define XF86XK_Standby 0x1008ff10 /* System into standby mode */
457#define XF86XK_AudioLowerVolume 0x1008ff11 /* Volume control down */
458#define XF86XK_AudioMute 0x1008ff12 /* Mute sound from the system */
459#define XF86XK_AudioRaiseVolume 0x1008ff13 /* Volume control up */
460#define XF86XK_AudioPlay 0x1008ff14 /* Start playing of audio > */
461#define XF86XK_AudioStop 0x1008ff15 /* Stop playing audio */
462#define XF86XK_AudioPrev 0x1008ff16 /* Previous track */
463#define XF86XK_AudioNext 0x1008ff17 /* Next track */
464#define XF86XK_HomePage 0x1008ff18 /* Display user's home page */
465#define XF86XK_Mail 0x1008ff19 /* Invoke user's mail program */
466#define XF86XK_Start 0x1008ff1a /* Start application */
467#define XF86XK_Search 0x1008ff1b /* Search */
468#define XF86XK_AudioRecord 0x1008ff1c /* Record audio application */
469
470/* These are sometimes found on PDA's (e.g. Palm, PocketPC or elsewhere) */
471#define XF86XK_Calculator 0x1008ff1d /* Invoke calculator program */
472#define XF86XK_Memo 0x1008ff1e /* Invoke Memo taking program */
473#define XF86XK_ToDoList 0x1008ff1f /* Invoke To Do List program */
474#define XF86XK_Calendar 0x1008ff20 /* Invoke Calendar program */
475#define XF86XK_PowerDown 0x1008ff21 /* Deep sleep the system */
476#define XF86XK_ContrastAdjust 0x1008ff22 /* Adjust screen contrast */
477#define XF86XK_RockerUp 0x1008ff23 /* Rocker switches exist up */
478#define XF86XK_RockerDown 0x1008ff24 /* and down */
479#define XF86XK_RockerEnter 0x1008ff25 /* and let you press them */
480
481/* Some more "Internet" keyboard symbols */
482#define XF86XK_Back 0x1008ff26 /* Like back on a browser */
483#define XF86XK_Forward 0x1008ff27 /* Like forward on a browser */
484#define XF86XK_Stop 0x1008ff28 /* Stop current operation */
485#define XF86XK_Refresh 0x1008ff29 /* Refresh the page */
486#define XF86XK_PowerOff 0x1008ff2a /* Power off system entirely */
487#define XF86XK_WakeUp 0x1008ff2b /* Wake up system from sleep */
488#define XF86XK_Eject 0x1008ff2c /* Eject device (e.g. DVD) */
489#define XF86XK_ScreenSaver 0x1008ff2d /* Invoke screensaver */
490#define XF86XK_WWW 0x1008ff2e /* Invoke web browser */
491#define XF86XK_Sleep 0x1008ff2f /* Put system to sleep */
492#define XF86XK_Favorites 0x1008ff30 /* Show favorite locations */
493#define XF86XK_AudioPause 0x1008ff31 /* Pause audio playing */
494#define XF86XK_AudioMedia 0x1008ff32 /* Launch media collection app */
495#define XF86XK_MyComputer 0x1008ff33 /* Display "My Computer" window */
496#define XF86XK_VendorHome 0x1008ff34 /* Display vendor home web site */
497#define XF86XK_LightBulb 0x1008ff35 /* Light bulb keys exist */
498#define XF86XK_Shop 0x1008ff36 /* Display shopping web site */
499#define XF86XK_History 0x1008ff37 /* Show history of web surfing */
500#define XF86XK_OpenURL 0x1008ff38 /* Open selected URL */
501#define XF86XK_AddFavorite 0x1008ff39 /* Add URL to favorites list */
502#define XF86XK_HotLinks 0x1008ff3a /* Show "hot" links */
503#define XF86XK_BrightnessAdjust 0x1008ff3b /* Invoke brightness adj. UI */
504#define XF86XK_Finance 0x1008ff3c /* Display financial site */
505#define XF86XK_Community 0x1008ff3d /* Display user's community */
506#define XF86XK_AudioRewind 0x1008ff3e /* "rewind" audio track */
507#define XF86XK_BackForward 0x1008ff3f /* ??? */
508#define XF86XK_Launch0 0x1008ff40 /* Launch Application */
509#define XF86XK_Launch1 0x1008ff41 /* Launch Application */
510#define XF86XK_Launch2 0x1008ff42 /* Launch Application */
511#define XF86XK_Launch3 0x1008ff43 /* Launch Application */
512#define XF86XK_Launch4 0x1008ff44 /* Launch Application */
513#define XF86XK_Launch5 0x1008ff45 /* Launch Application */
514#define XF86XK_Launch6 0x1008ff46 /* Launch Application */
515#define XF86XK_Launch7 0x1008ff47 /* Launch Application */
516#define XF86XK_Launch8 0x1008ff48 /* Launch Application */
517#define XF86XK_Launch9 0x1008ff49 /* Launch Application */
518#define XF86XK_LaunchA 0x1008ff4a /* Launch Application */
519#define XF86XK_LaunchB 0x1008ff4b /* Launch Application */
520#define XF86XK_LaunchC 0x1008ff4c /* Launch Application */
521#define XF86XK_LaunchD 0x1008ff4d /* Launch Application */
522#define XF86XK_LaunchE 0x1008ff4e /* Launch Application */
523#define XF86XK_LaunchF 0x1008ff4f /* Launch Application */
524
525#define XF86XK_ApplicationLeft 0x1008ff50 /* switch to application, left */
526#define XF86XK_ApplicationRight 0x1008ff51 /* switch to application, right*/
527#define XF86XK_Book 0x1008ff52 /* Launch bookreader */
528#define XF86XK_CD 0x1008ff53 /* Launch CD/DVD player */
529#define XF86XK_Calculater 0x1008ff54 /* Launch Calculater */
530#define XF86XK_Clear 0x1008ff55 /* Clear window, screen */
531#define XF86XK_Close 0x1008ff56 /* Close window */
532#define XF86XK_Copy 0x1008ff57 /* Copy selection */
533#define XF86XK_Cut 0x1008ff58 /* Cut selection */
534#define XF86XK_Display 0x1008ff59 /* Output switch key */
535#define XF86XK_DOS 0x1008ff5a /* Launch DOS (emulation) */
536#define XF86XK_Documents 0x1008ff5b /* Open documents window */
537#define XF86XK_Excel 0x1008ff5c /* Launch spread sheet */
538#define XF86XK_Explorer 0x1008ff5d /* Launch file explorer */
539#define XF86XK_Game 0x1008ff5e /* Launch game */
540#define XF86XK_Go 0x1008ff5f /* Go to URL */
541#define XF86XK_iTouch 0x1008ff60 /* Logitech iTouch- don't use */
542#define XF86XK_LogOff 0x1008ff61 /* Log off system */
543#define XF86XK_Market 0x1008ff62 /* ?? */
544#define XF86XK_Meeting 0x1008ff63 /* enter meeting in calendar */
545#define XF86XK_MenuKB 0x1008ff65 /* distinguish keyboard from PB */
546#define XF86XK_MenuPB 0x1008ff66 /* distinguish PB from keyboard */
547#define XF86XK_MySites 0x1008ff67 /* Favourites */
548#define XF86XK_New 0x1008ff68 /* New (folder, document... */
549#define XF86XK_News 0x1008ff69 /* News */
550#define XF86XK_OfficeHome 0x1008ff6a /* Office home (old Staroffice)*/
551#define XF86XK_Open 0x1008ff6b /* Open */
552#define XF86XK_Option 0x1008ff6c /* ?? */
553#define XF86XK_Paste 0x1008ff6d /* Paste */
554#define XF86XK_Phone 0x1008ff6e /* Launch phone; dial number */
555#define XF86XK_Q 0x1008ff70 /* Compaq's Q - don't use */
556#define XF86XK_Reply 0x1008ff72 /* Reply e.g., mail */
557#define XF86XK_Reload 0x1008ff73 /* Reload web page, file, etc. */
558#define XF86XK_RotateWindows 0x1008ff74 /* Rotate windows e.g. xrandr */
559#define XF86XK_RotationPB 0x1008ff75 /* don't use */
560#define XF86XK_RotationKB 0x1008ff76 /* don't use */
561#define XF86XK_Save 0x1008ff77 /* Save (file, document, state */
562#define XF86XK_ScrollUp 0x1008ff78 /* Scroll window/contents up */
563#define XF86XK_ScrollDown 0x1008ff79 /* Scrool window/contentd down */
564#define XF86XK_ScrollClick 0x1008ff7a /* Use XKB mousekeys instead */
565#define XF86XK_Send 0x1008ff7b /* Send mail, file, object */
566#define XF86XK_Spell 0x1008ff7c /* Spell checker */
567#define XF86XK_SplitScreen 0x1008ff7d /* Split window or screen */
568#define XF86XK_Support 0x1008ff7e /* Get support (??) */
569#define XF86XK_TaskPane 0x1008ff7f /* Show tasks */
570#define XF86XK_Terminal 0x1008ff80 /* Launch terminal emulator */
571#define XF86XK_Tools 0x1008ff81 /* toolbox of desktop/app. */
572#define XF86XK_Travel 0x1008ff82 /* ?? */
573#define XF86XK_UserPB 0x1008ff84 /* ?? */
574#define XF86XK_User1KB 0x1008ff85 /* ?? */
575#define XF86XK_User2KB 0x1008ff86 /* ?? */
576#define XF86XK_Video 0x1008ff87 /* Launch video player */
577#define XF86XK_WheelButton 0x1008ff88 /* button from a mouse wheel */
578#define XF86XK_Word 0x1008ff89 /* Launch word processor */
579#define XF86XK_Xfer 0x1008ff8a
580#define XF86XK_ZoomIn 0x1008ff8b /* zoom in view, map, etc. */
581#define XF86XK_ZoomOut 0x1008ff8c /* zoom out view, map, etc. */
582
583#define XF86XK_Away 0x1008ff8d /* mark yourself as away */
584#define XF86XK_Messenger 0x1008ff8e /* as in instant messaging */
585#define XF86XK_WebCam 0x1008ff8f /* Launch web camera app. */
586#define XF86XK_MailForward 0x1008ff90 /* Forward in mail */
587#define XF86XK_Pictures 0x1008ff91 /* Show pictures */
588#define XF86XK_Music 0x1008ff92 /* Launch music application */
589
590#define XF86XK_Battery 0x1008ff93 /* Display battery information */
591#define XF86XK_Bluetooth 0x1008ff94 /* Enable/disable Bluetooth */
592#define XF86XK_WLAN 0x1008ff95 /* Enable/disable WLAN */
593#define XF86XK_UWB 0x1008ff96 /* Enable/disable UWB */
594
595#define XF86XK_AudioForward 0x1008ff97 /* fast-forward audio track */
596#define XF86XK_AudioRepeat 0x1008ff98 /* toggle repeat mode */
597#define XF86XK_AudioRandomPlay 0x1008ff99 /* toggle shuffle mode */
598#define XF86XK_Subtitle 0x1008ff9a /* cycle through subtitle */
599#define XF86XK_AudioCycleTrack 0x1008ff9b /* cycle through audio tracks */
600#define XF86XK_CycleAngle 0x1008ff9c /* cycle through angles */
601#define XF86XK_FrameBack 0x1008ff9d /* video: go one frame back */
602#define XF86XK_FrameForward 0x1008ff9e /* video: go one frame forward */
603#define XF86XK_Time 0x1008ff9f /* display, or shows an entry for time seeking */
604#define XF86XK_Select 0x1008ffa0 /* Select button on joypads and remotes */
605#define XF86XK_View 0x1008ffa1 /* Show a view options/properties */
606#define XF86XK_TopMenu 0x1008ffa2 /* Go to a top-level menu in a video */
607
608#define XF86XK_Red 0x1008ffa3 /* Red button */
609#define XF86XK_Green 0x1008ffa4 /* Green button */
610#define XF86XK_Yellow 0x1008ffa5 /* Yellow button */
611#define XF86XK_Blue 0x1008ffa6 /* Blue button */
612
613#define XF86XK_Suspend 0x1008ffa7 /* Sleep to RAM */
614#define XF86XK_Hibernate 0x1008ffa8 /* Sleep to disk */
615#define XF86XK_TouchpadToggle 0x1008ffa9 /* Toggle between touchpad/trackstick */
616#define XF86XK_TouchpadOn 0x1008ffb0 /* The touchpad got switched on */
617#define XF86XK_TouchpadOff 0x1008ffb1 /* The touchpad got switched off */
618
619#define XF86XK_AudioMicMute 0x1008ffb2 /* Mute the Mic from the system */
620
621#define XF86XK_Keyboard 0x1008ffb3 /* User defined keyboard related action */
622
623#define XF86XK_WWAN 0x1008ffb4 /* Toggle WWAN (LTE, UMTS, etc.) radio */
624#define XF86XK_RFKill 0x1008ffb5 /* Toggle radios on/off */
625
626#define XF86XK_AudioPreset 0x1008ffb6 /* Select equalizer preset, e.g. theatre-mode */
627
628#define XF86XK_RotationLockToggle 0x1008ffb7 /* Toggle screen rotation lock on/off */
629
630#define XF86XK_FullScreen 0x1008ffb8 /* Toggle fullscreen */
631
632/* Keys for special action keys (hot keys) */
633/* Virtual terminals on some operating systems */
634#define XF86XK_Switch_VT_1 0x1008fe01
635#define XF86XK_Switch_VT_2 0x1008fe02
636#define XF86XK_Switch_VT_3 0x1008fe03
637#define XF86XK_Switch_VT_4 0x1008fe04
638#define XF86XK_Switch_VT_5 0x1008fe05
639#define XF86XK_Switch_VT_6 0x1008fe06
640#define XF86XK_Switch_VT_7 0x1008fe07
641#define XF86XK_Switch_VT_8 0x1008fe08
642#define XF86XK_Switch_VT_9 0x1008fe09
643#define XF86XK_Switch_VT_10 0x1008fe0a
644#define XF86XK_Switch_VT_11 0x1008fe0b
645#define XF86XK_Switch_VT_12 0x1008fe0c
646
647#define XF86XK_Ungrab 0x1008fe20 /* force ungrab */
648#define XF86XK_ClearGrab 0x1008fe21 /* kill application with grab */
649#define XF86XK_Next_VMode 0x1008fe22 /* next video mode available */
650#define XF86XK_Prev_VMode 0x1008fe23 /* prev. video mode available */
651#define XF86XK_LogWindowTree 0x1008fe24 /* print window tree to log */
652#define XF86XK_LogGrabInfo 0x1008fe25 /* print all active grabs to log */
653
654
655/*
656 * Reserved range for evdev symbols: 0x10081000-0x10081FFF
657 *
658 * Key syms within this range must match the Linux kernel
659 * input-event-codes.h file in the format:
660 * XF86XK_CamelCaseKernelName _EVDEVK(kernel value)
661 * For example, the kernel
662 * #define KEY_MACRO_RECORD_START 0x2b0
663 * effectively ends up as:
664 * #define XF86XK_MacroRecordStart 0x100812b0
665 *
666 * For historical reasons, some keysyms within the reserved range will be
667 * missing, most notably all "normal" keys that are mapped through default
668 * XKB layouts (e.g. KEY_Q).
669 *
670 * CamelCasing is done with a human control as last authority, e.g. see VOD
671 * instead of Vod for the Video on Demand key.
672 *
673 * The format for #defines is strict:
674 *
675 * #define XF86XK_FOO<tab...>_EVDEVK(0xABC)<tab><tab> |* kver KEY_FOO *|
676 *
677 * Where
678 * - alignment by tabs
679 * - the _EVDEVK macro must be used
680 * - the hex code must be in uppercase hex
681 * - the kernel version (kver) is in the form v5.10
682 * - kver and key name are within a slash-star comment (a pipe is used in
683 * this example for technical reasons)
684 * These #defines are parsed by scripts. Do not stray from the given format.
685 *
686 * Where the evdev keycode is mapped to a different symbol, please add a
687 * comment line starting with Use: but otherwise the same format, e.g.
688 * Use: XF86XK_RotationLockToggle _EVDEVK(0x231) v4.16 KEY_ROTATE_LOCK_TOGGLE
689 *
690 */
691#define _EVDEVK(_v) (0x10081000 + _v)
692/* Use: XF86XK_Eject _EVDEVK(0x0a2) KEY_EJECTCLOSECD */
693/* Use: XF86XK_New _EVDEVK(0x0b5) v2.6.14 KEY_NEW */
694/* Use: XK_Redo _EVDEVK(0x0b6) v2.6.14 KEY_REDO */
695/* KEY_DASHBOARD has been mapped to LaunchB in xkeyboard-config since 2011 */
696/* Use: XF86XK_LaunchB _EVDEVK(0x0cc) v2.6.28 KEY_DASHBOARD */
697/* Use: XF86XK_Display _EVDEVK(0x0e3) v2.6.12 KEY_SWITCHVIDEOMODE */
698/* Use: XF86XK_KbdLightOnOff _EVDEVK(0x0e4) v2.6.12 KEY_KBDILLUMTOGGLE */
699/* Use: XF86XK_KbdBrightnessDown _EVDEVK(0x0e5) v2.6.12 KEY_KBDILLUMDOWN */
700/* Use: XF86XK_KbdBrightnessUp _EVDEVK(0x0e6) v2.6.12 KEY_KBDILLUMUP */
701/* Use: XF86XK_Send _EVDEVK(0x0e7) v2.6.14 KEY_SEND */
702/* Use: XF86XK_Reply _EVDEVK(0x0e8) v2.6.14 KEY_REPLY */
703/* Use: XF86XK_MailForward _EVDEVK(0x0e9) v2.6.14 KEY_FORWARDMAIL */
704/* Use: XF86XK_Save _EVDEVK(0x0ea) v2.6.14 KEY_SAVE */
705/* Use: XF86XK_Documents _EVDEVK(0x0eb) v2.6.14 KEY_DOCUMENTS */
706/* Use: XF86XK_Battery _EVDEVK(0x0ec) v2.6.17 KEY_BATTERY */
707/* Use: XF86XK_Bluetooth _EVDEVK(0x0ed) v2.6.19 KEY_BLUETOOTH */
708/* Use: XF86XK_WLAN _EVDEVK(0x0ee) v2.6.19 KEY_WLAN */
709/* Use: XF86XK_UWB _EVDEVK(0x0ef) v2.6.24 KEY_UWB */
710/* Use: XF86XK_Next_VMode _EVDEVK(0x0f1) v2.6.23 KEY_VIDEO_NEXT */
711/* Use: XF86XK_Prev_VMode _EVDEVK(0x0f2) v2.6.23 KEY_VIDEO_PREV */
712/* Use: XF86XK_MonBrightnessCycle _EVDEVK(0x0f3) v2.6.23 KEY_BRIGHTNESS_CYCLE */
713#define XF86XK_BrightnessAuto _EVDEVK(0x0f4) /* v3.16 KEY_BRIGHTNESS_AUTO */
714#define XF86XK_DisplayOff _EVDEVK(0x0f5) /* v2.6.23 KEY_DISPLAY_OFF */
715/* Use: XF86XK_WWAN _EVDEVK(0x0f6) v3.13 KEY_WWAN */
716/* Use: XF86XK_RFKill _EVDEVK(0x0f7) v2.6.33 KEY_RFKILL */
717/* Use: XF86XK_AudioMicMute _EVDEVK(0x0f8) v3.1 KEY_MICMUTE */
718#define XF86XK_Info _EVDEVK(0x166) /* KEY_INFO */
719/* Use: XF86XK_CycleAngle _EVDEVK(0x173) KEY_ANGLE */
720/* Use: XF86XK_FullScreen _EVDEVK(0x174) v5.1 KEY_FULL_SCREEN */
721#define XF86XK_AspectRatio _EVDEVK(0x177) /* v5.1 KEY_ASPECT_RATIO */
722#define XF86XK_DVD _EVDEVK(0x185) /* KEY_DVD */
723#define XF86XK_Audio _EVDEVK(0x188) /* KEY_AUDIO */
724/* Use: XF86XK_Video _EVDEVK(0x189) KEY_VIDEO */
725/* Use: XF86XK_Calendar _EVDEVK(0x18d) KEY_CALENDAR */
726#define XF86XK_ChannelUp _EVDEVK(0x192) /* KEY_CHANNELUP */
727#define XF86XK_ChannelDown _EVDEVK(0x193) /* KEY_CHANNELDOWN */
728/* Use: XF86XK_AudioRandomPlay _EVDEVK(0x19a) KEY_SHUFFLE */
729#define XF86XK_Break _EVDEVK(0x19b) /* KEY_BREAK */
730#define XF86XK_VideoPhone _EVDEVK(0x1a0) /* v2.6.20 KEY_VIDEOPHONE */
731/* Use: XF86XK_Game _EVDEVK(0x1a1) v2.6.20 KEY_GAMES */
732/* Use: XF86XK_ZoomIn _EVDEVK(0x1a2) v2.6.20 KEY_ZOOMIN */
733/* Use: XF86XK_ZoomOut _EVDEVK(0x1a3) v2.6.20 KEY_ZOOMOUT */
734#define XF86XK_ZoomReset _EVDEVK(0x1a4) /* v2.6.20 KEY_ZOOMRESET */
735/* Use: XF86XK_Word _EVDEVK(0x1a5) v2.6.20 KEY_WORDPROCESSOR */
736#define XF86XK_Editor _EVDEVK(0x1a6) /* v2.6.20 KEY_EDITOR */
737/* Use: XF86XK_Excel _EVDEVK(0x1a7) v2.6.20 KEY_SPREADSHEET */
738#define XF86XK_GraphicsEditor _EVDEVK(0x1a8) /* v2.6.20 KEY_GRAPHICSEDITOR */
739#define XF86XK_Presentation _EVDEVK(0x1a9) /* v2.6.20 KEY_PRESENTATION */
740#define XF86XK_Database _EVDEVK(0x1aa) /* v2.6.20 KEY_DATABASE */
741/* Use: XF86XK_News _EVDEVK(0x1ab) v2.6.20 KEY_NEWS */
742#define XF86XK_Voicemail _EVDEVK(0x1ac) /* v2.6.20 KEY_VOICEMAIL */
743#define XF86XK_Addressbook _EVDEVK(0x1ad) /* v2.6.20 KEY_ADDRESSBOOK */
744/* Use: XF86XK_Messenger _EVDEVK(0x1ae) v2.6.20 KEY_MESSENGER */
745#define XF86XK_DisplayToggle _EVDEVK(0x1af) /* v2.6.20 KEY_DISPLAYTOGGLE */
746#define XF86XK_SpellCheck _EVDEVK(0x1b0) /* v2.6.24 KEY_SPELLCHECK */
747/* Use: XF86XK_LogOff _EVDEVK(0x1b1) v2.6.24 KEY_LOGOFF */
748/* Use: XK_dollar _EVDEVK(0x1b2) v2.6.24 KEY_DOLLAR */
749/* Use: XK_EuroSign _EVDEVK(0x1b3) v2.6.24 KEY_EURO */
750/* Use: XF86XK_FrameBack _EVDEVK(0x1b4) v2.6.24 KEY_FRAMEBACK */
751/* Use: XF86XK_FrameForward _EVDEVK(0x1b5) v2.6.24 KEY_FRAMEFORWARD */
752#define XF86XK_ContextMenu _EVDEVK(0x1b6) /* v2.6.24 KEY_CONTEXT_MENU */
753#define XF86XK_MediaRepeat _EVDEVK(0x1b7) /* v2.6.26 KEY_MEDIA_REPEAT */
754#define XF86XK_10ChannelsUp _EVDEVK(0x1b8) /* v2.6.38 KEY_10CHANNELSUP */
755#define XF86XK_10ChannelsDown _EVDEVK(0x1b9) /* v2.6.38 KEY_10CHANNELSDOWN */
756#define XF86XK_Images _EVDEVK(0x1ba) /* v2.6.39 KEY_IMAGES */
757#define XF86XK_NotificationCenter _EVDEVK(0x1bc) /* v5.10 KEY_NOTIFICATION_CENTER */
758#define XF86XK_PickupPhone _EVDEVK(0x1bd) /* v5.10 KEY_PICKUP_PHONE */
759#define XF86XK_HangupPhone _EVDEVK(0x1be) /* v5.10 KEY_HANGUP_PHONE */
760#define XF86XK_Fn _EVDEVK(0x1d0) /* KEY_FN */
761#define XF86XK_Fn_Esc _EVDEVK(0x1d1) /* KEY_FN_ESC */
762#define XF86XK_FnRightShift _EVDEVK(0x1e5) /* v5.10 KEY_FN_RIGHT_SHIFT */
763/* Use: XK_braille_dot_1 _EVDEVK(0x1f1) v2.6.17 KEY_BRL_DOT1 */
764/* Use: XK_braille_dot_2 _EVDEVK(0x1f2) v2.6.17 KEY_BRL_DOT2 */
765/* Use: XK_braille_dot_3 _EVDEVK(0x1f3) v2.6.17 KEY_BRL_DOT3 */
766/* Use: XK_braille_dot_4 _EVDEVK(0x1f4) v2.6.17 KEY_BRL_DOT4 */
767/* Use: XK_braille_dot_5 _EVDEVK(0x1f5) v2.6.17 KEY_BRL_DOT5 */
768/* Use: XK_braille_dot_6 _EVDEVK(0x1f6) v2.6.17 KEY_BRL_DOT6 */
769/* Use: XK_braille_dot_7 _EVDEVK(0x1f7) v2.6.17 KEY_BRL_DOT7 */
770/* Use: XK_braille_dot_8 _EVDEVK(0x1f8) v2.6.17 KEY_BRL_DOT8 */
771/* Use: XK_braille_dot_9 _EVDEVK(0x1f9) v2.6.23 KEY_BRL_DOT9 */
772/* Use: XK_braille_dot_1 _EVDEVK(0x1fa) v2.6.23 KEY_BRL_DOT10 */
773#define XF86XK_Numeric0 _EVDEVK(0x200) /* v2.6.28 KEY_NUMERIC_0 */
774#define XF86XK_Numeric1 _EVDEVK(0x201) /* v2.6.28 KEY_NUMERIC_1 */
775#define XF86XK_Numeric2 _EVDEVK(0x202) /* v2.6.28 KEY_NUMERIC_2 */
776#define XF86XK_Numeric3 _EVDEVK(0x203) /* v2.6.28 KEY_NUMERIC_3 */
777#define XF86XK_Numeric4 _EVDEVK(0x204) /* v2.6.28 KEY_NUMERIC_4 */
778#define XF86XK_Numeric5 _EVDEVK(0x205) /* v2.6.28 KEY_NUMERIC_5 */
779#define XF86XK_Numeric6 _EVDEVK(0x206) /* v2.6.28 KEY_NUMERIC_6 */
780#define XF86XK_Numeric7 _EVDEVK(0x207) /* v2.6.28 KEY_NUMERIC_7 */
781#define XF86XK_Numeric8 _EVDEVK(0x208) /* v2.6.28 KEY_NUMERIC_8 */
782#define XF86XK_Numeric9 _EVDEVK(0x209) /* v2.6.28 KEY_NUMERIC_9 */
783#define XF86XK_NumericStar _EVDEVK(0x20a) /* v2.6.28 KEY_NUMERIC_STAR */
784#define XF86XK_NumericPound _EVDEVK(0x20b) /* v2.6.28 KEY_NUMERIC_POUND */
785#define XF86XK_NumericA _EVDEVK(0x20c) /* v4.1 KEY_NUMERIC_A */
786#define XF86XK_NumericB _EVDEVK(0x20d) /* v4.1 KEY_NUMERIC_B */
787#define XF86XK_NumericC _EVDEVK(0x20e) /* v4.1 KEY_NUMERIC_C */
788#define XF86XK_NumericD _EVDEVK(0x20f) /* v4.1 KEY_NUMERIC_D */
789#define XF86XK_CameraFocus _EVDEVK(0x210) /* v2.6.33 KEY_CAMERA_FOCUS */
790#define XF86XK_WPSButton _EVDEVK(0x211) /* v2.6.34 KEY_WPS_BUTTON */
791/* Use: XF86XK_TouchpadToggle _EVDEVK(0x212) v2.6.37 KEY_TOUCHPAD_TOGGLE */
792/* Use: XF86XK_TouchpadOn _EVDEVK(0x213) v2.6.37 KEY_TOUCHPAD_ON */
793/* Use: XF86XK_TouchpadOff _EVDEVK(0x214) v2.6.37 KEY_TOUCHPAD_OFF */
794#define XF86XK_CameraZoomIn _EVDEVK(0x215) /* v2.6.39 KEY_CAMERA_ZOOMIN */
795#define XF86XK_CameraZoomOut _EVDEVK(0x216) /* v2.6.39 KEY_CAMERA_ZOOMOUT */
796#define XF86XK_CameraUp _EVDEVK(0x217) /* v2.6.39 KEY_CAMERA_UP */
797#define XF86XK_CameraDown _EVDEVK(0x218) /* v2.6.39 KEY_CAMERA_DOWN */
798#define XF86XK_CameraLeft _EVDEVK(0x219) /* v2.6.39 KEY_CAMERA_LEFT */
799#define XF86XK_CameraRight _EVDEVK(0x21a) /* v2.6.39 KEY_CAMERA_RIGHT */
800#define XF86XK_AttendantOn _EVDEVK(0x21b) /* v3.10 KEY_ATTENDANT_ON */
801#define XF86XK_AttendantOff _EVDEVK(0x21c) /* v3.10 KEY_ATTENDANT_OFF */
802#define XF86XK_AttendantToggle _EVDEVK(0x21d) /* v3.10 KEY_ATTENDANT_TOGGLE */
803#define XF86XK_LightsToggle _EVDEVK(0x21e) /* v3.10 KEY_LIGHTS_TOGGLE */
804#define XF86XK_ALSToggle _EVDEVK(0x230) /* v3.13 KEY_ALS_TOGGLE */
805/* Use: XF86XK_RotationLockToggle _EVDEVK(0x231) v4.16 KEY_ROTATE_LOCK_TOGGLE */
806#define XF86XK_Buttonconfig _EVDEVK(0x240) /* v3.16 KEY_BUTTONCONFIG */
807#define XF86XK_Taskmanager _EVDEVK(0x241) /* v3.16 KEY_TASKMANAGER */
808#define XF86XK_Journal _EVDEVK(0x242) /* v3.16 KEY_JOURNAL */
809#define XF86XK_ControlPanel _EVDEVK(0x243) /* v3.16 KEY_CONTROLPANEL */
810#define XF86XK_AppSelect _EVDEVK(0x244) /* v3.16 KEY_APPSELECT */
811#define XF86XK_Screensaver _EVDEVK(0x245) /* v3.16 KEY_SCREENSAVER */
812#define XF86XK_VoiceCommand _EVDEVK(0x246) /* v3.16 KEY_VOICECOMMAND */
813#define XF86XK_Assistant _EVDEVK(0x247) /* v4.13 KEY_ASSISTANT */
814/* Use: XK_ISO_Next_Group _EVDEVK(0x248) v5.2 KEY_KBD_LAYOUT_NEXT */
815#define XF86XK_EmojiPicker _EVDEVK(0x249) /* v5.13 KEY_EMOJI_PICKER */
816#define XF86XK_Dictate _EVDEVK(0x24a) /* v5.17 KEY_DICTATE */
817#define XF86XK_CameraAccessEnable _EVDEVK(0x24b) /* v6.2 KEY_CAMERA_ACCESS_ENABLE */
818#define XF86XK_CameraAccessDisable _EVDEVK(0x24c) /* v6.2 KEY_CAMERA_ACCESS_DISABLE */
819#define XF86XK_CameraAccessToggle _EVDEVK(0x24d) /* v6.2 KEY_CAMERA_ACCESS_TOGGLE */
820#define XF86XK_BrightnessMin _EVDEVK(0x250) /* v3.16 KEY_BRIGHTNESS_MIN */
821#define XF86XK_BrightnessMax _EVDEVK(0x251) /* v3.16 KEY_BRIGHTNESS_MAX */
822#define XF86XK_KbdInputAssistPrev _EVDEVK(0x260) /* v3.18 KEY_KBDINPUTASSIST_PREV */
823#define XF86XK_KbdInputAssistNext _EVDEVK(0x261) /* v3.18 KEY_KBDINPUTASSIST_NEXT */
824#define XF86XK_KbdInputAssistPrevgroup _EVDEVK(0x262) /* v3.18 KEY_KBDINPUTASSIST_PREVGROUP */
825#define XF86XK_KbdInputAssistNextgroup _EVDEVK(0x263) /* v3.18 KEY_KBDINPUTASSIST_NEXTGROUP */
826#define XF86XK_KbdInputAssistAccept _EVDEVK(0x264) /* v3.18 KEY_KBDINPUTASSIST_ACCEPT */
827#define XF86XK_KbdInputAssistCancel _EVDEVK(0x265) /* v3.18 KEY_KBDINPUTASSIST_CANCEL */
828#define XF86XK_RightUp _EVDEVK(0x266) /* v4.7 KEY_RIGHT_UP */
829#define XF86XK_RightDown _EVDEVK(0x267) /* v4.7 KEY_RIGHT_DOWN */
830#define XF86XK_LeftUp _EVDEVK(0x268) /* v4.7 KEY_LEFT_UP */
831#define XF86XK_LeftDown _EVDEVK(0x269) /* v4.7 KEY_LEFT_DOWN */
832#define XF86XK_RootMenu _EVDEVK(0x26a) /* v4.7 KEY_ROOT_MENU */
833#define XF86XK_MediaTopMenu _EVDEVK(0x26b) /* v4.7 KEY_MEDIA_TOP_MENU */
834#define XF86XK_Numeric11 _EVDEVK(0x26c) /* v4.7 KEY_NUMERIC_11 */
835#define XF86XK_Numeric12 _EVDEVK(0x26d) /* v4.7 KEY_NUMERIC_12 */
836#define XF86XK_AudioDesc _EVDEVK(0x26e) /* v4.7 KEY_AUDIO_DESC */
837#define XF86XK_3DMode _EVDEVK(0x26f) /* v4.7 KEY_3D_MODE */
838#define XF86XK_NextFavorite _EVDEVK(0x270) /* v4.7 KEY_NEXT_FAVORITE */
839#define XF86XK_StopRecord _EVDEVK(0x271) /* v4.7 KEY_STOP_RECORD */
840#define XF86XK_PauseRecord _EVDEVK(0x272) /* v4.7 KEY_PAUSE_RECORD */
841#define XF86XK_VOD _EVDEVK(0x273) /* v4.7 KEY_VOD */
842#define XF86XK_Unmute _EVDEVK(0x274) /* v4.7 KEY_UNMUTE */
843#define XF86XK_FastReverse _EVDEVK(0x275) /* v4.7 KEY_FASTREVERSE */
844#define XF86XK_SlowReverse _EVDEVK(0x276) /* v4.7 KEY_SLOWREVERSE */
845#define XF86XK_Data _EVDEVK(0x277) /* v4.7 KEY_DATA */
846#define XF86XK_OnScreenKeyboard _EVDEVK(0x278) /* v4.12 KEY_ONSCREEN_KEYBOARD */
847#define XF86XK_PrivacyScreenToggle _EVDEVK(0x279) /* v5.5 KEY_PRIVACY_SCREEN_TOGGLE */
848#define XF86XK_SelectiveScreenshot _EVDEVK(0x27a) /* v5.6 KEY_SELECTIVE_SCREENSHOT */
849#define XF86XK_NextElement _EVDEVK(0x27b) /* v5.18 KEY_NEXT_ELEMENT */
850#define XF86XK_PreviousElement _EVDEVK(0x27c) /* v5.18 KEY_PREVIOUS_ELEMENT */
851#define XF86XK_AutopilotEngageToggle _EVDEVK(0x27d) /* v5.18 KEY_AUTOPILOT_ENGAGE_TOGGLE */
852#define XF86XK_MarkWaypoint _EVDEVK(0x27e) /* v5.18 KEY_MARK_WAYPOINT */
853#define XF86XK_Sos _EVDEVK(0x27f) /* v5.18 KEY_SOS */
854#define XF86XK_NavChart _EVDEVK(0x280) /* v5.18 KEY_NAV_CHART */
855#define XF86XK_FishingChart _EVDEVK(0x281) /* v5.18 KEY_FISHING_CHART */
856#define XF86XK_SingleRangeRadar _EVDEVK(0x282) /* v5.18 KEY_SINGLE_RANGE_RADAR */
857#define XF86XK_DualRangeRadar _EVDEVK(0x283) /* v5.18 KEY_DUAL_RANGE_RADAR */
858#define XF86XK_RadarOverlay _EVDEVK(0x284) /* v5.18 KEY_RADAR_OVERLAY */
859#define XF86XK_TraditionalSonar _EVDEVK(0x285) /* v5.18 KEY_TRADITIONAL_SONAR */
860#define XF86XK_ClearvuSonar _EVDEVK(0x286) /* v5.18 KEY_CLEARVU_SONAR */
861#define XF86XK_SidevuSonar _EVDEVK(0x287) /* v5.18 KEY_SIDEVU_SONAR */
862#define XF86XK_NavInfo _EVDEVK(0x288) /* v5.18 KEY_NAV_INFO */
863/* Use: XF86XK_BrightnessAdjust _EVDEVK(0x289) v5.18 KEY_BRIGHTNESS_MENU */
864#define XF86XK_Macro1 _EVDEVK(0x290) /* v5.5 KEY_MACRO1 */
865#define XF86XK_Macro2 _EVDEVK(0x291) /* v5.5 KEY_MACRO2 */
866#define XF86XK_Macro3 _EVDEVK(0x292) /* v5.5 KEY_MACRO3 */
867#define XF86XK_Macro4 _EVDEVK(0x293) /* v5.5 KEY_MACRO4 */
868#define XF86XK_Macro5 _EVDEVK(0x294) /* v5.5 KEY_MACRO5 */
869#define XF86XK_Macro6 _EVDEVK(0x295) /* v5.5 KEY_MACRO6 */
870#define XF86XK_Macro7 _EVDEVK(0x296) /* v5.5 KEY_MACRO7 */
871#define XF86XK_Macro8 _EVDEVK(0x297) /* v5.5 KEY_MACRO8 */
872#define XF86XK_Macro9 _EVDEVK(0x298) /* v5.5 KEY_MACRO9 */
873#define XF86XK_Macro10 _EVDEVK(0x299) /* v5.5 KEY_MACRO10 */
874#define XF86XK_Macro11 _EVDEVK(0x29a) /* v5.5 KEY_MACRO11 */
875#define XF86XK_Macro12 _EVDEVK(0x29b) /* v5.5 KEY_MACRO12 */
876#define XF86XK_Macro13 _EVDEVK(0x29c) /* v5.5 KEY_MACRO13 */
877#define XF86XK_Macro14 _EVDEVK(0x29d) /* v5.5 KEY_MACRO14 */
878#define XF86XK_Macro15 _EVDEVK(0x29e) /* v5.5 KEY_MACRO15 */
879#define XF86XK_Macro16 _EVDEVK(0x29f) /* v5.5 KEY_MACRO16 */
880#define XF86XK_Macro17 _EVDEVK(0x2a0) /* v5.5 KEY_MACRO17 */
881#define XF86XK_Macro18 _EVDEVK(0x2a1) /* v5.5 KEY_MACRO18 */
882#define XF86XK_Macro19 _EVDEVK(0x2a2) /* v5.5 KEY_MACRO19 */
883#define XF86XK_Macro20 _EVDEVK(0x2a3) /* v5.5 KEY_MACRO20 */
884#define XF86XK_Macro21 _EVDEVK(0x2a4) /* v5.5 KEY_MACRO21 */
885#define XF86XK_Macro22 _EVDEVK(0x2a5) /* v5.5 KEY_MACRO22 */
886#define XF86XK_Macro23 _EVDEVK(0x2a6) /* v5.5 KEY_MACRO23 */
887#define XF86XK_Macro24 _EVDEVK(0x2a7) /* v5.5 KEY_MACRO24 */
888#define XF86XK_Macro25 _EVDEVK(0x2a8) /* v5.5 KEY_MACRO25 */
889#define XF86XK_Macro26 _EVDEVK(0x2a9) /* v5.5 KEY_MACRO26 */
890#define XF86XK_Macro27 _EVDEVK(0x2aa) /* v5.5 KEY_MACRO27 */
891#define XF86XK_Macro28 _EVDEVK(0x2ab) /* v5.5 KEY_MACRO28 */
892#define XF86XK_Macro29 _EVDEVK(0x2ac) /* v5.5 KEY_MACRO29 */
893#define XF86XK_Macro30 _EVDEVK(0x2ad) /* v5.5 KEY_MACRO30 */
894#define XF86XK_MacroRecordStart _EVDEVK(0x2b0) /* v5.5 KEY_MACRO_RECORD_START */
895#define XF86XK_MacroRecordStop _EVDEVK(0x2b1) /* v5.5 KEY_MACRO_RECORD_STOP */
896#define XF86XK_MacroPresetCycle _EVDEVK(0x2b2) /* v5.5 KEY_MACRO_PRESET_CYCLE */
897#define XF86XK_MacroPreset1 _EVDEVK(0x2b3) /* v5.5 KEY_MACRO_PRESET1 */
898#define XF86XK_MacroPreset2 _EVDEVK(0x2b4) /* v5.5 KEY_MACRO_PRESET2 */
899#define XF86XK_MacroPreset3 _EVDEVK(0x2b5) /* v5.5 KEY_MACRO_PRESET3 */
900#define XF86XK_KbdLcdMenu1 _EVDEVK(0x2b8) /* v5.5 KEY_KBD_LCD_MENU1 */
901#define XF86XK_KbdLcdMenu2 _EVDEVK(0x2b9) /* v5.5 KEY_KBD_LCD_MENU2 */
902#define XF86XK_KbdLcdMenu3 _EVDEVK(0x2ba) /* v5.5 KEY_KBD_LCD_MENU3 */
903#define XF86XK_KbdLcdMenu4 _EVDEVK(0x2bb) /* v5.5 KEY_KBD_LCD_MENU4 */
904#define XF86XK_KbdLcdMenu5 _EVDEVK(0x2bc) /* v5.5 KEY_KBD_LCD_MENU5 */
905#undef _EVDEVK
906// end of XF86keysyms.h
907
908 // All of the stuff below really has to match qxcbcommon.cpp in Qt!
909 { Qt::Key_Back, XF86XK_Back },
910 { Qt::Key_Forward, XF86XK_Forward },
911 { Qt::Key_Stop, XF86XK_Stop },
912 { Qt::Key_Refresh, XF86XK_Refresh },
913 { Qt::Key_Favorites, XF86XK_Favorites },
914 { Qt::Key_LaunchMedia, XF86XK_AudioMedia },
915 { Qt::Key_OpenUrl, XF86XK_OpenURL },
916 { Qt::Key_HomePage, XF86XK_HomePage },
917 { Qt::Key_Search, XF86XK_Search },
918 { Qt::Key_VolumeDown, XF86XK_AudioLowerVolume },
919 { Qt::Key_VolumeMute, XF86XK_AudioMute },
920 { Qt::Key_VolumeUp, XF86XK_AudioRaiseVolume },
921 { Qt::Key_MediaPlay, XF86XK_AudioPlay },
922 { Qt::Key_MediaStop, XF86XK_AudioStop },
923 { Qt::Key_MediaPrevious, XF86XK_AudioPrev },
924 { Qt::Key_MediaNext, XF86XK_AudioNext },
925 { Qt::Key_MediaRecord, XF86XK_AudioRecord },
926 { Qt::Key_MediaPause, XF86XK_AudioPause },
927 { Qt::Key_LaunchMail, XF86XK_Mail },
928 { Qt::Key_LaunchMedia, XF86XK_MyComputer },
929 { Qt::Key_Memo, XF86XK_Memo },
930 { Qt::Key_ToDoList, XF86XK_ToDoList },
931 { Qt::Key_Calendar, XF86XK_Calendar },
932 { Qt::Key_PowerDown, XF86XK_PowerDown },
933 { Qt::Key_ContrastAdjust, XF86XK_ContrastAdjust },
934 { Qt::Key_Standby, XF86XK_Standby },
935 { Qt::Key_MonBrightnessUp, XF86XK_MonBrightnessUp },
936 { Qt::Key_MonBrightnessDown, XF86XK_MonBrightnessDown },
937 { Qt::Key_KeyboardLightOnOff, XF86XK_KbdLightOnOff },
938 { Qt::Key_KeyboardBrightnessUp, XF86XK_KbdBrightnessUp },
939 { Qt::Key_KeyboardBrightnessDown,XF86XK_KbdBrightnessDown },
940 { Qt::Key_PowerOff, XF86XK_PowerOff },
941 { Qt::Key_WakeUp, XF86XK_WakeUp },
942 { Qt::Key_Eject, XF86XK_Eject },
943 { Qt::Key_ScreenSaver, XF86XK_ScreenSaver },
944 { Qt::Key_WWW, XF86XK_WWW },
945 { Qt::Key_Sleep, XF86XK_Sleep },
946 { Qt::Key_LightBulb, XF86XK_LightBulb },
947 { Qt::Key_Shop, XF86XK_Shop },
948 { Qt::Key_History, XF86XK_History },
949 { Qt::Key_AddFavorite, XF86XK_AddFavorite },
950 { Qt::Key_HotLinks, XF86XK_HotLinks },
951 { Qt::Key_BrightnessAdjust, XF86XK_BrightnessAdjust },
952 { Qt::Key_Finance, XF86XK_Finance },
953 { Qt::Key_Community, XF86XK_Community },
954 { Qt::Key_AudioRewind, XF86XK_AudioRewind },
955 { Qt::Key_BackForward, XF86XK_BackForward },
956 { Qt::Key_ApplicationLeft, XF86XK_ApplicationLeft },
957 { Qt::Key_ApplicationRight, XF86XK_ApplicationRight },
958 { Qt::Key_Book, XF86XK_Book },
959 { Qt::Key_CD, XF86XK_CD },
960 { Qt::Key_Calculator, XF86XK_Calculater },
961 { Qt::Key_Calculator, XF86XK_Calculator },
962 { Qt::Key_Clear, XF86XK_Clear },
963 { Qt::Key_ClearGrab, XF86XK_ClearGrab },
964 { Qt::Key_Close, XF86XK_Close },
965 { Qt::Key_Copy, XF86XK_Copy },
966 { Qt::Key_Cut, XF86XK_Cut },
967 { Qt::Key_Display, XF86XK_Display },
968 { Qt::Key_DOS, XF86XK_DOS },
969 { Qt::Key_Documents, XF86XK_Documents },
970 { Qt::Key_Excel, XF86XK_Excel },
971 { Qt::Key_Explorer, XF86XK_Explorer },
972 { Qt::Key_Game, XF86XK_Game },
973 { Qt::Key_Go, XF86XK_Go },
974 { Qt::Key_iTouch, XF86XK_iTouch },
975 { Qt::Key_LogOff, XF86XK_LogOff },
976 { Qt::Key_Market, XF86XK_Market },
977 { Qt::Key_Meeting, XF86XK_Meeting },
978 { Qt::Key_MenuKB, XF86XK_MenuKB },
979 { Qt::Key_MenuPB, XF86XK_MenuPB },
980 { Qt::Key_MySites, XF86XK_MySites },
981 { Qt::Key_New, XF86XK_New },
982 { Qt::Key_News, XF86XK_News },
983 { Qt::Key_OfficeHome, XF86XK_OfficeHome },
984 { Qt::Key_Open, XF86XK_Open },
985 { Qt::Key_Option, XF86XK_Option },
986 { Qt::Key_Paste, XF86XK_Paste },
987 { Qt::Key_Phone, XF86XK_Phone },
988 { Qt::Key_Reply, XF86XK_Reply },
989 { Qt::Key_Reload, XF86XK_Reload },
990 { Qt::Key_RotateWindows, XF86XK_RotateWindows },
991 { Qt::Key_RotationPB, XF86XK_RotationPB },
992 { Qt::Key_RotationKB, XF86XK_RotationKB },
993 { Qt::Key_Save, XF86XK_Save },
994 { Qt::Key_Send, XF86XK_Send },
995 { Qt::Key_Spell, XF86XK_Spell },
996 { Qt::Key_SplitScreen, XF86XK_SplitScreen },
997 { Qt::Key_Support, XF86XK_Support },
998 { Qt::Key_TaskPane, XF86XK_TaskPane },
999 { Qt::Key_Terminal, XF86XK_Terminal },
1000 { Qt::Key_Tools, XF86XK_Tools },
1001 { Qt::Key_Travel, XF86XK_Travel },
1002 { Qt::Key_Video, XF86XK_Video },
1003 { Qt::Key_Word, XF86XK_Word },
1004 { Qt::Key_Xfer, XF86XK_Xfer },
1005 { Qt::Key_ZoomIn, XF86XK_ZoomIn },
1006 { Qt::Key_ZoomOut, XF86XK_ZoomOut },
1007 { Qt::Key_Away, XF86XK_Away },
1008 { Qt::Key_Messenger, XF86XK_Messenger },
1009 { Qt::Key_WebCam, XF86XK_WebCam },
1010 { Qt::Key_MailForward, XF86XK_MailForward },
1011 { Qt::Key_Pictures, XF86XK_Pictures },
1012 { Qt::Key_Music, XF86XK_Music },
1013 { Qt::Key_Battery, XF86XK_Battery },
1014 { Qt::Key_Bluetooth, XF86XK_Bluetooth },
1015 { Qt::Key_WLAN, XF86XK_WLAN },
1016 { Qt::Key_UWB, XF86XK_UWB },
1017 { Qt::Key_AudioForward, XF86XK_AudioForward },
1018 { Qt::Key_AudioRepeat, XF86XK_AudioRepeat },
1019 { Qt::Key_AudioRandomPlay, XF86XK_AudioRandomPlay },
1020 { Qt::Key_Subtitle, XF86XK_Subtitle },
1021 { Qt::Key_AudioCycleTrack, XF86XK_AudioCycleTrack },
1022 { Qt::Key_Time, XF86XK_Time },
1023 { Qt::Key_Select, XF86XK_Select },
1024 { Qt::Key_View, XF86XK_View },
1025 { Qt::Key_TopMenu, XF86XK_TopMenu },
1026 { Qt::Key_Red, XF86XK_Red },
1027 { Qt::Key_Green, XF86XK_Green },
1028 { Qt::Key_Yellow, XF86XK_Yellow },
1029 { Qt::Key_Blue, XF86XK_Blue },
1030 { Qt::Key_Bluetooth, XF86XK_Bluetooth },
1031 { Qt::Key_Suspend, XF86XK_Suspend },
1032 { Qt::Key_Hibernate, XF86XK_Hibernate },
1033 { Qt::Key_TouchpadToggle, XF86XK_TouchpadToggle },
1034 { Qt::Key_TouchpadOn, XF86XK_TouchpadOn },
1035 { Qt::Key_TouchpadOff, XF86XK_TouchpadOff },
1036 { Qt::Key_MicMute, XF86XK_AudioMicMute },
1037 { Qt::Key_Launch0, XF86XK_Launch0 },
1038 { Qt::Key_Launch1, XF86XK_Launch1 },
1039 { Qt::Key_Launch2, XF86XK_Launch2 },
1040 { Qt::Key_Launch3, XF86XK_Launch3 },
1041 { Qt::Key_Launch4, XF86XK_Launch4 },
1042 { Qt::Key_Launch5, XF86XK_Launch5 },
1043 { Qt::Key_Launch6, XF86XK_Launch6 },
1044 { Qt::Key_Launch7, XF86XK_Launch7 },
1045 { Qt::Key_Launch8, XF86XK_Launch8 },
1046 { Qt::Key_Launch9, XF86XK_Launch9 },
1047 { Qt::Key_LaunchA, XF86XK_LaunchA },
1048 { Qt::Key_LaunchB, XF86XK_LaunchB },
1049 { Qt::Key_LaunchC, XF86XK_LaunchC },
1050 { Qt::Key_LaunchD, XF86XK_LaunchD },
1051 { Qt::Key_LaunchE, XF86XK_LaunchE },
1052 { Qt::Key_LaunchF, XF86XK_LaunchF },
1053};
1054// clang-format on
1055
1056//---------------------------------------------------------------------
1057// Debugging
1058//---------------------------------------------------------------------
1059#ifndef NDEBUG
1060inline void checkDisplay()
1061{
1062 // Some non-GUI apps might try to use us.
1063 if (!QX11Info::display()) {
1064 qCCritical(LOG_KKEYSERVER_X11) << "QX11Info::display() returns 0. I'm probably going to crash now.";
1065 qCCritical(LOG_KKEYSERVER_X11) << "If this is a KApplication initialized without GUI stuff, change it to be "
1066 "initialized with GUI stuff.";
1067 }
1068}
1069#else // NDEBUG
1070#define checkDisplay()
1071#endif
1072
1073//---------------------------------------------------------------------
1074// Initialization
1075//---------------------------------------------------------------------
1076
1077static bool g_bInitializedMods;
1078static uint g_modXNumLock, g_modXScrollLock, g_modXModeSwitch, g_alt_mask, g_meta_mask, g_super_mask, g_hyper_mask;
1079
1081{
1082 // Reinitialize the masks
1083 g_modXNumLock = 0;
1084 g_modXScrollLock = 0;
1085 g_modXModeSwitch = 0;
1086 g_alt_mask = 0;
1087 g_meta_mask = 0;
1088 g_super_mask = 0;
1089 g_hyper_mask = 0;
1090
1091 if (!QX11Info::isPlatformX11()) {
1092 qCWarning(LOG_KKEYSERVER_X11) << "X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1093 g_bInitializedMods = true;
1094 return false;
1095 }
1096
1097 checkDisplay();
1098 xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(QX11Info::connection());
1099 XModifierKeymap *xmk = XGetModifierMapping(QX11Info::display());
1100
1101 int min_keycode;
1102 int max_keycode;
1103 int keysyms_per_keycode = 0;
1104
1105 XDisplayKeycodes(QX11Info::display(), &min_keycode, &max_keycode);
1106 XFree(XGetKeyboardMapping(QX11Info::display(), min_keycode, 1, &keysyms_per_keycode));
1107
1108 for (int i = Mod1MapIndex; i < 8; i++) {
1109 uint mask = (1 << i);
1110 uint keySymX = NoSymbol;
1111
1112 // This used to be only XKeycodeToKeysym( ... , 0 ), but that fails with XFree4.3.99
1113 // and X.org R6.7 , where for some reason only ( ... , 1 ) works. I have absolutely no
1114 // idea what the problem is, but searching all possibilities until something valid is
1115 // found fixes the problem.
1116 for (int j = 0; j < xmk->max_keypermod; ++j) {
1117 for (int k = 0; k < keysyms_per_keycode; ++k) {
1118 keySymX = xcb_key_symbols_get_keysym(symbols, xmk->modifiermap[xmk->max_keypermod * i + j], k);
1119
1120 switch (keySymX) {
1121 case XK_Alt_L:
1122 case XK_Alt_R:
1123 g_alt_mask |= mask;
1124 break;
1125
1126 case XK_Super_L:
1127 case XK_Super_R:
1128 g_super_mask |= mask;
1129 break;
1130
1131 case XK_Hyper_L:
1132 case XK_Hyper_R:
1133 g_hyper_mask |= mask;
1134 break;
1135
1136 case XK_Meta_L:
1137 case XK_Meta_R:
1138 g_meta_mask |= mask;
1139 break;
1140
1141 case XK_Num_Lock:
1142 g_modXNumLock |= mask;
1143 break;
1144 case XK_Scroll_Lock:
1145 g_modXScrollLock |= mask;
1146 break;
1147 case XK_Mode_switch:
1148 g_modXModeSwitch |= mask;
1149 break;
1150 }
1151 }
1152 }
1153 }
1154
1155#ifdef KKEYSERVER_DEBUG
1156 qCDebug(LOG_KKEYSERVER_X11) << "Alt:" << g_alt_mask;
1157 qCDebug(LOG_KKEYSERVER_X11) << "Meta:" << g_meta_mask;
1158 qCDebug(LOG_KKEYSERVER_X11) << "Super:" << g_super_mask;
1159 qCDebug(LOG_KKEYSERVER_X11) << "Hyper:" << g_hyper_mask;
1160 qCDebug(LOG_KKEYSERVER_X11) << "NumLock:" << g_modXNumLock;
1161 qCDebug(LOG_KKEYSERVER_X11) << "ScrollLock:" << g_modXScrollLock;
1162 qCDebug(LOG_KKEYSERVER_X11) << "ModeSwitch:" << g_modXModeSwitch;
1163#endif
1164
1165 // Check if hyper overlaps with super or meta or alt
1166 if (g_hyper_mask & (g_super_mask | g_meta_mask | g_alt_mask)) {
1167#ifdef KKEYSERVER_DEBUG
1168 qCDebug(LOG_KKEYSERVER_X11) << "Hyper conflicts with super, meta or alt.";
1169#endif
1170 // Remove the conflicting masks
1171 g_hyper_mask &= ~(g_super_mask | g_meta_mask | g_alt_mask);
1172 }
1173
1174 // Check if super overlaps with meta or alt
1175 if (g_super_mask & (g_meta_mask | g_alt_mask)) {
1176#ifdef KKEYSERVER_DEBUG
1177 qCDebug(LOG_KKEYSERVER_X11) << "Super conflicts with meta or alt.";
1178#endif
1179 // Remove the conflicting masks
1180 g_super_mask &= ~(g_meta_mask | g_alt_mask);
1181 }
1182
1183 // Check if meta overlaps with alt
1184 if (g_meta_mask | g_alt_mask) {
1185#ifdef KKEYSERVER_DEBUG
1186 qCDebug(LOG_KKEYSERVER_X11) << "Meta conflicts with alt.";
1187#endif
1188 // Remove the conflicting masks
1189 g_meta_mask &= ~(g_alt_mask);
1190 }
1191
1192 if (!g_meta_mask) {
1193#ifdef KKEYSERVER_DEBUG
1194 qCDebug(LOG_KKEYSERVER_X11) << "Meta is not set or conflicted with alt.";
1195#endif
1196 if (g_super_mask) {
1197#ifdef KKEYSERVER_DEBUG
1198 qCDebug(LOG_KKEYSERVER_X11) << "Using super for meta";
1199#endif
1200 // Use Super
1201 g_meta_mask = g_super_mask;
1202 } else if (g_hyper_mask) {
1203#ifdef KKEYSERVER_DEBUG
1204 qCDebug(LOG_KKEYSERVER_X11) << "Using hyper for meta";
1205#endif
1206 // User Hyper
1207 g_meta_mask = g_hyper_mask;
1208 } else {
1209 // ???? Nothing left
1210 g_meta_mask = 0;
1211 }
1212 }
1213
1214#ifdef KKEYSERVER_DEBUG
1215 qCDebug(LOG_KKEYSERVER_X11) << "Alt:" << g_alt_mask;
1216 qCDebug(LOG_KKEYSERVER_X11) << "Meta:" << g_meta_mask;
1217 qCDebug(LOG_KKEYSERVER_X11) << "Super:" << g_super_mask;
1218 qCDebug(LOG_KKEYSERVER_X11) << "Hyper:" << g_hyper_mask;
1219 qCDebug(LOG_KKEYSERVER_X11) << "NumLock:" << g_modXNumLock;
1220 qCDebug(LOG_KKEYSERVER_X11) << "ScrollLock:" << g_modXScrollLock;
1221 qCDebug(LOG_KKEYSERVER_X11) << "ModeSwitch:" << g_modXModeSwitch;
1222#endif
1223
1224 if (!g_meta_mask) {
1225 qCWarning(LOG_KKEYSERVER_X11) << "Your keyboard setup doesn't provide a key to use for meta. See 'xmodmap -pm' or 'xkbcomp $DISPLAY'";
1226 }
1227
1228 g_rgX11ModInfo[2].modX = g_alt_mask;
1229 g_rgX11ModInfo[3].modX = g_meta_mask;
1230
1231 xcb_key_symbols_free(symbols);
1232 XFreeModifiermap(xmk);
1233 g_bInitializedMods = true;
1234
1235 return true;
1236}
1237
1238//---------------------------------------------------------------------
1239// Helper functions
1240//---------------------------------------------------------------------
1241
1242static bool is_keypad_key(xcb_keysym_t keysym)
1243{
1244 return keysym >= XK_KP_Space && keysym <= XK_KP_9;
1245}
1246
1247//---------------------------------------------------------------------
1248// Public functions
1249//---------------------------------------------------------------------
1250
1252{
1253 return ShiftMask;
1254}
1256{
1257 return ControlMask;
1258}
1260{
1261 if (!g_bInitializedMods) {
1263 }
1264 return g_alt_mask;
1265}
1267{
1268 if (!g_bInitializedMods) {
1270 }
1271 return g_meta_mask;
1272}
1273
1275{
1276 if (!g_bInitializedMods) {
1278 }
1279 return g_modXNumLock;
1280}
1282{
1283 return LockMask;
1284}
1286{
1287 if (!g_bInitializedMods) {
1289 }
1290 return g_modXScrollLock;
1291}
1293{
1294 if (!g_bInitializedMods) {
1296 }
1297 return g_modXModeSwitch;
1298}
1299
1301{
1302 return modXMeta() != 0;
1303}
1304
1305uint getModsRequired(uint sym)
1306{
1307 if (!QX11Info::isPlatformX11()) {
1308 qCWarning(LOG_KKEYSERVER_X11) << "X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1309 return 0;
1310 }
1311 uint mod = 0;
1312
1313 // FIXME: This might not be true on all keyboard layouts!
1314 if (sym == XK_Sys_Req) {
1315 return Qt::ALT;
1316 }
1317 if (sym == XK_Break) {
1318 return Qt::CTRL;
1319 }
1320
1321 if (sym < 0x3000) {
1322 QChar c(sym);
1323 if (c.isLetter() && c.toLower() != c.toUpper() && sym == c.toUpper().unicode()) {
1324 return Qt::SHIFT;
1325 }
1326 }
1327
1328 uchar code = XKeysymToKeycode(QX11Info::display(), sym);
1329 if (code) {
1330 // need to check index 0 before the others, so that a null-mod
1331 // can take precedence over the others, in case the modified
1332 // key produces the same symbol.
1333 if (sym == XKeycodeToKeysym(QX11Info::display(), code, 0)) {
1334 ;
1335 } else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 1)) {
1336 mod = Qt::SHIFT;
1337 } else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 2)) {
1338 mod = MODE_SWITCH;
1339 } else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 3)) {
1340 mod = Qt::SHIFT | MODE_SWITCH;
1341 }
1342 }
1343 return mod;
1344}
1345
1346#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0)
1347bool keyQtToCodeX(int keyQt, int *keyCode)
1348{
1349 if (!QX11Info::isPlatformX11()) {
1350 qCWarning(LOG_KKEYSERVER_X11) << "X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1351 return false;
1352 }
1353 int sym;
1354 uint mod;
1355 keyQtToSymX(keyQt, &sym);
1356 keyQtToModX(keyQt, &mod);
1357
1358 // Get any extra mods required by the sym.
1359 // E.g., XK_Plus requires SHIFT on the en layout.
1360 uint modExtra = getModsRequired(sym);
1361 // Get the X modifier equivalent.
1362 if (!sym || !keyQtToModX((keyQt & Qt::KeyboardModifierMask) | modExtra, &mod)) {
1363 *keyCode = 0;
1364 return false;
1365 }
1366
1367 *keyCode = XKeysymToKeycode(QX11Info::display(), sym);
1368 return true;
1369}
1370#endif
1371
1373{
1374 QList<int> keyCodes;
1375 if (!QX11Info::isPlatformX11()) {
1376 qCWarning(LOG_KKEYSERVER_X11) << "X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1377 return keyCodes;
1378 }
1379 uint mod;
1380 const QList<int> syms(keyQtToSymXs(keyQt));
1381 keyQtToModX(keyQt, &mod);
1382
1383 for (int sym : syms) {
1384 // Get any extra mods required by the sym.
1385 // E.g., XK_Plus requires SHIFT on the en layout.
1386 uint modExtra = getModsRequired(sym);
1387 // Get the X modifier equivalent.
1388 if (!sym || !keyQtToModX((keyQt & Qt::KeyboardModifierMask) | modExtra, &mod)) {
1389 continue;
1390 }
1391
1392 keyCodes.append(XKeysymToKeycode(QX11Info::display(), sym));
1393 }
1394 return keyCodes;
1395}
1396
1397#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0)
1398bool keyQtToSymX(int keyQt, int *keySym)
1399{
1400 int symQt = keyQt & ~Qt::KeyboardModifierMask;
1401
1402 if (keyQt & Qt::KeypadModifier) {
1403 if (symQt >= Qt::Key_0 && symQt <= Qt::Key_9) {
1404 *keySym = XK_KP_0 + (symQt - Qt::Key_0);
1405 return true;
1406 }
1407 } else {
1408 if (symQt < 0x1000) {
1409 *keySym = QChar(symQt).toUpper().unicode();
1410 return true;
1411 }
1412 }
1413
1414 for (const TransKey &tk : g_rgQtToSymX) {
1415 if (tk.keySymQt == symQt) {
1416 if ((keyQt & Qt::KeypadModifier) && !is_keypad_key(tk.keySymX)) {
1417 continue;
1418 }
1419 *keySym = tk.keySymX;
1420 return true;
1421 }
1422 }
1423
1424 *keySym = 0;
1425 if (symQt != Qt::Key_Shift && symQt != Qt::Key_Control && symQt != Qt::Key_Alt && symQt != Qt::Key_Meta && symQt != Qt::Key_Direction_L
1426 && symQt != Qt::Key_Direction_R) {
1427 // qCDebug(LOG_KKEYSERVER_X11) << "Sym::initQt( " << QString::number(keyQt,16) << " ): failed to convert key.";
1428 }
1429 return false;
1430}
1431#endif
1432
1434{
1435 int symQt = keyQt & ~Qt::KeyboardModifierMask;
1436 QList<int> syms;
1437
1438 if (keyQt & Qt::KeypadModifier) {
1439 if (symQt >= Qt::Key_0 && symQt <= Qt::Key_9) {
1440 syms.append(XK_KP_0 + (symQt - Qt::Key_0));
1441 return syms;
1442 }
1443 } else {
1444 if (symQt < 0x1000) {
1445 syms.append(QChar(symQt).toUpper().unicode());
1446 return syms;
1447 }
1448 }
1449
1450 for (const TransKey &tk : g_rgQtToSymX) {
1451 if (tk.keySymQt == symQt) {
1452 if ((keyQt & Qt::KeypadModifier) && !is_keypad_key(tk.keySymX)) {
1453 continue;
1454 }
1455 syms.append(tk.keySymX);
1456 }
1457 }
1458 return syms;
1459}
1460
1461bool symXModXToKeyQt(uint32_t keySym, uint16_t modX, int *keyQt)
1462{
1463 int keyModQt = 0;
1464 *keyQt = Qt::Key_unknown;
1465
1466 if (keySym >= XK_KP_0 && keySym <= XK_KP_9) {
1467 // numeric keypad keys
1468 *keyQt = Qt::Key_0 + ((int)keySym - XK_KP_0);
1469 } else if (keySym < 0x1000) {
1470 if (keySym >= 'a' && keySym <= 'z') {
1471 *keyQt = QChar(keySym).toUpper().unicode();
1472 } else {
1473 *keyQt = keySym;
1474 }
1475 }
1476
1477 else if (keySym < 0x3000) {
1478 *keyQt = keySym;
1479 }
1480
1481 else {
1482 for (const TransKey &tk : g_rgQtToSymX) {
1483 if (tk.keySymX == keySym) {
1484 *keyQt = tk.keySymQt;
1485 break;
1486 }
1487 }
1488 }
1489
1490 if (*keyQt == Qt::Key_unknown) {
1491 return false;
1492 }
1493
1494 if (modXToQt(modX, &keyModQt)) {
1495 *keyQt |= keyModQt;
1496 if (is_keypad_key(keySym)) {
1497 *keyQt |= Qt::KeypadModifier;
1498 }
1499 return true;
1500 }
1501 return false;
1502}
1503
1504bool keyQtToModX(int modQt, uint *modX)
1505{
1506 if (!g_bInitializedMods) {
1508 }
1509
1510 *modX = 0;
1511 for (int i = 0; i < 4; i++) {
1512 if (modQt & g_rgX11ModInfo[i].modQt) {
1513 if (g_rgX11ModInfo[i].modX) {
1514 *modX |= g_rgX11ModInfo[i].modX;
1515 } else {
1516 // The qt modifier has no x equivalent. Return false
1517 return false;
1518 }
1519 }
1520 }
1521 return true;
1522}
1523
1524bool modXToQt(uint modX, int *modQt)
1525{
1526 if (!g_bInitializedMods) {
1528 }
1529
1530 *modQt = 0;
1531 for (int i = 0; i < 4; i++) {
1532 if (modX & g_rgX11ModInfo[i].modX) {
1533 *modQt |= g_rgX11ModInfo[i].modQt;
1534 continue;
1535 }
1536 }
1537 return true;
1538}
1539
1540bool codeXToSym(uchar codeX, uint modX, uint *sym)
1541{
1542 if (!QX11Info::isPlatformX11()) {
1543 qCWarning(LOG_KKEYSERVER_X11) << "X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1544 return false;
1545 }
1546 KeySym keySym;
1547 XKeyPressedEvent event;
1548
1549 checkDisplay();
1550
1551 event.type = KeyPress;
1552 event.display = QX11Info::display();
1553 event.state = modX;
1554 event.keycode = codeX;
1555
1556 XLookupString(&event, nullptr, 0, &keySym, nullptr);
1557 *sym = (uint)keySym;
1558 return true;
1559}
1560
1562{
1563 return modXShift() | modXCtrl() | modXAlt() | modXMeta();
1564}
1565
1566bool xEventToQt(XEvent *e, int *keyQt)
1567{
1568 Q_ASSERT(e->type == KeyPress || e->type == KeyRelease);
1569
1570 uchar keyCodeX = e->xkey.keycode;
1571 uint keyModX = e->xkey.state & (accelModMaskX() | MODE_SWITCH);
1572
1573 KeySym keySym;
1574 char buffer[16];
1575 XLookupString((XKeyEvent *)e, buffer, 15, &keySym, nullptr);
1576 uint keySymX = (uint)keySym;
1577
1578 // If numlock is active and a keypad key is pressed, XOR the SHIFT state.
1579 // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left.
1580 if (e->xkey.state & modXNumLock()) {
1581 uint sym = XKeycodeToKeysym(QX11Info::display(), keyCodeX, 0);
1582 // TODO: what's the xor operator in c++?
1583 // If this is a keypad key,
1584 if (sym >= XK_KP_Space && sym <= XK_KP_9) {
1585 switch (sym) {
1586 // Leave the following keys unaltered
1587 // FIXME: The proper solution is to see which keysyms don't change when shifted.
1588 case XK_KP_Multiply:
1589 case XK_KP_Add:
1590 case XK_KP_Subtract:
1591 case XK_KP_Divide:
1592 break;
1593 default:
1594 if (keyModX & modXShift()) {
1595 keyModX &= ~modXShift();
1596 } else {
1597 keyModX |= modXShift();
1598 }
1599 }
1600 }
1601 }
1602
1603 return KKeyServer::symXModXToKeyQt(keySymX, keyModX, keyQt);
1604}
1605
1606bool xcbKeyPressEventToQt(xcb_generic_event_t *e, int *keyQt)
1607{
1608 if ((e->response_type & ~0x80) != XCB_KEY_PRESS && (e->response_type & ~0x80) != XCB_KEY_RELEASE) {
1609 return false;
1610 }
1611 return xcbKeyPressEventToQt(reinterpret_cast<xcb_key_press_event_t *>(e), keyQt);
1612}
1613
1614bool xcbKeyPressEventToQt(xcb_key_press_event_t *e, int *keyQt)
1615{
1616 const uint16_t keyModX = e->state & (accelModMaskX() | MODE_SWITCH);
1617
1618 xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(QX11Info::connection());
1619
1620 // We might have to use 4,5 instead of 0,1 here when mode_switch is active, just not sure how to test that.
1621 const xcb_keysym_t keySym0 = xcb_key_press_lookup_keysym(symbols, e, 0);
1622 const xcb_keysym_t keySym1 = xcb_key_press_lookup_keysym(symbols, e, 1);
1623 xcb_keysym_t keySymX;
1624
1625 if ((e->state & KKeyServer::modXNumLock()) && is_keypad_key(keySym1)) {
1626 if ((e->state & XCB_MOD_MASK_SHIFT)) {
1627 keySymX = keySym0;
1628 } else {
1629 keySymX = keySym1;
1630 }
1631 } else {
1632 keySymX = keySym0;
1633 }
1634
1635 bool ok = KKeyServer::symXModXToKeyQt(keySymX, keyModX, keyQt);
1636
1637 if ((*keyQt & Qt::ShiftModifier) && !KKeyServer::isShiftAsModifierAllowed(*keyQt)) {
1638 if (*keyQt != Qt::Key_Tab) { // KKeySequenceWidget does not map shift+tab to backtab
1639 static const int FirstLevelShift = 1;
1640 keySymX = xcb_key_symbols_get_keysym(symbols, e->detail, FirstLevelShift);
1641 KKeyServer::symXModXToKeyQt(keySymX, keyModX, keyQt);
1642 }
1643 *keyQt &= ~Qt::ShiftModifier;
1644 }
1645
1646 xcb_key_symbols_free(symbols);
1647 return ok;
1648}
1649
1650} // end of namespace KKeyServer block
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
A collection of functions for the conversion of key presses and their modifiers from the window syste...
uint modXLock()
Returns the X11 Lock modifier mask/flag.
uint modXAlt()
Returns the X11 Alt (Mod1) modifier mask/flag.
uint modXMeta()
Returns the X11 Win (Mod3) modifier mask/flag.
bool initializeMods()
Initialises the values to return for the mod*() functions below.
uint stringUserToMod(const QString &mod)
Converts the modifier given as user-readable string (in English) to KKey::ModFlag modifier,...
bool symXModXToKeyQt(uint32_t keySym, uint16_t modX, int *keyQt)
Converts the given symbol and modifier combination to a Qt key code.
QList< int > keyQtToSymXs(int keyQt)
Extracts the symbols from the given Qt key and converts it to an X11 symbol + modifiers.
bool keyQtToSymX(int keyQt, int *keySym)
Extracts the symbol from the given Qt key and converts it to an X11 symbol + modifiers.
bool isShiftAsModifierAllowed(int keyQt)
Test if the shift modifier should be recorded for a given key.
bool keyboardHasMetaKey()
Returns true if the current keyboard layout supports the Meta key.
bool xEventToQt(XEvent *e, int *keyQt)
Converts an X keypress event into a Qt key + modifier code.
uint modXCtrl()
Returns the X11 Ctrl modifier mask/flag.
bool keyQtToCodeX(int keyQt, int *keyCode)
Extracts the code from the given Qt key.
uint modXScrollLock()
Returns the X11 ScrollLock modifier mask/flag.
uint modXShift()
Returns the X11 Shift modifier mask/flag.
QList< int > keyQtToCodeXs(int keyQt)
Extracts the codes from the given Qt key.
bool modXToQt(uint modX, int *modQt)
Converts the mask of ORed X11 modifiers to a mask of ORed Qt key code modifiers.
uint modXModeSwitch()
Returns the X11 Mode_switch modifier mask/flag.
uint accelModMaskX()
Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and Win (if available).
bool keyQtToModX(int modQt, uint *modX)
Extracts the modifiers from the given Qt key and converts them in a mask of X11 modifiers.
QString modToStringUser(uint mod)
Converts the mask of ORed KKey::ModFlag modifiers to a user-readable string.
bool xcbKeyPressEventToQt(xcb_generic_event_t *e, int *keyQt)
Converts an XCB keypress event into a Qt key + modifier code.
uint modXNumLock()
Returns the X11 NumLock modifier mask/flag.
bool isLetter() const const
char32_t toUpper(char32_t ucs4)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
void append(QList< T > &&value)
bool isEmpty() const const
QString toLower() const const
KeyboardModifierMask
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.