29 # define XK_MISCELLANY
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
65 uint sym, symVariation;
94 { XK_ISO_Left_Tab,
"Backtab" },
99 { XK_Scroll_Lock,
I18N_NOOP(
"ScrollLock") },
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 },
131 { Qt::Key_Print, XK_F22 },
133 { Qt::Key_Print, XK_Print },
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 },
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 },
195 {
'/', XK_KP_Divide },
196 {
'*', XK_KP_Multiply },
197 {
'-', XK_KP_Subtract },
199 { Qt::Key_Return, XK_KP_Enter }
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
481 if ( !QX11Info::display() ) {
482 kError() <<
"QX11Info::display() returns 0. I'm probably going to crash now." << endl;
483 kError() <<
"If this is a KApplication initialized without GUI stuff, change it to be "
484 "initialized with GUI stuff." << endl;
488 # define checkDisplay()
510 XModifierKeymap* xmk = XGetModifierMapping( QX11Info::display() );
512 int min_keycode, max_keycode;
513 int keysyms_per_keycode = 0;
515 XDisplayKeycodes( QX11Info::display(), &min_keycode, &max_keycode );
516 XFree( XGetKeyboardMapping( QX11Info::display(), min_keycode, 1, &keysyms_per_keycode ));
518 for(
int i = Mod1MapIndex; i < 8; i++ ) {
519 uint
mask = (1 << i);
520 uint keySymX = NoSymbol;
526 for(
int j = 0; j < xmk->max_keypermod; ++j ) {
528 for(
int k = 0; k < keysyms_per_keycode; ++k ) {
530 keySymX = XKeycodeToKeysym( QX11Info::display(), xmk->modifiermap[xmk->max_keypermod * i + j], k );
553 #ifdef KKEYSERVER_DEBUG
565 #ifdef KKEYSERVER_DEBUG
566 kDebug() <<
"Hyper conflicts with super, meta or alt.";
574 #ifdef KKEYSERVER_DEBUG
575 kDebug() <<
"Super conflicts with meta or alt.";
584 #ifdef KKEYSERVER_DEBUG
585 kDebug() <<
"Meta conflicts with alt.";
592 #ifdef KKEYSERVER_DEBUG
593 kDebug() <<
"Meta is not set or conflicted with alt.";
596 #ifdef KKEYSERVER_DEBUG
597 kDebug() <<
"Using super for meta";
602 #ifdef KKEYSERVER_DEBUG
603 kDebug() <<
"Using hyper for meta";
613 #ifdef KKEYSERVER_DEBUG
624 kWarning() <<
"Your keyboard setup doesn't provide a key to use for meta. See 'xmodmap -pm' or 'xkbcomp $DISPLAY'";
630 XFreeModifiermap( xmk );
660 if( sym == XK_Sys_Req )
return Qt::ALT;
661 if( sym == XK_Break )
return Qt::CTRL;
665 if( c.isLetter() && c.toLower() != c.toUpper() && sym == c.toUpper().unicode() )
669 uchar code = XKeysymToKeycode( QX11Info::display(), sym );
674 if( sym == XKeycodeToKeysym( QX11Info::display(), code, 0 ) )
676 else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 1 ) )
678 else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 2 ) )
680 else if( sym == XKeycodeToKeysym( QX11Info::display(), code, 3 ) )
697 if( !sym || !
keyQtToModX( (keyQt & Qt::KeyboardModifierMask) | modExtra, &mod ) ) {
702 *keyCode = XKeysymToKeycode( QX11Info::display(), sym );
708 int symQt = keyQt & ~Qt::KeyboardModifierMask;
710 if( symQt < 0x1000 ) {
711 *keySym = QChar(symQt).toUpper().unicode();
716 for( uint i = 0; i <
sizeof(
g_rgQtToSymX)/
sizeof(TransKey); i++ ) {
724 if( symQt != Qt::Key_Shift && symQt != Qt::Key_Control && symQt != Qt::Key_Alt &&
725 symQt != Qt::Key_Meta && symQt != Qt::Key_Direction_L && symQt != Qt::Key_Direction_R )
726 kDebug(125) <<
"Sym::initQt( " << QString::number(keyQt,16) <<
" ): failed to convert key.";
732 *keyQt = Qt::Key_unknown;
733 if( keySym < 0x1000 ) {
734 if( keySym >=
'a' && keySym <=
'z' )
735 *keyQt = QChar(keySym).toUpper().unicode();
740 else if( keySym < 0x3000 )
744 for( uint i = 0; i <
sizeof(
g_rgQtToSymX)/
sizeof(TransKey); i++ )
751 return (*keyQt != Qt::Key_unknown);
763 for(
int i = 0; i < 4; i++ ) {
783 for(
int i = 0; i < 4; i++ ) {
796 XKeyPressedEvent event;
800 event.type = KeyPress;
801 event.display = QX11Info::display();
803 event.keycode = codeX;
805 XLookupString( &event, 0, 0, &keySym, 0 );
806 *sym = (uint) keySym;
819 Q_ASSERT(e->type == KeyPress || e->type == KeyRelease);
821 uchar keyCodeX = e->xkey.keycode;
826 XLookupString( (XKeyEvent*) e, buffer, 15, &keySym, 0 );
827 uint keySymX = (uint)keySym;
832 uint sym = XKeycodeToKeysym( QX11Info::display(), keyCodeX, 0 );
835 if( sym >= XK_KP_Space && sym <= XK_KP_9 ) {
858 *keyQt = keyCodeQt | keyModQt;