• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.9.5 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

kkeyserver_x11.cpp
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
00003 
00004     Win32 port:
00005     Copyright (C) 2004 Jarosław Staniek <staniek@kde.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "kkeyserver_x11.h"
00024 
00025 #include "kdebug.h"
00026 #include "klocale.h"
00027 
00028 #include <QX11Info>
00029 # define XK_MISCELLANY
00030 # define XK_XKB_KEYS
00031 # include <X11/X.h>
00032 # include <X11/Xlib.h>
00033 # include <X11/Xutil.h>
00034 # include <X11/keysymdef.h>
00035 # define X11_ONLY(arg) arg, //allows to omit an argument
00036 
00037 // #define KKEYSERVER_DEBUG 1
00038 
00039 
00040 
00041 namespace KKeyServer
00042 {
00043 
00044 //---------------------------------------------------------------------
00045 // Data Structures
00046 //---------------------------------------------------------------------
00047 
00048 struct Mod
00049 {
00050     int m_mod;
00051 };
00052 
00053 //---------------------------------------------------------------------
00054 // Array Structures
00055 //---------------------------------------------------------------------
00056 
00057 struct X11ModInfo
00058 {
00059     int modQt;
00060     int modX;
00061 };
00062 
00063 struct SymVariation
00064 {
00065     uint sym, symVariation;
00066     bool bActive;
00067 };
00068 
00069 struct SymName
00070 {
00071     uint sym;
00072     const char* psName;
00073 };
00074 
00075 struct TransKey {
00076     int keySymQt;
00077     uint keySymX;
00078 };
00079 
00080 //---------------------------------------------------------------------
00081 // Arrays
00082 //---------------------------------------------------------------------
00083 
00084 static X11ModInfo g_rgX11ModInfo[4] =
00085 {
00086     { Qt::SHIFT,   X11_ONLY(ShiftMask) },
00087     { Qt::CTRL,    X11_ONLY(ControlMask) },
00088     { Qt::ALT,     X11_ONLY(Mod1Mask) },
00089     { Qt::META,    X11_ONLY(Mod4Mask) }
00090 };
00091 
00092 // Special Names List
00093 static const SymName g_rgSymNames[] = {
00094     { XK_ISO_Left_Tab, "Backtab" },
00095     { XK_BackSpace,    I18N_NOOP("Backspace") },
00096     { XK_Sys_Req,      I18N_NOOP("SysReq") },
00097     { XK_Caps_Lock,    I18N_NOOP("CapsLock") },
00098     { XK_Num_Lock,     I18N_NOOP("NumLock") },
00099     { XK_Scroll_Lock,  I18N_NOOP("ScrollLock") },
00100     { XK_Prior,        I18N_NOOP("PageUp") },
00101     { XK_Next,         I18N_NOOP("PageDown") },
00102 #ifdef sun
00103     { XK_F11,          I18N_NOOP("Stop") },
00104     { XK_F12,          I18N_NOOP("Again") },
00105     { XK_F13,          I18N_NOOP("Props") },
00106     { XK_F14,          I18N_NOOP("Undo") },
00107     { XK_F15,          I18N_NOOP("Front") },
00108     { XK_F16,          I18N_NOOP("Copy") },
00109     { XK_F17,          I18N_NOOP("Open") },
00110     { XK_F18,          I18N_NOOP("Paste") },
00111     { XK_F19,          I18N_NOOP("Find") },
00112     { XK_F20,          I18N_NOOP("Cut") },
00113     { XK_F22,          I18N_NOOP("Print") },
00114 #endif
00115     { 0, 0 }
00116 };
00117 
00118 // These are the X equivalents to the Qt keycodes 0x1000 - 0x1026
00119 static const TransKey g_rgQtToSymX[] =
00120 {
00121     { Qt::Key_Escape,     XK_Escape },
00122     { Qt::Key_Tab,        XK_Tab },
00123     { Qt::Key_Backtab,    XK_ISO_Left_Tab },
00124     { Qt::Key_Backspace,  XK_BackSpace },
00125     { Qt::Key_Return,     XK_Return },
00126     { Qt::Key_Enter,      XK_KP_Enter },
00127     { Qt::Key_Insert,     XK_Insert },
00128     { Qt::Key_Delete,     XK_Delete },
00129     { Qt::Key_Pause,      XK_Pause },
00130 #ifdef sun
00131     { Qt::Key_Print,      XK_F22 },
00132 #else
00133     { Qt::Key_Print,      XK_Print },
00134 #endif
00135     { Qt::Key_SysReq,     XK_Sys_Req },
00136     { Qt::Key_Home,       XK_Home },
00137     { Qt::Key_End,        XK_End },
00138     { Qt::Key_Left,       XK_Left },
00139     { Qt::Key_Up,         XK_Up },
00140     { Qt::Key_Right,      XK_Right },
00141     { Qt::Key_Down,       XK_Down },
00142     { Qt::Key_PageUp,      XK_Prior },
00143     { Qt::Key_PageDown,       XK_Next },
00144     //{ Qt::Key_Shift,      0 },
00145     //{ Qt::Key_Control,    0 },
00146     //{ Qt::Key_Meta,       0 },
00147     //{ Qt::Key_Alt,        0 },
00148     { Qt::Key_CapsLock,   XK_Caps_Lock },
00149     { Qt::Key_NumLock,    XK_Num_Lock },
00150     { Qt::Key_ScrollLock, XK_Scroll_Lock },
00151     { Qt::Key_F1,         XK_F1 },
00152     { Qt::Key_F2,         XK_F2 },
00153     { Qt::Key_F3,         XK_F3 },
00154     { Qt::Key_F4,         XK_F4 },
00155     { Qt::Key_F5,         XK_F5 },
00156     { Qt::Key_F6,         XK_F6 },
00157     { Qt::Key_F7,         XK_F7 },
00158     { Qt::Key_F8,         XK_F8 },
00159     { Qt::Key_F9,         XK_F9 },
00160     { Qt::Key_F10,        XK_F10 },
00161     { Qt::Key_F11,        XK_F11 },
00162     { Qt::Key_F12,        XK_F12 },
00163     { Qt::Key_F13,        XK_F13 },
00164     { Qt::Key_F14,        XK_F14 },
00165     { Qt::Key_F15,        XK_F15 },
00166     { Qt::Key_F16,        XK_F16 },
00167     { Qt::Key_F17,        XK_F17 },
00168     { Qt::Key_F18,        XK_F18 },
00169     { Qt::Key_F19,        XK_F19 },
00170     { Qt::Key_F20,        XK_F20 },
00171     { Qt::Key_F21,        XK_F21 },
00172     { Qt::Key_F22,        XK_F22 },
00173     { Qt::Key_F23,        XK_F23 },
00174     { Qt::Key_F24,        XK_F24 },
00175     { Qt::Key_F25,        XK_F25 },
00176     { Qt::Key_F26,        XK_F26 },
00177     { Qt::Key_F27,        XK_F27 },
00178     { Qt::Key_F28,        XK_F28 },
00179     { Qt::Key_F29,        XK_F29 },
00180     { Qt::Key_F30,        XK_F30 },
00181     { Qt::Key_F31,        XK_F31 },
00182     { Qt::Key_F32,        XK_F32 },
00183     { Qt::Key_F33,        XK_F33 },
00184     { Qt::Key_F34,        XK_F34 },
00185     { Qt::Key_F35,        XK_F35 },
00186     { Qt::Key_Super_L,    XK_Super_L },
00187     { Qt::Key_Super_R,    XK_Super_R },
00188     { Qt::Key_Menu,       XK_Menu },
00189     { Qt::Key_Hyper_L,    XK_Hyper_L },
00190     { Qt::Key_Hyper_R,    XK_Hyper_R },
00191     { Qt::Key_Help,       XK_Help },
00192     //{ Qt::Key_Direction_L, XK_Direction_L }, These keys don't exist in X11
00193     //{ Qt::Key_Direction_R, XK_Direction_R },
00194 
00195     { '/',                XK_KP_Divide },
00196     { '*',                XK_KP_Multiply },
00197     { '-',                XK_KP_Subtract },
00198     { '+',                XK_KP_Add },
00199     { Qt::Key_Return,     XK_KP_Enter }
00200 
00201 // the next lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining some special
00202 // multimedia keys. They are included here as not every system has them.
00203 #define XF86XK_MonBrightnessUp     0x1008FF02
00204 #define XF86XK_MonBrightnessDown   0x1008FF03
00205 #define XF86XK_KbdLightOnOff       0x1008FF04
00206 #define XF86XK_KbdBrightnessUp     0x1008FF05
00207 #define XF86XK_KbdBrightnessDown   0x1008FF06
00208 #define XF86XK_Standby             0x1008FF10
00209 #define XF86XK_AudioLowerVolume    0x1008FF11
00210 #define XF86XK_AudioMute           0x1008FF12
00211 #define XF86XK_AudioRaiseVolume    0x1008FF13
00212 #define XF86XK_AudioPlay           0x1008FF14
00213 #define XF86XK_AudioStop           0x1008FF15
00214 #define XF86XK_AudioPrev           0x1008FF16
00215 #define XF86XK_AudioNext           0x1008FF17
00216 #define XF86XK_HomePage            0x1008FF18
00217 #define XF86XK_Mail                0x1008FF19
00218 #define XF86XK_Start               0x1008FF1A
00219 #define XF86XK_Search              0x1008FF1B
00220 #define XF86XK_AudioRecord         0x1008FF1C
00221 #define XF86XK_Calculator          0x1008FF1D
00222 #define XF86XK_Memo                0x1008FF1E
00223 #define XF86XK_ToDoList            0x1008FF1F
00224 #define XF86XK_Calendar            0x1008FF20
00225 #define XF86XK_PowerDown           0x1008FF21
00226 #define XF86XK_ContrastAdjust      0x1008FF22
00227 #define XF86XK_Back                0x1008FF26
00228 #define XF86XK_Forward             0x1008FF27
00229 #define XF86XK_Stop                0x1008FF28
00230 #define XF86XK_Refresh             0x1008FF29
00231 #define XF86XK_PowerOff            0x1008FF2A
00232 #define XF86XK_WakeUp              0x1008FF2B
00233 #define XF86XK_Eject               0x1008FF2C
00234 #define XF86XK_ScreenSaver         0x1008FF2D
00235 #define XF86XK_WWW                 0x1008FF2E
00236 #define XF86XK_Sleep               0x1008FF2F
00237 #define XF86XK_Favorites           0x1008FF30
00238 #define XF86XK_AudioPause          0x1008FF31
00239 #define XF86XK_AudioMedia          0x1008FF32
00240 #define XF86XK_MyComputer          0x1008FF33
00241 #define XF86XK_LightBulb           0x1008FF35
00242 #define XF86XK_Shop                0x1008FF36
00243 #define XF86XK_History             0x1008FF37
00244 #define XF86XK_OpenURL             0x1008FF38
00245 #define XF86XK_AddFavorite         0x1008FF39
00246 #define XF86XK_HotLinks            0x1008FF3A
00247 #define XF86XK_BrightnessAdjust    0x1008FF3B
00248 #define XF86XK_Finance             0x1008FF3C
00249 #define XF86XK_Community           0x1008FF3D
00250 #define XF86XK_AudioRewind         0x1008FF3E
00251 #define XF86XK_BackForward         0x1008FF3F
00252 #define XF86XK_Launch0             0x1008FF40
00253 #define XF86XK_Launch1             0x1008FF41
00254 #define XF86XK_Launch2             0x1008FF42
00255 #define XF86XK_Launch3             0x1008FF43
00256 #define XF86XK_Launch4             0x1008FF44
00257 #define XF86XK_Launch5             0x1008FF45
00258 #define XF86XK_Launch6             0x1008FF46
00259 #define XF86XK_Launch7             0x1008FF47
00260 #define XF86XK_Launch8             0x1008FF48
00261 #define XF86XK_Launch9             0x1008FF49
00262 #define XF86XK_LaunchA             0x1008FF4A
00263 #define XF86XK_LaunchB             0x1008FF4B
00264 #define XF86XK_LaunchC             0x1008FF4C
00265 #define XF86XK_LaunchD             0x1008FF4D
00266 #define XF86XK_LaunchE             0x1008FF4E
00267 #define XF86XK_LaunchF             0x1008FF4F
00268 #define XF86XK_ApplicationLeft     0x1008FF50
00269 #define XF86XK_ApplicationRight    0x1008FF51
00270 #define XF86XK_Book                0x1008FF52
00271 #define XF86XK_CD                  0x1008FF53
00272 #define XF86XK_Calculater          0x1008FF54
00273 #define XF86XK_Clear               0x1008FF55
00274 #define XF86XK_ClearGrab           0x1008FE21
00275 #define XF86XK_Close               0x1008FF56
00276 #define XF86XK_Copy                0x1008FF57
00277 #define XF86XK_Cut                 0x1008FF58
00278 #define XF86XK_Display             0x1008FF59
00279 #define XF86XK_DOS                 0x1008FF5A
00280 #define XF86XK_Documents           0x1008FF5B
00281 #define XF86XK_Excel               0x1008FF5C
00282 #define XF86XK_Explorer            0x1008FF5D
00283 #define XF86XK_Game                0x1008FF5E
00284 #define XF86XK_Go                  0x1008FF5F
00285 #define XF86XK_iTouch              0x1008FF60
00286 #define XF86XK_LogOff              0x1008FF61
00287 #define XF86XK_Market              0x1008FF62
00288 #define XF86XK_Meeting             0x1008FF63
00289 #define XF86XK_MenuKB              0x1008FF65
00290 #define XF86XK_MenuPB              0x1008FF66
00291 #define XF86XK_MySites             0x1008FF67
00292 #define XF86XK_News                0x1008FF69
00293 #define XF86XK_OfficeHome          0x1008FF6A
00294 #define XF86XK_Option              0x1008FF6C
00295 #define XF86XK_Paste               0x1008FF6D
00296 #define XF86XK_Phone               0x1008FF6E
00297 #define XF86XK_Reply               0x1008FF72
00298 #define XF86XK_Reload              0x1008FF73
00299 #define XF86XK_RotateWindows       0x1008FF74
00300 #define XF86XK_RotationPB          0x1008FF75
00301 #define XF86XK_RotationKB          0x1008FF76
00302 #define XF86XK_Save                0x1008FF77
00303 #define XF86XK_Send                0x1008FF7B
00304 #define XF86XK_Spell               0x1008FF7C
00305 #define XF86XK_SplitScreen         0x1008FF7D
00306 #define XF86XK_Support             0x1008FF7E
00307 #define XF86XK_TaskPane            0x1008FF7F
00308 #define XF86XK_Terminal            0x1008FF80
00309 #define XF86XK_Tools               0x1008FF81
00310 #define XF86XK_Travel              0x1008FF82
00311 #define XF86XK_Video               0x1008FF87
00312 #define XF86XK_Word                0x1008FF89
00313 #define XF86XK_Xfer                0x1008FF8A
00314 #define XF86XK_ZoomIn              0x1008FF8B
00315 #define XF86XK_ZoomOut             0x1008FF8C
00316 #define XF86XK_Away                0x1008FF8D
00317 #define XF86XK_Messenger           0x1008FF8E
00318 #define XF86XK_WebCam              0x1008FF8F
00319 #define XF86XK_MailForward         0x1008FF90
00320 #define XF86XK_Pictures            0x1008FF91
00321 #define XF86XK_Music               0x1008FF92
00322 #define XF86XK_Battery             0x1008FF93
00323 #define XF86XK_Bluetooth           0x1008FF94
00324 #define XF86XK_WLAN                0x1008FF95
00325 #define XF86XK_UWB                 0x1008FF96
00326 #define XF86XK_AudioForward        0x1008FF97
00327 #define XF86XK_AudioRepeat         0x1008FF98
00328 #define XF86XK_AudioRandomPlay     0x1008FF99
00329 #define XF86XK_Subtitle            0x1008FF9A
00330 #define XF86XK_AudioCycleTrack     0x1008FF9B
00331 #define XF86XK_Time                0x1008FF9F
00332 #define XF86XK_Select              0x1008FFA0
00333 #define XF86XK_View                0x1008FFA1
00334 #define XF86XK_TopMenu             0x1008FFA2
00335 #define XF86XK_Suspend             0x1008FFA7
00336 #define XF86XK_Hibernate           0x1008FFA8
00337 // end of XF86keysyms.h
00338         ,
00339 
00340     // All of the stuff below really has to match qkeymapper_x11.cpp in Qt!
00341     { Qt::Key_Back,       XF86XK_Back },
00342     { Qt::Key_Forward,    XF86XK_Forward },
00343     { Qt::Key_Stop,       XF86XK_Stop },
00344     { Qt::Key_Refresh,    XF86XK_Refresh },
00345     { Qt::Key_Favorites,  XF86XK_Favorites },
00346     { Qt::Key_LaunchMedia, XF86XK_AudioMedia },
00347     { Qt::Key_OpenUrl,    XF86XK_OpenURL },
00348     { Qt::Key_HomePage,   XF86XK_HomePage },
00349     { Qt::Key_Search,     XF86XK_Search },
00350     { Qt::Key_VolumeDown, XF86XK_AudioLowerVolume },
00351     { Qt::Key_VolumeMute, XF86XK_AudioMute },
00352     { Qt::Key_VolumeUp,   XF86XK_AudioRaiseVolume },
00353     { Qt::Key_MediaPlay,  XF86XK_AudioPlay },
00354     { Qt::Key_MediaStop,  XF86XK_AudioStop },
00355     { Qt::Key_MediaPrevious,  XF86XK_AudioPrev },
00356     { Qt::Key_MediaNext,  XF86XK_AudioNext },
00357     { Qt::Key_MediaRecord, XF86XK_AudioRecord },
00358     { Qt::Key_LaunchMail, XF86XK_Mail },
00359     { Qt::Key_Launch0,    XF86XK_MyComputer },
00360     { Qt::Key_Launch1,    XF86XK_Calculator },
00361     { Qt::Key_Memo,    XF86XK_Memo },
00362     { Qt::Key_ToDoList,    XF86XK_ToDoList },
00363     { Qt::Key_Calendar,    XF86XK_Calendar },
00364     { Qt::Key_PowerDown,    XF86XK_PowerDown },
00365     { Qt::Key_ContrastAdjust,    XF86XK_ContrastAdjust },
00366     { Qt::Key_Standby,    XF86XK_Standby },
00367     { Qt::Key_MonBrightnessUp,  XF86XK_MonBrightnessUp },
00368     { Qt::Key_MonBrightnessDown,  XF86XK_MonBrightnessDown },
00369     { Qt::Key_KeyboardLightOnOff,  XF86XK_KbdLightOnOff },
00370     { Qt::Key_KeyboardBrightnessUp,  XF86XK_KbdBrightnessUp },
00371     { Qt::Key_KeyboardBrightnessDown,  XF86XK_KbdBrightnessDown },
00372     { Qt::Key_PowerOff,  XF86XK_PowerOff },
00373     { Qt::Key_WakeUp,  XF86XK_WakeUp },
00374     { Qt::Key_Eject,  XF86XK_Eject },
00375     { Qt::Key_ScreenSaver,  XF86XK_ScreenSaver },
00376     { Qt::Key_WWW,  XF86XK_WWW },
00377     { Qt::Key_Sleep,  XF86XK_Sleep },
00378     { Qt::Key_LightBulb,  XF86XK_LightBulb },
00379     { Qt::Key_Shop,  XF86XK_Shop },
00380     { Qt::Key_History,  XF86XK_History },
00381     { Qt::Key_AddFavorite,  XF86XK_AddFavorite },
00382     { Qt::Key_HotLinks,  XF86XK_HotLinks },
00383     { Qt::Key_BrightnessAdjust,  XF86XK_BrightnessAdjust },
00384     { Qt::Key_Finance,  XF86XK_Finance },
00385     { Qt::Key_Community,  XF86XK_Community },
00386     { Qt::Key_AudioRewind,  XF86XK_AudioRewind },
00387     { Qt::Key_BackForward,  XF86XK_BackForward },
00388     { Qt::Key_ApplicationLeft,  XF86XK_ApplicationLeft },
00389     { Qt::Key_ApplicationRight,  XF86XK_ApplicationRight },
00390     { Qt::Key_Book,  XF86XK_Book },
00391     { Qt::Key_CD,  XF86XK_CD },
00392     { Qt::Key_Calculator,  XF86XK_Calculater },
00393     { Qt::Key_Clear,  XF86XK_Clear },
00394     { Qt::Key_ClearGrab,  XF86XK_ClearGrab },
00395     { Qt::Key_Close,  XF86XK_Close },
00396     { Qt::Key_Copy,  XF86XK_Copy },
00397     { Qt::Key_Cut,  XF86XK_Cut },
00398     { Qt::Key_Display,  XF86XK_Display },
00399     { Qt::Key_DOS,  XF86XK_DOS },
00400     { Qt::Key_Documents,  XF86XK_Documents },
00401     { Qt::Key_Excel,  XF86XK_Excel },
00402     { Qt::Key_Explorer,  XF86XK_Explorer },
00403     { Qt::Key_Game,  XF86XK_Game },
00404     { Qt::Key_Go,  XF86XK_Go },
00405     { Qt::Key_iTouch,  XF86XK_iTouch },
00406     { Qt::Key_LogOff,  XF86XK_LogOff },
00407     { Qt::Key_Market,  XF86XK_Market },
00408     { Qt::Key_Meeting,  XF86XK_Meeting },
00409     { Qt::Key_MenuKB,  XF86XK_MenuKB },
00410     { Qt::Key_MenuPB,  XF86XK_MenuPB },
00411     { Qt::Key_MySites,  XF86XK_MySites },
00412     { Qt::Key_News,  XF86XK_News },
00413     { Qt::Key_OfficeHome,  XF86XK_OfficeHome },
00414     { Qt::Key_Option,  XF86XK_Option },
00415     { Qt::Key_Paste,  XF86XK_Paste },
00416     { Qt::Key_Phone,  XF86XK_Phone },
00417     { Qt::Key_Reply,  XF86XK_Reply },
00418     { Qt::Key_Reload,  XF86XK_Reload },
00419     { Qt::Key_RotateWindows,  XF86XK_RotateWindows },
00420     { Qt::Key_RotationPB,  XF86XK_RotationPB },
00421     { Qt::Key_RotationKB,  XF86XK_RotationKB },
00422     { Qt::Key_Save,  XF86XK_Save },
00423     { Qt::Key_Send,  XF86XK_Send },
00424     { Qt::Key_Spell,  XF86XK_Spell },
00425     { Qt::Key_SplitScreen,  XF86XK_SplitScreen },
00426     { Qt::Key_Support,  XF86XK_Support },
00427     { Qt::Key_TaskPane,  XF86XK_TaskPane },
00428     { Qt::Key_Terminal,  XF86XK_Terminal },
00429     { Qt::Key_Tools,  XF86XK_Tools },
00430     { Qt::Key_Travel,  XF86XK_Travel },
00431     { Qt::Key_Video,  XF86XK_Video },
00432     { Qt::Key_Word,  XF86XK_Word },
00433     { Qt::Key_Xfer,  XF86XK_Xfer },
00434     { Qt::Key_ZoomIn,  XF86XK_ZoomIn },
00435     { Qt::Key_ZoomOut,  XF86XK_ZoomOut },
00436     { Qt::Key_Away,  XF86XK_Away },
00437     { Qt::Key_Messenger,  XF86XK_Messenger },
00438     { Qt::Key_WebCam,  XF86XK_WebCam },
00439     { Qt::Key_MailForward,  XF86XK_MailForward },
00440     { Qt::Key_Pictures,  XF86XK_Pictures },
00441     { Qt::Key_Music,  XF86XK_Music },
00442     { Qt::Key_Battery,  XF86XK_Battery },
00443     { Qt::Key_Bluetooth,  XF86XK_Bluetooth },
00444     { Qt::Key_WLAN,  XF86XK_WLAN },
00445     { Qt::Key_UWB,  XF86XK_UWB },
00446     { Qt::Key_AudioForward,  XF86XK_AudioForward },
00447     { Qt::Key_AudioRepeat,  XF86XK_AudioRepeat },
00448     { Qt::Key_AudioRandomPlay,  XF86XK_AudioRandomPlay },
00449     { Qt::Key_Subtitle,  XF86XK_Subtitle },
00450     { Qt::Key_AudioCycleTrack,  XF86XK_AudioCycleTrack },
00451     { Qt::Key_Time,  XF86XK_Time },
00452     { Qt::Key_Select,  XF86XK_Select },
00453     { Qt::Key_View,  XF86XK_View },
00454     { Qt::Key_TopMenu,  XF86XK_TopMenu },
00455     { Qt::Key_Bluetooth,  XF86XK_Bluetooth },
00456     { Qt::Key_Suspend,  XF86XK_Suspend },
00457     { Qt::Key_Hibernate,  XF86XK_Hibernate },
00458     { Qt::Key_Launch2,    XF86XK_Launch0 },
00459     { Qt::Key_Launch3,    XF86XK_Launch1 },
00460     { Qt::Key_Launch4,    XF86XK_Launch2 },
00461     { Qt::Key_Launch5,    XF86XK_Launch3 },
00462     { Qt::Key_Launch6,    XF86XK_Launch4 },
00463     { Qt::Key_Launch7,    XF86XK_Launch5 },
00464     { Qt::Key_Launch8,    XF86XK_Launch6 },
00465     { Qt::Key_Launch9,    XF86XK_Launch7 },
00466     { Qt::Key_LaunchA,    XF86XK_Launch8 },
00467     { Qt::Key_LaunchB,    XF86XK_Launch9 },
00468     { Qt::Key_LaunchC,    XF86XK_LaunchA },
00469     { Qt::Key_LaunchD,    XF86XK_LaunchB },
00470     { Qt::Key_LaunchE,    XF86XK_LaunchC },
00471     { Qt::Key_LaunchF,    XF86XK_LaunchD },
00472 };
00473 
00474 //---------------------------------------------------------------------
00475 // Debugging
00476 //---------------------------------------------------------------------
00477 #ifndef NDEBUG
00478 inline void checkDisplay()
00479 {
00480     // Some non-GUI apps might try to use us.
00481     if ( !QX11Info::display() ) {
00482         kError() << "QX11Info::display() returns 0.  I'm probably going to crash now." << endl;
00483         kError() << "If this is a KApplication initialized without GUI stuff, change it to be "
00484                     "initialized with GUI stuff." << endl;
00485     }
00486 }
00487 #else // NDEBUG
00488 # define checkDisplay()
00489 #endif
00490 
00491 //---------------------------------------------------------------------
00492 // Initialization
00493 //---------------------------------------------------------------------
00494 
00495 static bool g_bInitializedMods;
00496 static uint g_modXNumLock, g_modXScrollLock, g_modXModeSwitch, g_alt_mask, g_meta_mask, g_super_mask, g_hyper_mask;
00497 
00498 bool initializeMods()
00499 {
00500     // Reinitialize the masks
00501     g_modXNumLock = 0;
00502     g_modXScrollLock = 0;
00503     g_modXModeSwitch = 0;
00504     g_alt_mask = 0;
00505     g_meta_mask = 0;
00506     g_super_mask = 0;
00507     g_hyper_mask = 0;
00508 
00509     checkDisplay();
00510     XModifierKeymap* xmk = XGetModifierMapping( QX11Info::display() );
00511 
00512     int min_keycode, max_keycode;
00513     int keysyms_per_keycode = 0;
00514 
00515     XDisplayKeycodes( QX11Info::display(), &min_keycode, &max_keycode );
00516     XFree( XGetKeyboardMapping( QX11Info::display(), min_keycode, 1, &keysyms_per_keycode ));
00517 
00518     for( int i = Mod1MapIndex; i < 8; i++ ) {
00519         uint mask = (1 << i);
00520         uint keySymX = NoSymbol;
00521 
00522         // This used to be only XKeycodeToKeysym( ... , 0 ), but that fails with XFree4.3.99
00523         // and X.org R6.7 , where for some reason only ( ... , 1 ) works. I have absolutely no
00524         // idea what the problem is, but searching all possibilities until something valid is
00525         // found fixes the problem.
00526         for( int j = 0; j < xmk->max_keypermod; ++j ) {
00527 
00528             for( int k = 0; k < keysyms_per_keycode; ++k ) {
00529 
00530                 keySymX = XKeycodeToKeysym( QX11Info::display(), xmk->modifiermap[xmk->max_keypermod * i + j], k );
00531 
00532                 switch( keySymX ) {
00533                     case XK_Alt_L:
00534                     case XK_Alt_R:       g_alt_mask |= mask; break;
00535 
00536                     case XK_Super_L:
00537                     case XK_Super_R:     g_super_mask |= mask; break;
00538 
00539                     case XK_Hyper_L:
00540                     case XK_Hyper_R:     g_hyper_mask |= mask; break;
00541 
00542                     case XK_Meta_L:
00543                     case XK_Meta_R:      g_meta_mask |= mask; break;
00544 
00545                     case XK_Num_Lock:    g_modXNumLock |= mask; break;
00546                     case XK_Scroll_Lock: g_modXScrollLock |= mask; break;
00547                     case XK_Mode_switch: g_modXModeSwitch |= mask; break;
00548                 }
00549             }
00550         }
00551     }
00552 
00553 #ifdef KKEYSERVER_DEBUG
00554     kDebug() << "Alt:" << g_alt_mask;
00555     kDebug() << "Meta:" << g_meta_mask;
00556     kDebug() << "Super:" << g_super_mask;
00557     kDebug() << "Hyper:" << g_hyper_mask;
00558     kDebug() << "NumLock:" << g_modXNumLock;
00559     kDebug() << "ScrollLock:" << g_modXScrollLock;
00560     kDebug() << "ModeSwitch:" << g_modXModeSwitch;
00561 #endif
00562 
00563     // Check if hyper overlaps with super or meta or alt
00564     if (g_hyper_mask&(g_super_mask|g_meta_mask|g_alt_mask)) {
00565 #ifdef KKEYSERVER_DEBUG
00566         kDebug() << "Hyper conflicts with super, meta or alt.";
00567 #endif
00568         // Remove the conflicting masks
00569         g_hyper_mask &= ~(g_super_mask|g_meta_mask|g_alt_mask);
00570     }
00571 
00572     // Check if super overlaps with meta or alt
00573     if (g_super_mask&(g_meta_mask|g_alt_mask)) {
00574 #ifdef KKEYSERVER_DEBUG
00575         kDebug() << "Super conflicts with meta or alt.";
00576 #endif
00577         // Remove the conflicting masks
00578         g_super_mask &= ~(g_meta_mask|g_alt_mask);
00579     }
00580 
00581 
00582     // Check if meta overlaps with alt
00583     if (g_meta_mask|g_alt_mask) {
00584 #ifdef KKEYSERVER_DEBUG
00585         kDebug() << "Meta conflicts with alt.";
00586 #endif
00587         // Remove the conflicting masks
00588         g_meta_mask &= ~(g_alt_mask);
00589     }
00590 
00591     if (!g_meta_mask) {
00592 #ifdef KKEYSERVER_DEBUG
00593         kDebug() << "Meta is not set or conflicted with alt.";
00594 #endif
00595         if (g_super_mask) {
00596 #ifdef KKEYSERVER_DEBUG
00597             kDebug() << "Using super for meta";
00598 #endif
00599             // Use Super
00600             g_meta_mask = g_super_mask;
00601         } else if (g_hyper_mask) {
00602 #ifdef KKEYSERVER_DEBUG
00603             kDebug() << "Using hyper for meta";
00604 #endif
00605             // User Hyper
00606             g_meta_mask = g_hyper_mask;
00607         } else {
00608             // ???? Nothing left
00609             g_meta_mask = 0;
00610         }
00611     }
00612 
00613 #ifdef KKEYSERVER_DEBUG
00614     kDebug() << "Alt:" << g_alt_mask;
00615     kDebug() << "Meta:" << g_meta_mask;
00616     kDebug() << "Super:" << g_super_mask;
00617     kDebug() << "Hyper:" << g_hyper_mask;
00618     kDebug() << "NumLock:" << g_modXNumLock;
00619     kDebug() << "ScrollLock:" << g_modXScrollLock;
00620     kDebug() << "ModeSwitch:" << g_modXModeSwitch;
00621 #endif
00622 
00623     if (!g_meta_mask) {
00624         kWarning() << "Your keyboard setup doesn't provide a key to use for meta. See 'xmodmap -pm' or 'xkbcomp $DISPLAY'";
00625     }
00626 
00627     g_rgX11ModInfo[2].modX = g_alt_mask;
00628     g_rgX11ModInfo[3].modX = g_meta_mask;
00629 
00630     XFreeModifiermap( xmk );
00631     g_bInitializedMods = true;
00632 
00633     return true;
00634 }
00635 
00636 
00637 //---------------------------------------------------------------------
00638 // Public functions
00639 //---------------------------------------------------------------------
00640 
00641 
00642 uint modXShift()      { return ShiftMask; }
00643 uint modXCtrl()       { return ControlMask; }
00644 uint modXAlt()        { if( !g_bInitializedMods ) { initializeMods(); } return g_alt_mask; }
00645 uint modXMeta()       { if( !g_bInitializedMods ) { initializeMods(); } return g_meta_mask; }
00646 
00647 uint modXNumLock()    { if( !g_bInitializedMods ) { initializeMods(); } return g_modXNumLock; }
00648 uint modXLock()       { return LockMask; }
00649 uint modXScrollLock() { if( !g_bInitializedMods ) { initializeMods(); } return g_modXScrollLock; }
00650 uint modXModeSwitch() { if( !g_bInitializedMods ) { initializeMods(); } return g_modXModeSwitch; }
00651 
00652 bool keyboardHasMetaKey() { return modXMeta() != 0; }
00653 
00654 
00655 uint getModsRequired(uint sym)
00656 {
00657     uint mod = 0;
00658 
00659     // FIXME: This might not be true on all keyboard layouts!
00660     if( sym == XK_Sys_Req ) return Qt::ALT;
00661     if( sym == XK_Break ) return Qt::CTRL;
00662 
00663     if( sym < 0x3000 ) {
00664         QChar c(sym);
00665         if( c.isLetter() && c.toLower() != c.toUpper() && sym == c.toUpper().unicode() )
00666             return Qt::SHIFT;
00667     }
00668 
00669     uchar code = XKeysymToKeycode( QX11Info::display(), sym );
00670     if( code ) {
00671         // need to check index 0 before the others, so that a null-mod
00672         //  can take precedence over the others, in case the modified
00673         //  key produces the same symbol.
00674         if( sym == XKeycodeToKeysym( QX11Info::display(), code, 0 ) )
00675             ;
00676         else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 1 ) )
00677             mod = Qt::SHIFT;
00678         else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 2 ) )
00679             mod = MODE_SWITCH;
00680         else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 3 ) )
00681             mod = Qt::SHIFT | MODE_SWITCH;
00682     }
00683     return mod;
00684 }
00685 
00686 bool keyQtToCodeX( int keyQt, int* keyCode )
00687 {
00688     int sym;
00689     uint mod;
00690     keyQtToSymX(keyQt, &sym);
00691     keyQtToModX(keyQt, &mod);
00692 
00693     // Get any extra mods required by the sym.
00694     //  E.g., XK_Plus requires SHIFT on the en layout.
00695     uint modExtra = getModsRequired(sym);
00696     // Get the X modifier equivalent.
00697     if( !sym || !keyQtToModX( (keyQt & Qt::KeyboardModifierMask) | modExtra, &mod ) ) {
00698         *keyCode = 0;
00699         return false;
00700     }
00701 
00702     *keyCode = XKeysymToKeycode( QX11Info::display(), sym );
00703     return true;
00704 }
00705 
00706 bool keyQtToSymX( int keyQt, int* keySym )
00707 {
00708     int symQt = keyQt & ~Qt::KeyboardModifierMask;
00709 
00710     if( symQt < 0x1000 ) {
00711         *keySym = QChar(symQt).toUpper().unicode();
00712         return true;
00713     }
00714 
00715 
00716     for( uint i = 0; i < sizeof(g_rgQtToSymX)/sizeof(TransKey); i++ ) {
00717         if( g_rgQtToSymX[i].keySymQt == symQt ) {
00718             *keySym = g_rgQtToSymX[i].keySymX;
00719             return true;
00720         }
00721     }
00722 
00723     *keySym = 0;
00724     if( symQt != Qt::Key_Shift && symQt != Qt::Key_Control && symQt != Qt::Key_Alt &&
00725         symQt != Qt::Key_Meta && symQt != Qt::Key_Direction_L && symQt != Qt::Key_Direction_R )
00726         kDebug(125) << "Sym::initQt( " << QString::number(keyQt,16) << " ): failed to convert key.";
00727     return false;
00728 }
00729 
00730 bool symXToKeyQt( uint keySym, int* keyQt )
00731 {
00732     *keyQt = Qt::Key_unknown;
00733     if( keySym < 0x1000 ) {
00734         if( keySym >= 'a' && keySym <= 'z' )
00735             *keyQt = QChar(keySym).toUpper().unicode();
00736         else
00737             *keyQt = keySym;
00738     }
00739 
00740     else if( keySym < 0x3000 )
00741         *keyQt = keySym;
00742 
00743     else {
00744         for( uint i = 0; i < sizeof(g_rgQtToSymX)/sizeof(TransKey); i++ )
00745             if( g_rgQtToSymX[i].keySymX == keySym ) {
00746                 *keyQt = g_rgQtToSymX[i].keySymQt;
00747                 break;
00748             }
00749     }
00750 
00751     return (*keyQt != Qt::Key_unknown);
00752 }
00753 
00754 /* are these things actually used anywhere?  there's no way
00755    they can do anything on non-X11 */
00756 
00757 bool keyQtToModX( int modQt, uint* modX )
00758 {
00759     if( !g_bInitializedMods )
00760         initializeMods();
00761 
00762     *modX = 0;
00763     for( int i = 0; i < 4; i++ ) {
00764 
00765         if( modQt & g_rgX11ModInfo[i].modQt ) {
00766             if( g_rgX11ModInfo[i].modX ) {
00767                 *modX |= g_rgX11ModInfo[i].modX;
00768             } else {
00769                 // The qt modifier has no x equivalent. Return false
00770                 return false;
00771             }
00772         }
00773     }
00774     return true;
00775 }
00776 
00777 bool modXToQt( uint modX, int* modQt )
00778 {
00779     if( !g_bInitializedMods )
00780         initializeMods();
00781 
00782     *modQt = 0;
00783     for( int i = 0; i < 4; i++ ) {
00784         if( modX & g_rgX11ModInfo[i].modX ) {
00785             *modQt |= g_rgX11ModInfo[i].modQt;
00786             continue;
00787         }
00788     }
00789     return true;
00790 }
00791 
00792 
00793 bool codeXToSym( uchar codeX, uint modX, uint* sym )
00794 {
00795     KeySym keySym;
00796     XKeyPressedEvent event;
00797 
00798     checkDisplay();
00799 
00800     event.type = KeyPress;
00801     event.display = QX11Info::display();
00802     event.state = modX;
00803     event.keycode = codeX;
00804 
00805     XLookupString( &event, 0, 0, &keySym, 0 );
00806     *sym = (uint) keySym;
00807     return true;
00808 }
00809 
00810 
00811 uint accelModMaskX()
00812 {
00813     return modXShift() | modXCtrl() | modXAlt() | modXMeta();
00814 }
00815 
00816 
00817 bool xEventToQt( XEvent* e, int* keyQt )
00818 {
00819     Q_ASSERT(e->type == KeyPress || e->type == KeyRelease);
00820 
00821     uchar keyCodeX = e->xkey.keycode;
00822     uint keyModX = e->xkey.state & (accelModMaskX() | MODE_SWITCH);
00823 
00824     KeySym keySym;
00825     char buffer[16];
00826     XLookupString( (XKeyEvent*) e, buffer, 15, &keySym, 0 );
00827     uint keySymX = (uint)keySym;
00828 
00829     // If numlock is active and a keypad key is pressed, XOR the SHIFT state.
00830     //  e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left.
00831     if( e->xkey.state & modXNumLock() ) {
00832         uint sym = XKeycodeToKeysym( QX11Info::display(), keyCodeX, 0 );
00833         // TODO: what's the xor operator in c++?
00834         // If this is a keypad key,
00835         if( sym >= XK_KP_Space && sym <= XK_KP_9 ) {
00836             switch( sym ) {
00837                 // Leave the following keys unaltered
00838                 // FIXME: The proper solution is to see which keysyms don't change when shifted.
00839                 case XK_KP_Multiply:
00840                 case XK_KP_Add:
00841                 case XK_KP_Subtract:
00842                 case XK_KP_Divide:
00843                     break;
00844                 default:
00845                     if( keyModX & modXShift() )
00846                         keyModX &= ~modXShift();
00847                     else
00848                         keyModX |= modXShift();
00849             }
00850         }
00851     }
00852 
00853     int keyCodeQt;
00854     int keyModQt;
00855     symXToKeyQt(keySymX, &keyCodeQt);
00856     modXToQt(keyModX, &keyModQt);
00857 
00858     *keyQt = keyCodeQt | keyModQt;
00859     return true;
00860 }
00861 
00862 
00863 } // end of namespace KKeyServer block
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:32:40 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.9.5 API Reference

Skip menu "kdelibs-4.9.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal