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

KDEUI

  • kdeui
  • util
kkeyserver_x11.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
3 
4  Win32 port:
5  Copyright (C) 2004 JarosÅ‚aw Staniek <staniek@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kkeyserver_x11.h"
24 
25 #include "kdebug.h"
26 #include "klocale.h"
27 
28 #include <QX11Info>
29 # define XK_MISCELLANY
30 # define XK_XKB_KEYS
31 # include <X11/X.h>
32 # include <X11/Xlib.h>
33 # include <X11/Xutil.h>
34 # include <X11/keysymdef.h>
35 # define X11_ONLY(arg) arg, //allows to omit an argument
36 
37 // #define KKEYSERVER_DEBUG 1
38 
39 
40 
41 namespace KKeyServer
42 {
43 
44 //---------------------------------------------------------------------
45 // Data Structures
46 //---------------------------------------------------------------------
47 
48 struct Mod
49 {
50  int m_mod;
51 };
52 
53 //---------------------------------------------------------------------
54 // Array Structures
55 //---------------------------------------------------------------------
56 
57 struct X11ModInfo
58 {
59  int modQt;
60  int modX;
61 };
62 
63 struct SymVariation
64 {
65  uint sym, symVariation;
66  bool bActive;
67 };
68 
69 struct SymName
70 {
71  uint sym;
72  const char* psName;
73 };
74 
75 struct TransKey {
76  int keySymQt;
77  uint keySymX;
78 };
79 
80 //---------------------------------------------------------------------
81 // Arrays
82 //---------------------------------------------------------------------
83 
84 static X11ModInfo g_rgX11ModInfo[4] =
85 {
86  { Qt::SHIFT, X11_ONLY(ShiftMask) },
87  { Qt::CTRL, X11_ONLY(ControlMask) },
88  { Qt::ALT, X11_ONLY(Mod1Mask) },
89  { Qt::META, X11_ONLY(Mod4Mask) }
90 };
91 
92 // Special Names List
93 static const SymName g_rgSymNames[] = {
94  { XK_ISO_Left_Tab, "Backtab" },
95  { XK_BackSpace, I18N_NOOP("Backspace") },
96  { XK_Sys_Req, I18N_NOOP("SysReq") },
97  { XK_Caps_Lock, I18N_NOOP("CapsLock") },
98  { XK_Num_Lock, I18N_NOOP("NumLock") },
99  { XK_Scroll_Lock, I18N_NOOP("ScrollLock") },
100  { XK_Prior, I18N_NOOP("PageUp") },
101  { XK_Next, I18N_NOOP("PageDown") },
102 #ifdef sun
103  { XK_F11, I18N_NOOP("Stop") },
104  { XK_F12, I18N_NOOP("Again") },
105  { XK_F13, I18N_NOOP("Props") },
106  { XK_F14, I18N_NOOP("Undo") },
107  { XK_F15, I18N_NOOP("Front") },
108  { XK_F16, I18N_NOOP("Copy") },
109  { XK_F17, I18N_NOOP("Open") },
110  { XK_F18, I18N_NOOP("Paste") },
111  { XK_F19, I18N_NOOP("Find") },
112  { XK_F20, I18N_NOOP("Cut") },
113  { XK_F22, I18N_NOOP("Print") },
114 #endif
115  { 0, 0 }
116 };
117 
118 // These are the X equivalents to the Qt keycodes 0x1000 - 0x1026
119 static const TransKey g_rgQtToSymX[] =
120 {
121  { Qt::Key_Escape, XK_Escape },
122  { Qt::Key_Tab, XK_Tab },
123  { Qt::Key_Backtab, XK_ISO_Left_Tab },
124  { Qt::Key_Backspace, XK_BackSpace },
125  { Qt::Key_Return, XK_Return },
126  { Qt::Key_Enter, XK_KP_Enter },
127  { Qt::Key_Insert, XK_Insert },
128  { Qt::Key_Delete, XK_Delete },
129  { Qt::Key_Pause, XK_Pause },
130 #ifdef sun
131  { Qt::Key_Print, XK_F22 },
132 #else
133  { Qt::Key_Print, XK_Print },
134 #endif
135  { Qt::Key_SysReq, XK_Sys_Req },
136  { Qt::Key_Home, XK_Home },
137  { Qt::Key_End, XK_End },
138  { Qt::Key_Left, XK_Left },
139  { Qt::Key_Up, XK_Up },
140  { Qt::Key_Right, XK_Right },
141  { Qt::Key_Down, XK_Down },
142  { Qt::Key_PageUp, XK_Prior },
143  { Qt::Key_PageDown, XK_Next },
144  //{ Qt::Key_Shift, 0 },
145  //{ Qt::Key_Control, 0 },
146  //{ Qt::Key_Meta, 0 },
147  //{ Qt::Key_Alt, 0 },
148  { Qt::Key_CapsLock, XK_Caps_Lock },
149  { Qt::Key_NumLock, XK_Num_Lock },
150  { Qt::Key_ScrollLock, XK_Scroll_Lock },
151  { Qt::Key_F1, XK_F1 },
152  { Qt::Key_F2, XK_F2 },
153  { Qt::Key_F3, XK_F3 },
154  { Qt::Key_F4, XK_F4 },
155  { Qt::Key_F5, XK_F5 },
156  { Qt::Key_F6, XK_F6 },
157  { Qt::Key_F7, XK_F7 },
158  { Qt::Key_F8, XK_F8 },
159  { Qt::Key_F9, XK_F9 },
160  { Qt::Key_F10, XK_F10 },
161  { Qt::Key_F11, XK_F11 },
162  { Qt::Key_F12, XK_F12 },
163  { Qt::Key_F13, XK_F13 },
164  { Qt::Key_F14, XK_F14 },
165  { Qt::Key_F15, XK_F15 },
166  { Qt::Key_F16, XK_F16 },
167  { Qt::Key_F17, XK_F17 },
168  { Qt::Key_F18, XK_F18 },
169  { Qt::Key_F19, XK_F19 },
170  { Qt::Key_F20, XK_F20 },
171  { Qt::Key_F21, XK_F21 },
172  { Qt::Key_F22, XK_F22 },
173  { Qt::Key_F23, XK_F23 },
174  { Qt::Key_F24, XK_F24 },
175  { Qt::Key_F25, XK_F25 },
176  { Qt::Key_F26, XK_F26 },
177  { Qt::Key_F27, XK_F27 },
178  { Qt::Key_F28, XK_F28 },
179  { Qt::Key_F29, XK_F29 },
180  { Qt::Key_F30, XK_F30 },
181  { Qt::Key_F31, XK_F31 },
182  { Qt::Key_F32, XK_F32 },
183  { Qt::Key_F33, XK_F33 },
184  { Qt::Key_F34, XK_F34 },
185  { Qt::Key_F35, XK_F35 },
186  { Qt::Key_Super_L, XK_Super_L },
187  { Qt::Key_Super_R, XK_Super_R },
188  { Qt::Key_Menu, XK_Menu },
189  { Qt::Key_Hyper_L, XK_Hyper_L },
190  { Qt::Key_Hyper_R, XK_Hyper_R },
191  { Qt::Key_Help, XK_Help },
192  //{ Qt::Key_Direction_L, XK_Direction_L }, These keys don't exist in X11
193  //{ Qt::Key_Direction_R, XK_Direction_R },
194 
195  { '/', XK_KP_Divide },
196  { '*', XK_KP_Multiply },
197  { '-', XK_KP_Subtract },
198  { '+', XK_KP_Add },
199  { Qt::Key_Return, XK_KP_Enter }
200 
201 // the next lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining some special
202 // multimedia keys. They are included here as not every system has them.
203 #define XF86XK_MonBrightnessUp 0x1008FF02
204 #define XF86XK_MonBrightnessDown 0x1008FF03
205 #define XF86XK_KbdLightOnOff 0x1008FF04
206 #define XF86XK_KbdBrightnessUp 0x1008FF05
207 #define XF86XK_KbdBrightnessDown 0x1008FF06
208 #define XF86XK_Standby 0x1008FF10
209 #define XF86XK_AudioLowerVolume 0x1008FF11
210 #define XF86XK_AudioMute 0x1008FF12
211 #define XF86XK_AudioRaiseVolume 0x1008FF13
212 #define XF86XK_AudioPlay 0x1008FF14
213 #define XF86XK_AudioStop 0x1008FF15
214 #define XF86XK_AudioPrev 0x1008FF16
215 #define XF86XK_AudioNext 0x1008FF17
216 #define XF86XK_HomePage 0x1008FF18
217 #define XF86XK_Mail 0x1008FF19
218 #define XF86XK_Start 0x1008FF1A
219 #define XF86XK_Search 0x1008FF1B
220 #define XF86XK_AudioRecord 0x1008FF1C
221 #define XF86XK_Calculator 0x1008FF1D
222 #define XF86XK_Memo 0x1008FF1E
223 #define XF86XK_ToDoList 0x1008FF1F
224 #define XF86XK_Calendar 0x1008FF20
225 #define XF86XK_PowerDown 0x1008FF21
226 #define XF86XK_ContrastAdjust 0x1008FF22
227 #define XF86XK_Back 0x1008FF26
228 #define XF86XK_Forward 0x1008FF27
229 #define XF86XK_Stop 0x1008FF28
230 #define XF86XK_Refresh 0x1008FF29
231 #define XF86XK_PowerOff 0x1008FF2A
232 #define XF86XK_WakeUp 0x1008FF2B
233 #define XF86XK_Eject 0x1008FF2C
234 #define XF86XK_ScreenSaver 0x1008FF2D
235 #define XF86XK_WWW 0x1008FF2E
236 #define XF86XK_Sleep 0x1008FF2F
237 #define XF86XK_Favorites 0x1008FF30
238 #define XF86XK_AudioPause 0x1008FF31
239 #define XF86XK_AudioMedia 0x1008FF32
240 #define XF86XK_MyComputer 0x1008FF33
241 #define XF86XK_LightBulb 0x1008FF35
242 #define XF86XK_Shop 0x1008FF36
243 #define XF86XK_History 0x1008FF37
244 #define XF86XK_OpenURL 0x1008FF38
245 #define XF86XK_AddFavorite 0x1008FF39
246 #define XF86XK_HotLinks 0x1008FF3A
247 #define XF86XK_BrightnessAdjust 0x1008FF3B
248 #define XF86XK_Finance 0x1008FF3C
249 #define XF86XK_Community 0x1008FF3D
250 #define XF86XK_AudioRewind 0x1008FF3E
251 #define XF86XK_BackForward 0x1008FF3F
252 #define XF86XK_Launch0 0x1008FF40
253 #define XF86XK_Launch1 0x1008FF41
254 #define XF86XK_Launch2 0x1008FF42
255 #define XF86XK_Launch3 0x1008FF43
256 #define XF86XK_Launch4 0x1008FF44
257 #define XF86XK_Launch5 0x1008FF45
258 #define XF86XK_Launch6 0x1008FF46
259 #define XF86XK_Launch7 0x1008FF47
260 #define XF86XK_Launch8 0x1008FF48
261 #define XF86XK_Launch9 0x1008FF49
262 #define XF86XK_LaunchA 0x1008FF4A
263 #define XF86XK_LaunchB 0x1008FF4B
264 #define XF86XK_LaunchC 0x1008FF4C
265 #define XF86XK_LaunchD 0x1008FF4D
266 #define XF86XK_LaunchE 0x1008FF4E
267 #define XF86XK_LaunchF 0x1008FF4F
268 #define XF86XK_ApplicationLeft 0x1008FF50
269 #define XF86XK_ApplicationRight 0x1008FF51
270 #define XF86XK_Book 0x1008FF52
271 #define XF86XK_CD 0x1008FF53
272 #define XF86XK_Calculater 0x1008FF54
273 #define XF86XK_Clear 0x1008FF55
274 #define XF86XK_ClearGrab 0x1008FE21
275 #define XF86XK_Close 0x1008FF56
276 #define XF86XK_Copy 0x1008FF57
277 #define XF86XK_Cut 0x1008FF58
278 #define XF86XK_Display 0x1008FF59
279 #define XF86XK_DOS 0x1008FF5A
280 #define XF86XK_Documents 0x1008FF5B
281 #define XF86XK_Excel 0x1008FF5C
282 #define XF86XK_Explorer 0x1008FF5D
283 #define XF86XK_Game 0x1008FF5E
284 #define XF86XK_Go 0x1008FF5F
285 #define XF86XK_iTouch 0x1008FF60
286 #define XF86XK_LogOff 0x1008FF61
287 #define XF86XK_Market 0x1008FF62
288 #define XF86XK_Meeting 0x1008FF63
289 #define XF86XK_MenuKB 0x1008FF65
290 #define XF86XK_MenuPB 0x1008FF66
291 #define XF86XK_MySites 0x1008FF67
292 #define XF86XK_News 0x1008FF69
293 #define XF86XK_OfficeHome 0x1008FF6A
294 #define XF86XK_Option 0x1008FF6C
295 #define XF86XK_Paste 0x1008FF6D
296 #define XF86XK_Phone 0x1008FF6E
297 #define XF86XK_Reply 0x1008FF72
298 #define XF86XK_Reload 0x1008FF73
299 #define XF86XK_RotateWindows 0x1008FF74
300 #define XF86XK_RotationPB 0x1008FF75
301 #define XF86XK_RotationKB 0x1008FF76
302 #define XF86XK_Save 0x1008FF77
303 #define XF86XK_Send 0x1008FF7B
304 #define XF86XK_Spell 0x1008FF7C
305 #define XF86XK_SplitScreen 0x1008FF7D
306 #define XF86XK_Support 0x1008FF7E
307 #define XF86XK_TaskPane 0x1008FF7F
308 #define XF86XK_Terminal 0x1008FF80
309 #define XF86XK_Tools 0x1008FF81
310 #define XF86XK_Travel 0x1008FF82
311 #define XF86XK_Video 0x1008FF87
312 #define XF86XK_Word 0x1008FF89
313 #define XF86XK_Xfer 0x1008FF8A
314 #define XF86XK_ZoomIn 0x1008FF8B
315 #define XF86XK_ZoomOut 0x1008FF8C
316 #define XF86XK_Away 0x1008FF8D
317 #define XF86XK_Messenger 0x1008FF8E
318 #define XF86XK_WebCam 0x1008FF8F
319 #define XF86XK_MailForward 0x1008FF90
320 #define XF86XK_Pictures 0x1008FF91
321 #define XF86XK_Music 0x1008FF92
322 #define XF86XK_Battery 0x1008FF93
323 #define XF86XK_Bluetooth 0x1008FF94
324 #define XF86XK_WLAN 0x1008FF95
325 #define XF86XK_UWB 0x1008FF96
326 #define XF86XK_AudioForward 0x1008FF97
327 #define XF86XK_AudioRepeat 0x1008FF98
328 #define XF86XK_AudioRandomPlay 0x1008FF99
329 #define XF86XK_Subtitle 0x1008FF9A
330 #define XF86XK_AudioCycleTrack 0x1008FF9B
331 #define XF86XK_Time 0x1008FF9F
332 #define XF86XK_Select 0x1008FFA0
333 #define XF86XK_View 0x1008FFA1
334 #define XF86XK_TopMenu 0x1008FFA2
335 #define XF86XK_Suspend 0x1008FFA7
336 #define XF86XK_Hibernate 0x1008FFA8
337 // end of XF86keysyms.h
338  ,
339  { Qt::Key_Back, XF86XK_Back },
340  { Qt::Key_Forward, XF86XK_Forward },
341  { Qt::Key_Stop, XF86XK_Stop },
342  { Qt::Key_Refresh, XF86XK_Refresh },
343  { Qt::Key_Favorites, XF86XK_Favorites },
344  { Qt::Key_LaunchMedia, XF86XK_AudioMedia },
345  { Qt::Key_OpenUrl, XF86XK_OpenURL },
346  { Qt::Key_HomePage, XF86XK_HomePage },
347  { Qt::Key_Search, XF86XK_Search },
348  { Qt::Key_VolumeDown, XF86XK_AudioLowerVolume },
349  { Qt::Key_VolumeMute, XF86XK_AudioMute },
350  { Qt::Key_VolumeUp, XF86XK_AudioRaiseVolume },
351  { Qt::Key_MediaPlay, XF86XK_AudioPlay },
352  { Qt::Key_MediaStop, XF86XK_AudioStop },
353  { Qt::Key_MediaPrevious, XF86XK_AudioPrev },
354  { Qt::Key_MediaNext, XF86XK_AudioNext },
355  { Qt::Key_MediaRecord, XF86XK_AudioRecord },
356  { Qt::Key_LaunchMail, XF86XK_Mail },
357  { Qt::Key_Launch0, XF86XK_MyComputer },
358  { Qt::Key_Calculator, XF86XK_Calculator },
359  { Qt::Key_Memo, XF86XK_Memo },
360  { Qt::Key_ToDoList, XF86XK_ToDoList },
361  { Qt::Key_Calendar, XF86XK_Calendar },
362  { Qt::Key_PowerDown, XF86XK_PowerDown },
363  { Qt::Key_ContrastAdjust, XF86XK_ContrastAdjust },
364  { Qt::Key_Standby, XF86XK_Standby },
365  { Qt::Key_MonBrightnessUp, XF86XK_MonBrightnessUp },
366  { Qt::Key_MonBrightnessDown, XF86XK_MonBrightnessDown },
367  { Qt::Key_KeyboardLightOnOff, XF86XK_KbdLightOnOff },
368  { Qt::Key_KeyboardBrightnessUp, XF86XK_KbdBrightnessUp },
369  { Qt::Key_KeyboardBrightnessDown, XF86XK_KbdBrightnessDown },
370  { Qt::Key_PowerOff, XF86XK_PowerOff },
371  { Qt::Key_WakeUp, XF86XK_WakeUp },
372  { Qt::Key_Eject, XF86XK_Eject },
373  { Qt::Key_ScreenSaver, XF86XK_ScreenSaver },
374  { Qt::Key_WWW, XF86XK_WWW },
375  { Qt::Key_Sleep, XF86XK_Sleep },
376  { Qt::Key_LightBulb, XF86XK_LightBulb },
377  { Qt::Key_Shop, XF86XK_Shop },
378  { Qt::Key_History, XF86XK_History },
379  { Qt::Key_AddFavorite, XF86XK_AddFavorite },
380  { Qt::Key_HotLinks, XF86XK_HotLinks },
381  { Qt::Key_BrightnessAdjust, XF86XK_BrightnessAdjust },
382  { Qt::Key_Finance, XF86XK_Finance },
383  { Qt::Key_Community, XF86XK_Community },
384  { Qt::Key_AudioRewind, XF86XK_AudioRewind },
385  { Qt::Key_BackForward, XF86XK_BackForward },
386  { Qt::Key_ApplicationLeft, XF86XK_ApplicationLeft },
387  { Qt::Key_ApplicationRight, XF86XK_ApplicationRight },
388  { Qt::Key_Book, XF86XK_Book },
389  { Qt::Key_CD, XF86XK_CD },
390  { Qt::Key_Calculator, XF86XK_Calculater },
391  { Qt::Key_Clear, XF86XK_Clear },
392  { Qt::Key_ClearGrab, XF86XK_ClearGrab },
393  { Qt::Key_Close, XF86XK_Close },
394  { Qt::Key_Copy, XF86XK_Copy },
395  { Qt::Key_Cut, XF86XK_Cut },
396  { Qt::Key_Display, XF86XK_Display },
397  { Qt::Key_DOS, XF86XK_DOS },
398  { Qt::Key_Documents, XF86XK_Documents },
399  { Qt::Key_Excel, XF86XK_Excel },
400  { Qt::Key_Explorer, XF86XK_Explorer },
401  { Qt::Key_Game, XF86XK_Game },
402  { Qt::Key_Go, XF86XK_Go },
403  { Qt::Key_iTouch, XF86XK_iTouch },
404  { Qt::Key_LogOff, XF86XK_LogOff },
405  { Qt::Key_Market, XF86XK_Market },
406  { Qt::Key_Meeting, XF86XK_Meeting },
407  { Qt::Key_MenuKB, XF86XK_MenuKB },
408  { Qt::Key_MenuPB, XF86XK_MenuPB },
409  { Qt::Key_MySites, XF86XK_MySites },
410  { Qt::Key_News, XF86XK_News },
411  { Qt::Key_OfficeHome, XF86XK_OfficeHome },
412  { Qt::Key_Option, XF86XK_Option },
413  { Qt::Key_Paste, XF86XK_Paste },
414  { Qt::Key_Phone, XF86XK_Phone },
415  { Qt::Key_Reply, XF86XK_Reply },
416  { Qt::Key_Reload, XF86XK_Reload },
417  { Qt::Key_RotateWindows, XF86XK_RotateWindows },
418  { Qt::Key_RotationPB, XF86XK_RotationPB },
419  { Qt::Key_RotationKB, XF86XK_RotationKB },
420  { Qt::Key_Save, XF86XK_Save },
421  { Qt::Key_Send, XF86XK_Send },
422  { Qt::Key_Spell, XF86XK_Spell },
423  { Qt::Key_SplitScreen, XF86XK_SplitScreen },
424  { Qt::Key_Support, XF86XK_Support },
425  { Qt::Key_TaskPane, XF86XK_TaskPane },
426  { Qt::Key_Terminal, XF86XK_Terminal },
427  { Qt::Key_Tools, XF86XK_Tools },
428  { Qt::Key_Travel, XF86XK_Travel },
429  { Qt::Key_Video, XF86XK_Video },
430  { Qt::Key_Word, XF86XK_Word },
431  { Qt::Key_Xfer, XF86XK_Xfer },
432  { Qt::Key_ZoomIn, XF86XK_ZoomIn },
433  { Qt::Key_ZoomOut, XF86XK_ZoomOut },
434  { Qt::Key_Away, XF86XK_Away },
435  { Qt::Key_Messenger, XF86XK_Messenger },
436  { Qt::Key_WebCam, XF86XK_WebCam },
437  { Qt::Key_MailForward, XF86XK_MailForward },
438  { Qt::Key_Pictures, XF86XK_Pictures },
439  { Qt::Key_Music, XF86XK_Music },
440  { Qt::Key_Battery, XF86XK_Battery },
441  { Qt::Key_Bluetooth, XF86XK_Bluetooth },
442  { Qt::Key_WLAN, XF86XK_WLAN },
443  { Qt::Key_UWB, XF86XK_UWB },
444  { Qt::Key_AudioForward, XF86XK_AudioForward },
445  { Qt::Key_AudioRepeat, XF86XK_AudioRepeat },
446  { Qt::Key_AudioRandomPlay, XF86XK_AudioRandomPlay },
447  { Qt::Key_Subtitle, XF86XK_Subtitle },
448  { Qt::Key_AudioCycleTrack, XF86XK_AudioCycleTrack },
449  { Qt::Key_Time, XF86XK_Time },
450  { Qt::Key_Select, XF86XK_Select },
451  { Qt::Key_View, XF86XK_View },
452  { Qt::Key_TopMenu, XF86XK_TopMenu },
453  { Qt::Key_Bluetooth, XF86XK_Bluetooth },
454  { Qt::Key_Suspend, XF86XK_Suspend },
455  { Qt::Key_Hibernate, XF86XK_Hibernate },
456  { Qt::Key_Launch2, XF86XK_Launch0 },
457  { Qt::Key_Launch3, XF86XK_Launch1 },
458  { Qt::Key_Launch4, XF86XK_Launch2 },
459  { Qt::Key_Launch5, XF86XK_Launch3 },
460  { Qt::Key_Launch6, XF86XK_Launch4 },
461  { Qt::Key_Launch7, XF86XK_Launch5 },
462  { Qt::Key_Launch8, XF86XK_Launch6 },
463  { Qt::Key_Launch9, XF86XK_Launch7 },
464  { Qt::Key_LaunchA, XF86XK_Launch8 },
465  { Qt::Key_LaunchB, XF86XK_Launch9 },
466  { Qt::Key_LaunchC, XF86XK_LaunchA },
467  { Qt::Key_LaunchD, XF86XK_LaunchB },
468  { Qt::Key_LaunchE, XF86XK_LaunchC },
469  { Qt::Key_LaunchF, XF86XK_LaunchD },
470 };
471 
472 //---------------------------------------------------------------------
473 // Debugging
474 //---------------------------------------------------------------------
475 #ifndef NDEBUG
476 inline void checkDisplay()
477 {
478  // Some non-GUI apps might try to use us.
479  if ( !QX11Info::display() ) {
480  kError() << "QX11Info::display() returns 0. I'm probably going to crash now." << endl;
481  kError() << "If this is a KApplication initialized without GUI stuff, change it to be "
482  "initialized with GUI stuff." << endl;
483  }
484 }
485 #else // NDEBUG
486 # define checkDisplay()
487 #endif
488 
489 //---------------------------------------------------------------------
490 // Initialization
491 //---------------------------------------------------------------------
492 
493 static bool g_bInitializedMods;
494 static uint g_modXNumLock, g_modXScrollLock, g_modXModeSwitch, g_alt_mask, g_meta_mask, g_super_mask, g_hyper_mask;
495 
496 bool initializeMods()
497 {
498  // Reinitialize the masks
499  g_modXNumLock = 0;
500  g_modXScrollLock = 0;
501  g_modXModeSwitch = 0;
502  g_alt_mask = 0;
503  g_meta_mask = 0;
504  g_super_mask = 0;
505  g_hyper_mask = 0;
506 
507  checkDisplay();
508  XModifierKeymap* xmk = XGetModifierMapping( QX11Info::display() );
509 
510  int min_keycode, max_keycode;
511  int keysyms_per_keycode = 0;
512 
513  XDisplayKeycodes( QX11Info::display(), &min_keycode, &max_keycode );
514  XFree( XGetKeyboardMapping( QX11Info::display(), min_keycode, 1, &keysyms_per_keycode ));
515 
516  for( int i = Mod1MapIndex; i < 8; i++ ) {
517  uint mask = (1 << i);
518  uint keySymX = NoSymbol;
519 
520  // This used to be only XKeycodeToKeysym( ... , 0 ), but that fails with XFree4.3.99
521  // and X.org R6.7 , where for some reason only ( ... , 1 ) works. I have absolutely no
522  // idea what the problem is, but searching all possibilities until something valid is
523  // found fixes the problem.
524  for( int j = 0; j < xmk->max_keypermod; ++j ) {
525 
526  for( int k = 0; k < keysyms_per_keycode; ++k ) {
527 
528  keySymX = XKeycodeToKeysym( QX11Info::display(), xmk->modifiermap[xmk->max_keypermod * i + j], k );
529 
530  switch( keySymX ) {
531  case XK_Alt_L:
532  case XK_Alt_R: g_alt_mask |= mask; break;
533 
534  case XK_Super_L:
535  case XK_Super_R: g_super_mask |= mask; break;
536 
537  case XK_Hyper_L:
538  case XK_Hyper_R: g_hyper_mask |= mask; break;
539 
540  case XK_Meta_L:
541  case XK_Meta_R: g_meta_mask |= mask; break;
542 
543  case XK_Num_Lock: g_modXNumLock |= mask; break;
544  case XK_Scroll_Lock: g_modXScrollLock |= mask; break;
545  case XK_Mode_switch: g_modXModeSwitch |= mask; break;
546  }
547  }
548  }
549  }
550 
551 #ifdef KKEYSERVER_DEBUG
552  kDebug() << "Alt:" << g_alt_mask;
553  kDebug() << "Meta:" << g_meta_mask;
554  kDebug() << "Super:" << g_super_mask;
555  kDebug() << "Hyper:" << g_hyper_mask;
556  kDebug() << "NumLock:" << g_modXNumLock;
557  kDebug() << "ScrollLock:" << g_modXScrollLock;
558  kDebug() << "ModeSwitch:" << g_modXModeSwitch;
559 #endif
560 
561  // Check if hyper overlaps with super or meta or alt
562  if (g_hyper_mask&(g_super_mask|g_meta_mask|g_alt_mask)) {
563 #ifdef KKEYSERVER_DEBUG
564  kDebug() << "Hyper conflicts with super, meta or alt.";
565 #endif
566  // Remove the conflicting masks
567  g_hyper_mask &= ~(g_super_mask|g_meta_mask|g_alt_mask);
568  }
569 
570  // Check if super overlaps with meta or alt
571  if (g_super_mask&(g_meta_mask|g_alt_mask)) {
572 #ifdef KKEYSERVER_DEBUG
573  kDebug() << "Super conflicts with meta or alt.";
574 #endif
575  // Remove the conflicting masks
576  g_super_mask &= ~(g_meta_mask|g_alt_mask);
577  }
578 
579 
580  // Check if meta overlaps with alt
581  if (g_meta_mask|g_alt_mask) {
582 #ifdef KKEYSERVER_DEBUG
583  kDebug() << "Meta conflicts with alt.";
584 #endif
585  // Remove the conflicting masks
586  g_meta_mask &= ~(g_alt_mask);
587  }
588 
589  if (!g_meta_mask) {
590 #ifdef KKEYSERVER_DEBUG
591  kDebug() << "Meta is not set or conflicted with alt.";
592 #endif
593  if (g_super_mask) {
594 #ifdef KKEYSERVER_DEBUG
595  kDebug() << "Using super for meta";
596 #endif
597  // Use Super
598  g_meta_mask = g_super_mask;
599  } else if (g_hyper_mask) {
600 #ifdef KKEYSERVER_DEBUG
601  kDebug() << "Using hyper for meta";
602 #endif
603  // User Hyper
604  g_meta_mask = g_hyper_mask;
605  } else {
606  // ???? Nothing left
607  g_meta_mask = 0;
608  }
609  }
610 
611 #ifdef KKEYSERVER_DEBUG
612  kDebug() << "Alt:" << g_alt_mask;
613  kDebug() << "Meta:" << g_meta_mask;
614  kDebug() << "Super:" << g_super_mask;
615  kDebug() << "Hyper:" << g_hyper_mask;
616  kDebug() << "NumLock:" << g_modXNumLock;
617  kDebug() << "ScrollLock:" << g_modXScrollLock;
618  kDebug() << "ModeSwitch:" << g_modXModeSwitch;
619 #endif
620 
621  if (!g_meta_mask) {
622  kWarning() << "Your keyboard setup doesn't provide a key to use for meta. See 'xmodmap -pm' or 'xkbcomp $DISPLAY'";
623  }
624 
625  g_rgX11ModInfo[2].modX = g_alt_mask;
626  g_rgX11ModInfo[3].modX = g_meta_mask;
627 
628  XFreeModifiermap( xmk );
629  g_bInitializedMods = true;
630 
631  return true;
632 }
633 
634 
635 //---------------------------------------------------------------------
636 // Public functions
637 //---------------------------------------------------------------------
638 
639 
640 uint modXShift() { return ShiftMask; }
641 uint modXCtrl() { return ControlMask; }
642 uint modXAlt() { if( !g_bInitializedMods ) { initializeMods(); } return g_alt_mask; }
643 uint modXMeta() { if( !g_bInitializedMods ) { initializeMods(); } return g_meta_mask; }
644 
645 uint modXNumLock() { if( !g_bInitializedMods ) { initializeMods(); } return g_modXNumLock; }
646 uint modXLock() { return LockMask; }
647 uint modXScrollLock() { if( !g_bInitializedMods ) { initializeMods(); } return g_modXScrollLock; }
648 uint modXModeSwitch() { if( !g_bInitializedMods ) { initializeMods(); } return g_modXModeSwitch; }
649 
650 bool keyboardHasMetaKey() { return modXMeta() != 0; }
651 
652 
653 uint getModsRequired(uint sym)
654 {
655  uint mod = 0;
656 
657  // FIXME: This might not be true on all keyboard layouts!
658  if( sym == XK_Sys_Req ) return Qt::ALT;
659  if( sym == XK_Break ) return Qt::CTRL;
660 
661  if( sym < 0x3000 ) {
662  QChar c(sym);
663  if( c.isLetter() && c.toLower() != c.toUpper() && sym == c.toUpper().unicode() )
664  return Qt::SHIFT;
665  }
666 
667  uchar code = XKeysymToKeycode( QX11Info::display(), sym );
668  if( code ) {
669  // need to check index 0 before the others, so that a null-mod
670  // can take precedence over the others, in case the modified
671  // key produces the same symbol.
672  if( sym == XKeycodeToKeysym( QX11Info::display(), code, 0 ) )
673  ;
674  else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 1 ) )
675  mod = Qt::SHIFT;
676  else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 2 ) )
677  mod = MODE_SWITCH;
678  else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 3 ) )
679  mod = Qt::SHIFT | MODE_SWITCH;
680  }
681  return mod;
682 }
683 
684 bool keyQtToCodeX( int keyQt, int* keyCode )
685 {
686  int sym;
687  uint mod;
688  keyQtToSymX(keyQt, &sym);
689  keyQtToModX(keyQt, &mod);
690 
691  // Get any extra mods required by the sym.
692  // E.g., XK_Plus requires SHIFT on the en layout.
693  uint modExtra = getModsRequired(sym);
694  // Get the X modifier equivalent.
695  if( !sym || !keyQtToModX( (keyQt & Qt::KeyboardModifierMask) | modExtra, &mod ) ) {
696  *keyCode = 0;
697  return false;
698  }
699 
700  *keyCode = XKeysymToKeycode( QX11Info::display(), sym );
701  return true;
702 }
703 
704 bool keyQtToSymX( int keyQt, int* keySym )
705 {
706  int symQt = keyQt & ~Qt::KeyboardModifierMask;
707 
708  if( symQt < 0x1000 ) {
709  *keySym = QChar(symQt).toUpper().unicode();
710  return true;
711  }
712 
713 
714  for( uint i = 0; i < sizeof(g_rgQtToSymX)/sizeof(TransKey); i++ ) {
715  if( g_rgQtToSymX[i].keySymQt == symQt ) {
716  *keySym = g_rgQtToSymX[i].keySymX;
717  return true;
718  }
719  }
720 
721  *keySym = 0;
722  if( symQt != Qt::Key_Shift && symQt != Qt::Key_Control && symQt != Qt::Key_Alt &&
723  symQt != Qt::Key_Meta && symQt != Qt::Key_Direction_L && symQt != Qt::Key_Direction_R )
724  kDebug(125) << "Sym::initQt( " << QString::number(keyQt,16) << " ): failed to convert key.";
725  return false;
726 }
727 
728 bool symXToKeyQt( uint keySym, int* keyQt )
729 {
730  *keyQt = Qt::Key_unknown;
731  if( keySym < 0x1000 ) {
732  if( keySym >= 'a' && keySym <= 'z' )
733  *keyQt = QChar(keySym).toUpper().unicode();
734  else
735  *keyQt = keySym;
736  }
737 
738  else if( keySym < 0x3000 )
739  *keyQt = keySym;
740 
741  else {
742  for( uint i = 0; i < sizeof(g_rgQtToSymX)/sizeof(TransKey); i++ )
743  if( g_rgQtToSymX[i].keySymX == keySym ) {
744  *keyQt = g_rgQtToSymX[i].keySymQt;
745  break;
746  }
747  }
748 
749  return (*keyQt != Qt::Key_unknown);
750 }
751 
752 /* are these things actually used anywhere? there's no way
753  they can do anything on non-X11 */
754 
755 bool keyQtToModX( int modQt, uint* modX )
756 {
757  if( !g_bInitializedMods )
758  initializeMods();
759 
760  *modX = 0;
761  for( int i = 0; i < 4; i++ ) {
762 
763  if( modQt & g_rgX11ModInfo[i].modQt ) {
764  if( g_rgX11ModInfo[i].modX ) {
765  *modX |= g_rgX11ModInfo[i].modX;
766  } else {
767  // The qt modifier has no x equivalent. Return false
768  return false;
769  }
770  }
771  }
772  return true;
773 }
774 
775 bool modXToQt( uint modX, int* modQt )
776 {
777  if( !g_bInitializedMods )
778  initializeMods();
779 
780  *modQt = 0;
781  for( int i = 0; i < 4; i++ ) {
782  if( modX & g_rgX11ModInfo[i].modX ) {
783  *modQt |= g_rgX11ModInfo[i].modQt;
784  continue;
785  }
786  }
787  return true;
788 }
789 
790 
791 bool codeXToSym( uchar codeX, uint modX, uint* sym )
792 {
793  KeySym keySym;
794  XKeyPressedEvent event;
795 
796  checkDisplay();
797 
798  event.type = KeyPress;
799  event.display = QX11Info::display();
800  event.state = modX;
801  event.keycode = codeX;
802 
803  XLookupString( &event, 0, 0, &keySym, 0 );
804  *sym = (uint) keySym;
805  return true;
806 }
807 
808 
809 uint accelModMaskX()
810 {
811  return modXShift() | modXCtrl() | modXAlt() | modXMeta();
812 }
813 
814 
815 bool xEventToQt( XEvent* e, int* keyQt )
816 {
817  Q_ASSERT(e->type == KeyPress || e->type == KeyRelease);
818 
819  uchar keyCodeX = e->xkey.keycode;
820  uint keyModX = e->xkey.state & (accelModMaskX() | MODE_SWITCH);
821 
822  KeySym keySym;
823  char buffer[16];
824  XLookupString( (XKeyEvent*) e, buffer, 15, &keySym, 0 );
825  uint keySymX = (uint)keySym;
826 
827  // If numlock is active and a keypad key is pressed, XOR the SHIFT state.
828  // e.g., KP_4 => Shift+KP_Left, and Shift+KP_4 => KP_Left.
829  if( e->xkey.state & modXNumLock() ) {
830  uint sym = XKeycodeToKeysym( QX11Info::display(), keyCodeX, 0 );
831  // TODO: what's the xor operator in c++?
832  // If this is a keypad key,
833  if( sym >= XK_KP_Space && sym <= XK_KP_9 ) {
834  switch( sym ) {
835  // Leave the following keys unaltered
836  // FIXME: The proper solution is to see which keysyms don't change when shifted.
837  case XK_KP_Multiply:
838  case XK_KP_Add:
839  case XK_KP_Subtract:
840  case XK_KP_Divide:
841  break;
842  default:
843  if( keyModX & modXShift() )
844  keyModX &= ~modXShift();
845  else
846  keyModX |= modXShift();
847  }
848  }
849  }
850 
851  int keyCodeQt;
852  int keyModQt;
853  symXToKeyQt(keySymX, &keyCodeQt);
854  modXToQt(keyModX, &keyModQt);
855 
856  *keyQt = keyCodeQt | keyModQt;
857  return true;
858 }
859 
860 
861 } // end of namespace KKeyServer block
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Fri Dec 7 2012 16:04:40 by doxygen 1.8.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.8.5 API Reference

Skip menu "kdelibs-4.8.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