45#define KEYCTXT "keyboard-key-name"
46static ModInfo g_rgModInfo[4] = {
56static bool g_bInitializedKKeyLabels;
57static bool g_bMacLabels;
59static void intializeKKeyLabels()
65 g_bMacLabels = (*g_rgModInfo[2].sLabel ==
QLatin1String(
"Command"));
66 g_bInitializedKKeyLabels =
true;
73static QString modToString(uint mod,
bool bUserSpace)
75 if (bUserSpace && !g_bInitializedKKeyLabels) {
76 intializeKKeyLabels();
80 for (
int i = 3; i >= 0; i--) {
81 if (mod & g_rgModInfo[i].modQt) {
85 s += (bUserSpace) ? *g_rgModInfo[i].sLabel :
QLatin1String(g_rgModInfo[i].psName);
93 return modToString(mod,
true);
98 for (
int i = 3; i >= 0; i--) {
100 return g_rgModInfo[i].modQt;
109 keyQt &=
~Qt::KeyboardModifierMask;
313 uint sym, symVariation;
332static X11ModInfo g_rgX11ModInfo[4] = {
334 {
Qt::CTRL, X11_ONLY(ControlMask) },
335 {
Qt::ALT, X11_ONLY(Mod1Mask) },
340static const TransKey g_rgQtToSymX[] = {
443#define XF86XK_ModeLock 0x1008ff01
446#define XF86XK_MonBrightnessUp 0x1008ff02
447#define XF86XK_MonBrightnessDown 0x1008ff03
448#define XF86XK_KbdLightOnOff 0x1008ff04
449#define XF86XK_KbdBrightnessUp 0x1008ff05
450#define XF86XK_KbdBrightnessDown 0x1008ff06
451#define XF86XK_MonBrightnessCycle 0x1008ff07
456#define XF86XK_Standby 0x1008ff10
457#define XF86XK_AudioLowerVolume 0x1008ff11
458#define XF86XK_AudioMute 0x1008ff12
459#define XF86XK_AudioRaiseVolume 0x1008ff13
460#define XF86XK_AudioPlay 0x1008ff14
461#define XF86XK_AudioStop 0x1008ff15
462#define XF86XK_AudioPrev 0x1008ff16
463#define XF86XK_AudioNext 0x1008ff17
464#define XF86XK_HomePage 0x1008ff18
465#define XF86XK_Mail 0x1008ff19
466#define XF86XK_Start 0x1008ff1a
467#define XF86XK_Search 0x1008ff1b
468#define XF86XK_AudioRecord 0x1008ff1c
471#define XF86XK_Calculator 0x1008ff1d
472#define XF86XK_Memo 0x1008ff1e
473#define XF86XK_ToDoList 0x1008ff1f
474#define XF86XK_Calendar 0x1008ff20
475#define XF86XK_PowerDown 0x1008ff21
476#define XF86XK_ContrastAdjust 0x1008ff22
477#define XF86XK_RockerUp 0x1008ff23
478#define XF86XK_RockerDown 0x1008ff24
479#define XF86XK_RockerEnter 0x1008ff25
482#define XF86XK_Back 0x1008ff26
483#define XF86XK_Forward 0x1008ff27
484#define XF86XK_Stop 0x1008ff28
485#define XF86XK_Refresh 0x1008ff29
486#define XF86XK_PowerOff 0x1008ff2a
487#define XF86XK_WakeUp 0x1008ff2b
488#define XF86XK_Eject 0x1008ff2c
489#define XF86XK_ScreenSaver 0x1008ff2d
490#define XF86XK_WWW 0x1008ff2e
491#define XF86XK_Sleep 0x1008ff2f
492#define XF86XK_Favorites 0x1008ff30
493#define XF86XK_AudioPause 0x1008ff31
494#define XF86XK_AudioMedia 0x1008ff32
495#define XF86XK_MyComputer 0x1008ff33
496#define XF86XK_VendorHome 0x1008ff34
497#define XF86XK_LightBulb 0x1008ff35
498#define XF86XK_Shop 0x1008ff36
499#define XF86XK_History 0x1008ff37
500#define XF86XK_OpenURL 0x1008ff38
501#define XF86XK_AddFavorite 0x1008ff39
502#define XF86XK_HotLinks 0x1008ff3a
503#define XF86XK_BrightnessAdjust 0x1008ff3b
504#define XF86XK_Finance 0x1008ff3c
505#define XF86XK_Community 0x1008ff3d
506#define XF86XK_AudioRewind 0x1008ff3e
507#define XF86XK_BackForward 0x1008ff3f
508#define XF86XK_Launch0 0x1008ff40
509#define XF86XK_Launch1 0x1008ff41
510#define XF86XK_Launch2 0x1008ff42
511#define XF86XK_Launch3 0x1008ff43
512#define XF86XK_Launch4 0x1008ff44
513#define XF86XK_Launch5 0x1008ff45
514#define XF86XK_Launch6 0x1008ff46
515#define XF86XK_Launch7 0x1008ff47
516#define XF86XK_Launch8 0x1008ff48
517#define XF86XK_Launch9 0x1008ff49
518#define XF86XK_LaunchA 0x1008ff4a
519#define XF86XK_LaunchB 0x1008ff4b
520#define XF86XK_LaunchC 0x1008ff4c
521#define XF86XK_LaunchD 0x1008ff4d
522#define XF86XK_LaunchE 0x1008ff4e
523#define XF86XK_LaunchF 0x1008ff4f
525#define XF86XK_ApplicationLeft 0x1008ff50
526#define XF86XK_ApplicationRight 0x1008ff51
527#define XF86XK_Book 0x1008ff52
528#define XF86XK_CD 0x1008ff53
529#define XF86XK_Calculater 0x1008ff54
530#define XF86XK_Clear 0x1008ff55
531#define XF86XK_Close 0x1008ff56
532#define XF86XK_Copy 0x1008ff57
533#define XF86XK_Cut 0x1008ff58
534#define XF86XK_Display 0x1008ff59
535#define XF86XK_DOS 0x1008ff5a
536#define XF86XK_Documents 0x1008ff5b
537#define XF86XK_Excel 0x1008ff5c
538#define XF86XK_Explorer 0x1008ff5d
539#define XF86XK_Game 0x1008ff5e
540#define XF86XK_Go 0x1008ff5f
541#define XF86XK_iTouch 0x1008ff60
542#define XF86XK_LogOff 0x1008ff61
543#define XF86XK_Market 0x1008ff62
544#define XF86XK_Meeting 0x1008ff63
545#define XF86XK_MenuKB 0x1008ff65
546#define XF86XK_MenuPB 0x1008ff66
547#define XF86XK_MySites 0x1008ff67
548#define XF86XK_New 0x1008ff68
549#define XF86XK_News 0x1008ff69
550#define XF86XK_OfficeHome 0x1008ff6a
551#define XF86XK_Open 0x1008ff6b
552#define XF86XK_Option 0x1008ff6c
553#define XF86XK_Paste 0x1008ff6d
554#define XF86XK_Phone 0x1008ff6e
555#define XF86XK_Q 0x1008ff70
556#define XF86XK_Reply 0x1008ff72
557#define XF86XK_Reload 0x1008ff73
558#define XF86XK_RotateWindows 0x1008ff74
559#define XF86XK_RotationPB 0x1008ff75
560#define XF86XK_RotationKB 0x1008ff76
561#define XF86XK_Save 0x1008ff77
562#define XF86XK_ScrollUp 0x1008ff78
563#define XF86XK_ScrollDown 0x1008ff79
564#define XF86XK_ScrollClick 0x1008ff7a
565#define XF86XK_Send 0x1008ff7b
566#define XF86XK_Spell 0x1008ff7c
567#define XF86XK_SplitScreen 0x1008ff7d
568#define XF86XK_Support 0x1008ff7e
569#define XF86XK_TaskPane 0x1008ff7f
570#define XF86XK_Terminal 0x1008ff80
571#define XF86XK_Tools 0x1008ff81
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
577#define XF86XK_WheelButton 0x1008ff88
578#define XF86XK_Word 0x1008ff89
579#define XF86XK_Xfer 0x1008ff8a
580#define XF86XK_ZoomIn 0x1008ff8b
581#define XF86XK_ZoomOut 0x1008ff8c
583#define XF86XK_Away 0x1008ff8d
584#define XF86XK_Messenger 0x1008ff8e
585#define XF86XK_WebCam 0x1008ff8f
586#define XF86XK_MailForward 0x1008ff90
587#define XF86XK_Pictures 0x1008ff91
588#define XF86XK_Music 0x1008ff92
590#define XF86XK_Battery 0x1008ff93
591#define XF86XK_Bluetooth 0x1008ff94
592#define XF86XK_WLAN 0x1008ff95
593#define XF86XK_UWB 0x1008ff96
595#define XF86XK_AudioForward 0x1008ff97
596#define XF86XK_AudioRepeat 0x1008ff98
597#define XF86XK_AudioRandomPlay 0x1008ff99
598#define XF86XK_Subtitle 0x1008ff9a
599#define XF86XK_AudioCycleTrack 0x1008ff9b
600#define XF86XK_CycleAngle 0x1008ff9c
601#define XF86XK_FrameBack 0x1008ff9d
602#define XF86XK_FrameForward 0x1008ff9e
603#define XF86XK_Time 0x1008ff9f
604#define XF86XK_Select 0x1008ffa0
605#define XF86XK_View 0x1008ffa1
606#define XF86XK_TopMenu 0x1008ffa2
608#define XF86XK_Red 0x1008ffa3
609#define XF86XK_Green 0x1008ffa4
610#define XF86XK_Yellow 0x1008ffa5
611#define XF86XK_Blue 0x1008ffa6
613#define XF86XK_Suspend 0x1008ffa7
614#define XF86XK_Hibernate 0x1008ffa8
615#define XF86XK_TouchpadToggle 0x1008ffa9
616#define XF86XK_TouchpadOn 0x1008ffb0
617#define XF86XK_TouchpadOff 0x1008ffb1
619#define XF86XK_AudioMicMute 0x1008ffb2
621#define XF86XK_Keyboard 0x1008ffb3
623#define XF86XK_WWAN 0x1008ffb4
624#define XF86XK_RFKill 0x1008ffb5
626#define XF86XK_AudioPreset 0x1008ffb6
628#define XF86XK_RotationLockToggle 0x1008ffb7
630#define XF86XK_FullScreen 0x1008ffb8
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
647#define XF86XK_Ungrab 0x1008fe20
648#define XF86XK_ClearGrab 0x1008fe21
649#define XF86XK_Next_VMode 0x1008fe22
650#define XF86XK_Prev_VMode 0x1008fe23
651#define XF86XK_LogWindowTree 0x1008fe24
652#define XF86XK_LogGrabInfo 0x1008fe25
691#define _EVDEVK(_v) (0x10081000 + _v)
713#define XF86XK_BrightnessAuto _EVDEVK(0x0f4)
714#define XF86XK_DisplayOff _EVDEVK(0x0f5)
718#define XF86XK_Info _EVDEVK(0x166)
721#define XF86XK_AspectRatio _EVDEVK(0x177)
722#define XF86XK_DVD _EVDEVK(0x185)
723#define XF86XK_Audio _EVDEVK(0x188)
726#define XF86XK_ChannelUp _EVDEVK(0x192)
727#define XF86XK_ChannelDown _EVDEVK(0x193)
729#define XF86XK_Break _EVDEVK(0x19b)
730#define XF86XK_VideoPhone _EVDEVK(0x1a0)
734#define XF86XK_ZoomReset _EVDEVK(0x1a4)
736#define XF86XK_Editor _EVDEVK(0x1a6)
738#define XF86XK_GraphicsEditor _EVDEVK(0x1a8)
739#define XF86XK_Presentation _EVDEVK(0x1a9)
740#define XF86XK_Database _EVDEVK(0x1aa)
742#define XF86XK_Voicemail _EVDEVK(0x1ac)
743#define XF86XK_Addressbook _EVDEVK(0x1ad)
745#define XF86XK_DisplayToggle _EVDEVK(0x1af)
746#define XF86XK_SpellCheck _EVDEVK(0x1b0)
752#define XF86XK_ContextMenu _EVDEVK(0x1b6)
753#define XF86XK_MediaRepeat _EVDEVK(0x1b7)
754#define XF86XK_10ChannelsUp _EVDEVK(0x1b8)
755#define XF86XK_10ChannelsDown _EVDEVK(0x1b9)
756#define XF86XK_Images _EVDEVK(0x1ba)
757#define XF86XK_NotificationCenter _EVDEVK(0x1bc)
758#define XF86XK_PickupPhone _EVDEVK(0x1bd)
759#define XF86XK_HangupPhone _EVDEVK(0x1be)
760#define XF86XK_Fn _EVDEVK(0x1d0)
761#define XF86XK_Fn_Esc _EVDEVK(0x1d1)
762#define XF86XK_FnRightShift _EVDEVK(0x1e5)
773#define XF86XK_Numeric0 _EVDEVK(0x200)
774#define XF86XK_Numeric1 _EVDEVK(0x201)
775#define XF86XK_Numeric2 _EVDEVK(0x202)
776#define XF86XK_Numeric3 _EVDEVK(0x203)
777#define XF86XK_Numeric4 _EVDEVK(0x204)
778#define XF86XK_Numeric5 _EVDEVK(0x205)
779#define XF86XK_Numeric6 _EVDEVK(0x206)
780#define XF86XK_Numeric7 _EVDEVK(0x207)
781#define XF86XK_Numeric8 _EVDEVK(0x208)
782#define XF86XK_Numeric9 _EVDEVK(0x209)
783#define XF86XK_NumericStar _EVDEVK(0x20a)
784#define XF86XK_NumericPound _EVDEVK(0x20b)
785#define XF86XK_NumericA _EVDEVK(0x20c)
786#define XF86XK_NumericB _EVDEVK(0x20d)
787#define XF86XK_NumericC _EVDEVK(0x20e)
788#define XF86XK_NumericD _EVDEVK(0x20f)
789#define XF86XK_CameraFocus _EVDEVK(0x210)
790#define XF86XK_WPSButton _EVDEVK(0x211)
794#define XF86XK_CameraZoomIn _EVDEVK(0x215)
795#define XF86XK_CameraZoomOut _EVDEVK(0x216)
796#define XF86XK_CameraUp _EVDEVK(0x217)
797#define XF86XK_CameraDown _EVDEVK(0x218)
798#define XF86XK_CameraLeft _EVDEVK(0x219)
799#define XF86XK_CameraRight _EVDEVK(0x21a)
800#define XF86XK_AttendantOn _EVDEVK(0x21b)
801#define XF86XK_AttendantOff _EVDEVK(0x21c)
802#define XF86XK_AttendantToggle _EVDEVK(0x21d)
803#define XF86XK_LightsToggle _EVDEVK(0x21e)
804#define XF86XK_ALSToggle _EVDEVK(0x230)
806#define XF86XK_Buttonconfig _EVDEVK(0x240)
807#define XF86XK_Taskmanager _EVDEVK(0x241)
808#define XF86XK_Journal _EVDEVK(0x242)
809#define XF86XK_ControlPanel _EVDEVK(0x243)
810#define XF86XK_AppSelect _EVDEVK(0x244)
811#define XF86XK_Screensaver _EVDEVK(0x245)
812#define XF86XK_VoiceCommand _EVDEVK(0x246)
813#define XF86XK_Assistant _EVDEVK(0x247)
815#define XF86XK_EmojiPicker _EVDEVK(0x249)
816#define XF86XK_Dictate _EVDEVK(0x24a)
817#define XF86XK_CameraAccessEnable _EVDEVK(0x24b)
818#define XF86XK_CameraAccessDisable _EVDEVK(0x24c)
819#define XF86XK_CameraAccessToggle _EVDEVK(0x24d)
820#define XF86XK_BrightnessMin _EVDEVK(0x250)
821#define XF86XK_BrightnessMax _EVDEVK(0x251)
822#define XF86XK_KbdInputAssistPrev _EVDEVK(0x260)
823#define XF86XK_KbdInputAssistNext _EVDEVK(0x261)
824#define XF86XK_KbdInputAssistPrevgroup _EVDEVK(0x262)
825#define XF86XK_KbdInputAssistNextgroup _EVDEVK(0x263)
826#define XF86XK_KbdInputAssistAccept _EVDEVK(0x264)
827#define XF86XK_KbdInputAssistCancel _EVDEVK(0x265)
828#define XF86XK_RightUp _EVDEVK(0x266)
829#define XF86XK_RightDown _EVDEVK(0x267)
830#define XF86XK_LeftUp _EVDEVK(0x268)
831#define XF86XK_LeftDown _EVDEVK(0x269)
832#define XF86XK_RootMenu _EVDEVK(0x26a)
833#define XF86XK_MediaTopMenu _EVDEVK(0x26b)
834#define XF86XK_Numeric11 _EVDEVK(0x26c)
835#define XF86XK_Numeric12 _EVDEVK(0x26d)
836#define XF86XK_AudioDesc _EVDEVK(0x26e)
837#define XF86XK_3DMode _EVDEVK(0x26f)
838#define XF86XK_NextFavorite _EVDEVK(0x270)
839#define XF86XK_StopRecord _EVDEVK(0x271)
840#define XF86XK_PauseRecord _EVDEVK(0x272)
841#define XF86XK_VOD _EVDEVK(0x273)
842#define XF86XK_Unmute _EVDEVK(0x274)
843#define XF86XK_FastReverse _EVDEVK(0x275)
844#define XF86XK_SlowReverse _EVDEVK(0x276)
845#define XF86XK_Data _EVDEVK(0x277)
846#define XF86XK_OnScreenKeyboard _EVDEVK(0x278)
847#define XF86XK_PrivacyScreenToggle _EVDEVK(0x279)
848#define XF86XK_SelectiveScreenshot _EVDEVK(0x27a)
849#define XF86XK_NextElement _EVDEVK(0x27b)
850#define XF86XK_PreviousElement _EVDEVK(0x27c)
851#define XF86XK_AutopilotEngageToggle _EVDEVK(0x27d)
852#define XF86XK_MarkWaypoint _EVDEVK(0x27e)
853#define XF86XK_Sos _EVDEVK(0x27f)
854#define XF86XK_NavChart _EVDEVK(0x280)
855#define XF86XK_FishingChart _EVDEVK(0x281)
856#define XF86XK_SingleRangeRadar _EVDEVK(0x282)
857#define XF86XK_DualRangeRadar _EVDEVK(0x283)
858#define XF86XK_RadarOverlay _EVDEVK(0x284)
859#define XF86XK_TraditionalSonar _EVDEVK(0x285)
860#define XF86XK_ClearvuSonar _EVDEVK(0x286)
861#define XF86XK_SidevuSonar _EVDEVK(0x287)
862#define XF86XK_NavInfo _EVDEVK(0x288)
864#define XF86XK_Macro1 _EVDEVK(0x290)
865#define XF86XK_Macro2 _EVDEVK(0x291)
866#define XF86XK_Macro3 _EVDEVK(0x292)
867#define XF86XK_Macro4 _EVDEVK(0x293)
868#define XF86XK_Macro5 _EVDEVK(0x294)
869#define XF86XK_Macro6 _EVDEVK(0x295)
870#define XF86XK_Macro7 _EVDEVK(0x296)
871#define XF86XK_Macro8 _EVDEVK(0x297)
872#define XF86XK_Macro9 _EVDEVK(0x298)
873#define XF86XK_Macro10 _EVDEVK(0x299)
874#define XF86XK_Macro11 _EVDEVK(0x29a)
875#define XF86XK_Macro12 _EVDEVK(0x29b)
876#define XF86XK_Macro13 _EVDEVK(0x29c)
877#define XF86XK_Macro14 _EVDEVK(0x29d)
878#define XF86XK_Macro15 _EVDEVK(0x29e)
879#define XF86XK_Macro16 _EVDEVK(0x29f)
880#define XF86XK_Macro17 _EVDEVK(0x2a0)
881#define XF86XK_Macro18 _EVDEVK(0x2a1)
882#define XF86XK_Macro19 _EVDEVK(0x2a2)
883#define XF86XK_Macro20 _EVDEVK(0x2a3)
884#define XF86XK_Macro21 _EVDEVK(0x2a4)
885#define XF86XK_Macro22 _EVDEVK(0x2a5)
886#define XF86XK_Macro23 _EVDEVK(0x2a6)
887#define XF86XK_Macro24 _EVDEVK(0x2a7)
888#define XF86XK_Macro25 _EVDEVK(0x2a8)
889#define XF86XK_Macro26 _EVDEVK(0x2a9)
890#define XF86XK_Macro27 _EVDEVK(0x2aa)
891#define XF86XK_Macro28 _EVDEVK(0x2ab)
892#define XF86XK_Macro29 _EVDEVK(0x2ac)
893#define XF86XK_Macro30 _EVDEVK(0x2ad)
894#define XF86XK_MacroRecordStart _EVDEVK(0x2b0)
895#define XF86XK_MacroRecordStop _EVDEVK(0x2b1)
896#define XF86XK_MacroPresetCycle _EVDEVK(0x2b2)
897#define XF86XK_MacroPreset1 _EVDEVK(0x2b3)
898#define XF86XK_MacroPreset2 _EVDEVK(0x2b4)
899#define XF86XK_MacroPreset3 _EVDEVK(0x2b5)
900#define XF86XK_KbdLcdMenu1 _EVDEVK(0x2b8)
901#define XF86XK_KbdLcdMenu2 _EVDEVK(0x2b9)
902#define XF86XK_KbdLcdMenu3 _EVDEVK(0x2ba)
903#define XF86XK_KbdLcdMenu4 _EVDEVK(0x2bb)
904#define XF86XK_KbdLcdMenu5 _EVDEVK(0x2bc)
1060inline void checkDisplay()
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.";
1070#define checkDisplay()
1077static bool g_bInitializedMods;
1078static uint g_modXNumLock, g_modXScrollLock, g_modXModeSwitch, g_alt_mask, g_meta_mask, g_super_mask, g_hyper_mask;
1084 g_modXScrollLock = 0;
1085 g_modXModeSwitch = 0;
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;
1098 xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(QX11Info::connection());
1099 XModifierKeymap *xmk = XGetModifierMapping(QX11Info::display());
1103 int keysyms_per_keycode = 0;
1105 XDisplayKeycodes(QX11Info::display(), &min_keycode, &max_keycode);
1106 XFree(XGetKeyboardMapping(QX11Info::display(), min_keycode, 1, &keysyms_per_keycode));
1108 for (
int i = Mod1MapIndex; i < 8; i++) {
1109 uint mask = (1 << i);
1110 uint keySymX = NoSymbol;
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);
1128 g_super_mask |= mask;
1133 g_hyper_mask |= mask;
1138 g_meta_mask |= mask;
1142 g_modXNumLock |= mask;
1144 case XK_Scroll_Lock:
1145 g_modXScrollLock |= mask;
1147 case XK_Mode_switch:
1148 g_modXModeSwitch |= mask;
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;
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.";
1171 g_hyper_mask &= ~(g_super_mask | g_meta_mask | g_alt_mask);
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.";
1180 g_super_mask &= ~(g_meta_mask | g_alt_mask);
1184 if (g_meta_mask | g_alt_mask) {
1185#ifdef KKEYSERVER_DEBUG
1186 qCDebug(LOG_KKEYSERVER_X11) <<
"Meta conflicts with alt.";
1189 g_meta_mask &= ~(g_alt_mask);
1193#ifdef KKEYSERVER_DEBUG
1194 qCDebug(LOG_KKEYSERVER_X11) <<
"Meta is not set or conflicted with alt.";
1197#ifdef KKEYSERVER_DEBUG
1198 qCDebug(LOG_KKEYSERVER_X11) <<
"Using super for meta";
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";
1207 g_meta_mask = g_hyper_mask;
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;
1225 qCWarning(LOG_KKEYSERVER_X11) <<
"Your keyboard setup doesn't provide a key to use for meta. See 'xmodmap -pm' or 'xkbcomp $DISPLAY'";
1228 g_rgX11ModInfo[2].modX = g_alt_mask;
1229 g_rgX11ModInfo[3].modX = g_meta_mask;
1231 xcb_key_symbols_free(symbols);
1232 XFreeModifiermap(xmk);
1233 g_bInitializedMods =
true;
1242static bool is_keypad_key(xcb_keysym_t keysym)
1244 return keysym >= XK_KP_Space && keysym <= XK_KP_9;
1261 if (!g_bInitializedMods) {
1268 if (!g_bInitializedMods) {
1276 if (!g_bInitializedMods) {
1279 return g_modXNumLock;
1287 if (!g_bInitializedMods) {
1290 return g_modXScrollLock;
1294 if (!g_bInitializedMods) {
1297 return g_modXModeSwitch;
1305uint getModsRequired(uint sym)
1307 if (!QX11Info::isPlatformX11()) {
1308 qCWarning(LOG_KKEYSERVER_X11) <<
"X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1314 if (sym == XK_Sys_Req) {
1317 if (sym == XK_Break) {
1323 if (c.isLetter() && c.toLower() != c.toUpper() && sym == c.toUpper().unicode()) {
1328 uchar code = XKeysymToKeycode(QX11Info::display(), sym);
1333 if (sym == XKeycodeToKeysym(QX11Info::display(), code, 0)) {
1335 }
else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 1)) {
1337 }
else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 2)) {
1339 }
else if (sym == XKeycodeToKeysym(QX11Info::display(), code, 3)) {
1346#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0)
1349 if (!QX11Info::isPlatformX11()) {
1350 qCWarning(LOG_KKEYSERVER_X11) <<
"X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1360 uint modExtra = getModsRequired(sym);
1367 *keyCode = XKeysymToKeycode(QX11Info::display(), sym);
1375 if (!QX11Info::isPlatformX11()) {
1376 qCWarning(LOG_KKEYSERVER_X11) <<
"X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1383 for (
int sym : syms) {
1386 uint modExtra = getModsRequired(sym);
1392 keyCodes.
append(XKeysymToKeycode(QX11Info::display(), sym));
1397#if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(6, 0)
1400 int symQt = keyQt &
~Qt::KeyboardModifierMask;
1404 *keySym = XK_KP_0 + (symQt -
Qt::Key_0);
1408 if (symQt < 0x1000) {
1414 for (
const TransKey &tk : g_rgQtToSymX) {
1415 if (tk.keySymQt == symQt) {
1419 *keySym = tk.keySymX;
1435 int symQt = keyQt &
~Qt::KeyboardModifierMask;
1444 if (symQt < 0x1000) {
1450 for (
const TransKey &tk : g_rgQtToSymX) {
1451 if (tk.keySymQt == symQt) {
1466 if (keySym >= XK_KP_0 && keySym <= XK_KP_9) {
1468 *keyQt =
Qt::Key_0 + ((int)keySym - XK_KP_0);
1469 }
else if (keySym < 0x1000) {
1470 if (keySym >=
'a' && keySym <=
'z') {
1477 else if (keySym < 0x3000) {
1482 for (
const TransKey &tk : g_rgQtToSymX) {
1483 if (tk.keySymX == keySym) {
1484 *keyQt = tk.keySymQt;
1496 if (is_keypad_key(keySym)) {
1506 if (!g_bInitializedMods) {
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;
1526 if (!g_bInitializedMods) {
1531 for (
int i = 0; i < 4; i++) {
1532 if (modX & g_rgX11ModInfo[i].modX) {
1533 *modQt |= g_rgX11ModInfo[i].modQt;
1540bool codeXToSym(uchar codeX, uint modX, uint *sym)
1542 if (!QX11Info::isPlatformX11()) {
1543 qCWarning(LOG_KKEYSERVER_X11) <<
"X11 implementation of KKeyServer accessed from non-X11 platform! This is an application bug.";
1547 XKeyPressedEvent
event;
1551 event.type = KeyPress;
1552 event.display = QX11Info::display();
1554 event.keycode = codeX;
1556 XLookupString(&event,
nullptr, 0, &keySym,
nullptr);
1557 *sym = (uint)keySym;
1568 Q_ASSERT(e->type == KeyPress || e->type == KeyRelease);
1570 uchar keyCodeX = e->xkey.keycode;
1571 uint keyModX = e->xkey.state & (
accelModMaskX() | MODE_SWITCH);
1575 XLookupString((XKeyEvent *)e, buffer, 15, &keySym,
nullptr);
1576 uint keySymX = (uint)keySym;
1581 uint sym = XKeycodeToKeysym(QX11Info::display(), keyCodeX, 0);
1584 if (sym >= XK_KP_Space && sym <= XK_KP_9) {
1588 case XK_KP_Multiply:
1590 case XK_KP_Subtract:
1595 keyModX &= ~modXShift();
1608 if ((e->response_type & ~0x80) != XCB_KEY_PRESS && (e->response_type & ~0x80) != XCB_KEY_RELEASE) {
1616 const uint16_t keyModX = e->state & (
accelModMaskX() | MODE_SWITCH);
1618 xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(QX11Info::connection());
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;
1626 if ((e->state & XCB_MOD_MASK_SHIFT)) {
1639 static const int FirstLevelShift = 1;
1640 keySymX = xcb_key_symbols_get_keysym(symbols, e->detail, FirstLevelShift);
1643 *keyQt &=
~Qt::ShiftModifier;
1646 xcb_key_symbols_free(symbols);