Debian Codegraph @

qt5/widgetsaddons/qtkeytrans.cpp

raw
1 /***************************************************************************
2 * Copyright (C) 2012~2012 by CSSlayer *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
20 #include "qtkeytrans.h"
21 #include "qtkeytransdata.h"
22 #include <QDebug>
23 #include <QTextCodec>
24 #include <ctype.h>
25 #include <fcitx-config/hotkey.h>
26 #include <algorithm>
27
28 #define _ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
29 #define _ARRAY_END(a) (a + _ARRAY_SIZE(a))
30
31 void qEventToSym(int key, const QString &text, Qt::KeyboardModifiers mod,
32 int &outsym, unsigned int &outstate) {
33 int sym = 0;
34 int state = 0;
35 do {
36 if (text.length() <= 0)
37 break;
38 int uni = text[0].unicode();
39 int *result =
40 std::lower_bound(unicodeHasKey, _ARRAY_END(unicodeHasKey), uni);
41 if (result != _ARRAY_END(unicodeHasKey)) {
42 sym = *result + 0x1000000;
43 break;
44 }
45
46 Unicode2Key *keyMap =
47 std::lower_bound(unicodeKeyMap, _ARRAY_END(unicodeKeyMap), uni);
48 if (keyMap != _ARRAY_END(unicodeKeyMap)) {
49 sym = keyMap->key;
50 break;
51 }
52 } while (0);
53
54 do {
55 if (sym)
56 break;
57
58 QtCode2Key *result = nullptr;
59 if (mod & Qt::KeypadModifier) {
60 result = std::lower_bound(keyPadQtCodeToKey,
61 _ARRAY_END(keyPadQtCodeToKey), key);
62 if (result == _ARRAY_END(keyPadQtCodeToKey))
63 result = nullptr;
64 } else {
65 if (text.isNull()) {
66 result = std::lower_bound(qtCodeToKeyBackup,
67 _ARRAY_END(qtCodeToKeyBackup), key);
68 if (result == _ARRAY_END(qtCodeToKeyBackup))
69 result = nullptr;
70 }
71 if (!result) {
72 result = std::lower_bound(qtCodeToKey, _ARRAY_END(qtCodeToKey), key);
73
74 if (result == _ARRAY_END(qtCodeToKey))
75 result = nullptr;
76 }
77
78 if (!result) {
79 result = std::lower_bound(keyPadQtCodeToKey,
80 _ARRAY_END(keyPadQtCodeToKey), key);
81 if (result == _ARRAY_END(keyPadQtCodeToKey))
82 result = nullptr;
83 }
84 }
85
86 if (result)
87 sym = result->key;
88
89 } while (0);
90
91 state = FcitxKeyState_None;
92
93 if (mod & Qt::CTRL)
94 state |= FcitxKeyState_Ctrl;
95
96 if (mod & Qt::ALT)
97 state |= FcitxKeyState_Alt;
98
99 if (mod & Qt::SHIFT)
100 state |= FcitxKeyState_Shift;
101
102 if (mod & Qt::META)
103 state |= FcitxKeyState_Super;
104
105 outsym = sym;
106 outstate = state;
107 }
108
109 // the next lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining
110 // some special
111 // multimedia keys. They are included here as not every system has them.
112 #define XF86FcitxKey_MonBrightnessUp 0x1008FF02
113 #define XF86FcitxKey_MonBrightnessDown 0x1008FF03
114 #define XF86FcitxKey_KbdLightOnOff 0x1008FF04
115 #define XF86FcitxKey_KbdBrightnessUp 0x1008FF05
116 #define XF86FcitxKey_KbdBrightnessDown 0x1008FF06
117 #define XF86FcitxKey_Standby 0x1008FF10
118 #define XF86FcitxKey_AudioLowerVolume 0x1008FF11
119 #define XF86FcitxKey_AudioMute 0x1008FF12
120 #define XF86FcitxKey_AudioRaiseVolume 0x1008FF13
121 #define XF86FcitxKey_AudioPlay 0x1008FF14
122 #define XF86FcitxKey_AudioStop 0x1008FF15
123 #define XF86FcitxKey_AudioPrev 0x1008FF16
124 #define XF86FcitxKey_AudioNext 0x1008FF17
125 #define XF86FcitxKey_HomePage 0x1008FF18
126 #define XF86FcitxKey_Mail 0x1008FF19
127 #define XF86FcitxKey_Start 0x1008FF1A
128 #define XF86FcitxKey_Search 0x1008FF1B
129 #define XF86FcitxKey_AudioRecord 0x1008FF1C
130 #define XF86FcitxKey_Calculator 0x1008FF1D
131 #define XF86FcitxKey_Memo 0x1008FF1E
132 #define XF86FcitxKey_ToDoList 0x1008FF1F
133 #define XF86FcitxKey_Calendar 0x1008FF20
134 #define XF86FcitxKey_PowerDown 0x1008FF21
135 #define XF86FcitxKey_ContrastAdjust 0x1008FF22
136 #define XF86FcitxKey_Back 0x1008FF26
137 #define XF86FcitxKey_Forward 0x1008FF27
138 #define XF86FcitxKey_Stop 0x1008FF28
139 #define XF86FcitxKey_Refresh 0x1008FF29
140 #define XF86FcitxKey_PowerOff 0x1008FF2A
141 #define XF86FcitxKey_WakeUp 0x1008FF2B
142 #define XF86FcitxKey_Eject 0x1008FF2C
143 #define XF86FcitxKey_ScreenSaver 0x1008FF2D
144 #define XF86FcitxKey_WWW 0x1008FF2E
145 #define XF86FcitxKey_Sleep 0x1008FF2F
146 #define XF86FcitxKey_Favorites 0x1008FF30
147 #define XF86FcitxKey_AudioPause 0x1008FF31
148 #define XF86FcitxKey_AudioMedia 0x1008FF32
149 #define XF86FcitxKey_MyComputer 0x1008FF33
150 #define XF86FcitxKey_LightBulb 0x1008FF35
151 #define XF86FcitxKey_Shop 0x1008FF36
152 #define XF86FcitxKey_History 0x1008FF37
153 #define XF86FcitxKey_OpenURL 0x1008FF38
154 #define XF86FcitxKey_AddFavorite 0x1008FF39
155 #define XF86FcitxKey_HotLinks 0x1008FF3A
156 #define XF86FcitxKey_BrightnessAdjust 0x1008FF3B
157 #define XF86FcitxKey_Finance 0x1008FF3C
158 #define XF86FcitxKey_Community 0x1008FF3D
159 #define XF86FcitxKey_AudioRewind 0x1008FF3E
160 #define XF86FcitxKey_BackForward 0x1008FF3F
161 #define XF86FcitxKey_Launch0 0x1008FF40
162 #define XF86FcitxKey_Launch1 0x1008FF41
163 #define XF86FcitxKey_Launch2 0x1008FF42
164 #define XF86FcitxKey_Launch3 0x1008FF43
165 #define XF86FcitxKey_Launch4 0x1008FF44
166 #define XF86FcitxKey_Launch5 0x1008FF45
167 #define XF86FcitxKey_Launch6 0x1008FF46
168 #define XF86FcitxKey_Launch7 0x1008FF47
169 #define XF86FcitxKey_Launch8 0x1008FF48
170 #define XF86FcitxKey_Launch9 0x1008FF49
171 #define XF86FcitxKey_LaunchA 0x1008FF4A
172 #define XF86FcitxKey_LaunchB 0x1008FF4B
173 #define XF86FcitxKey_LaunchC 0x1008FF4C
174 #define XF86FcitxKey_LaunchD 0x1008FF4D
175 #define XF86FcitxKey_LaunchE 0x1008FF4E
176 #define XF86FcitxKey_LaunchF 0x1008FF4F
177 #define XF86FcitxKey_ApplicationLeft 0x1008FF50
178 #define XF86FcitxKey_ApplicationRight 0x1008FF51
179 #define XF86FcitxKey_Book 0x1008FF52
180 #define XF86FcitxKey_CD 0x1008FF53
181 #define XF86FcitxKey_Calculater 0x1008FF54
182 #define XF86FcitxKey_Clear 0x1008FF55
183 #define XF86FcitxKey_ClearGrab 0x1008FE21
184 #define XF86FcitxKey_Close 0x1008FF56
185 #define XF86FcitxKey_Copy 0x1008FF57
186 #define XF86FcitxKey_Cut 0x1008FF58
187 #define XF86FcitxKey_Display 0x1008FF59
188 #define XF86FcitxKey_DOS 0x1008FF5A
189 #define XF86FcitxKey_Documents 0x1008FF5B
190 #define XF86FcitxKey_Excel 0x1008FF5C
191 #define XF86FcitxKey_Explorer 0x1008FF5D
192 #define XF86FcitxKey_Game 0x1008FF5E
193 #define XF86FcitxKey_Go 0x1008FF5F
194 #define XF86FcitxKey_iTouch 0x1008FF60
195 #define XF86FcitxKey_LogOff 0x1008FF61
196 #define XF86FcitxKey_Market 0x1008FF62
197 #define XF86FcitxKey_Meeting 0x1008FF63
198 #define XF86FcitxKey_MenuKB 0x1008FF65
199 #define XF86FcitxKey_MenuPB 0x1008FF66
200 #define XF86FcitxKey_MySites 0x1008FF67
201 #define XF86FcitxKey_News 0x1008FF69
202 #define XF86FcitxKey_OfficeHome 0x1008FF6A
203 #define XF86FcitxKey_Option 0x1008FF6C
204 #define XF86FcitxKey_Paste 0x1008FF6D
205 #define XF86FcitxKey_Phone 0x1008FF6E
206 #define XF86FcitxKey_Reply 0x1008FF72
207 #define XF86FcitxKey_Reload 0x1008FF73
208 #define XF86FcitxKey_RotateWindows 0x1008FF74
209 #define XF86FcitxKey_RotationPB 0x1008FF75
210 #define XF86FcitxKey_RotationKB 0x1008FF76
211 #define XF86FcitxKey_Save 0x1008FF77
212 #define XF86FcitxKey_Send 0x1008FF7B
213 #define XF86FcitxKey_Spell 0x1008FF7C
214 #define XF86FcitxKey_SplitScreen 0x1008FF7D
215 #define XF86FcitxKey_Support 0x1008FF7E
216 #define XF86FcitxKey_TaskPane 0x1008FF7F
217 #define XF86FcitxKey_Terminal 0x1008FF80
218 #define XF86FcitxKey_Tools 0x1008FF81
219 #define XF86FcitxKey_Travel 0x1008FF82
220 #define XF86FcitxKey_Video 0x1008FF87
221 #define XF86FcitxKey_Word 0x1008FF89
222 #define XF86FcitxKey_Xfer 0x1008FF8A
223 #define XF86FcitxKey_ZoomIn 0x1008FF8B
224 #define XF86FcitxKey_ZoomOut 0x1008FF8C
225 #define XF86FcitxKey_Away 0x1008FF8D
226 #define XF86FcitxKey_Messenger 0x1008FF8E
227 #define XF86FcitxKey_WebCam 0x1008FF8F
228 #define XF86FcitxKey_MailForward 0x1008FF90
229 #define XF86FcitxKey_Pictures 0x1008FF91
230 #define XF86FcitxKey_Music 0x1008FF92
231 #define XF86FcitxKey_Battery 0x1008FF93
232 #define XF86FcitxKey_Bluetooth 0x1008FF94
233 #define XF86FcitxKey_WLAN 0x1008FF95
234 #define XF86FcitxKey_UWB 0x1008FF96
235 #define XF86FcitxKey_AudioForward 0x1008FF97
236 #define XF86FcitxKey_AudioRepeat 0x1008FF98
237 #define XF86FcitxKey_AudioRandomPlay 0x1008FF99
238 #define XF86FcitxKey_Subtitle 0x1008FF9A
239 #define XF86FcitxKey_AudioCycleTrack 0x1008FF9B
240 #define XF86FcitxKey_Time 0x1008FF9F
241 #define XF86FcitxKey_Select 0x1008FFA0
242 #define XF86FcitxKey_View 0x1008FFA1
243 #define XF86FcitxKey_TopMenu 0x1008FFA2
244 #define XF86FcitxKey_Suspend 0x1008FFA7
245 #define XF86FcitxKey_Hibernate 0x1008FFA8
246 #define XF86FcitxKey_TouchpadToggle 0x1008FFA9
247 #define XF86FcitxKey_TouchpadOn 0x1008FFB0
248 #define XF86FcitxKey_TouchpadOff 0x1008FFB1
249
250 // end of XF86keysyms.h
251
252 QT_BEGIN_NAMESPACE
253
254 // keyboard mapping table
255 static const unsigned int KeyTbl[] = {
256
257 // misc keys
258
259 FcitxKey_Escape, Qt::Key_Escape, FcitxKey_Tab, Qt::Key_Tab,
260 FcitxKey_ISO_Left_Tab, Qt::Key_Backtab, FcitxKey_BackSpace,
261 Qt::Key_Backspace, FcitxKey_Return, Qt::Key_Return, FcitxKey_Insert,
262 Qt::Key_Insert, FcitxKey_Delete, Qt::Key_Delete, FcitxKey_Clear,
263 Qt::Key_Delete, FcitxKey_Pause, Qt::Key_Pause, FcitxKey_Print,
264 Qt::Key_Print, 0x1005FF60, Qt::Key_SysReq, // hardcoded Sun SysReq
265 0x1007ff00, Qt::Key_SysReq, // hardcoded X386 SysReq
266
267 // cursor movement
268
269 FcitxKey_Home, Qt::Key_Home, FcitxKey_End, Qt::Key_End, FcitxKey_Left,
270 Qt::Key_Left, FcitxKey_Up, Qt::Key_Up, FcitxKey_Right, Qt::Key_Right,
271 FcitxKey_Down, Qt::Key_Down, FcitxKey_Prior, Qt::Key_PageUp, FcitxKey_Next,
272 Qt::Key_PageDown,
273
274 // modifiers
275
276 FcitxKey_Shift_L, Qt::Key_Shift, FcitxKey_Shift_R, Qt::Key_Shift,
277 FcitxKey_Shift_Lock, Qt::Key_Shift, FcitxKey_Control_L, Qt::Key_Control,
278 FcitxKey_Control_R, Qt::Key_Control, FcitxKey_Meta_L, Qt::Key_Meta,
279 FcitxKey_Meta_R, Qt::Key_Meta, FcitxKey_Alt_L, Qt::Key_Alt, FcitxKey_Alt_R,
280 Qt::Key_Alt, FcitxKey_Caps_Lock, Qt::Key_CapsLock, FcitxKey_Num_Lock,
281 Qt::Key_NumLock, FcitxKey_Scroll_Lock, Qt::Key_ScrollLock, FcitxKey_Super_L,
282 Qt::Key_Super_L, FcitxKey_Super_R, Qt::Key_Super_R, FcitxKey_Menu,
283 Qt::Key_Menu, FcitxKey_Hyper_L, Qt::Key_Hyper_L, FcitxKey_Hyper_R,
284 Qt::Key_Hyper_R, FcitxKey_Help, Qt::Key_Help, 0x1000FF74,
285 Qt::Key_Backtab, // hardcoded HP backtab
286 0x1005FF10, Qt::Key_F11, // hardcoded Sun F36 (labeled F11)
287 0x1005FF11, Qt::Key_F12, // hardcoded Sun F37 (labeled F12)
288
289 // numeric and function keypad keys
290
291 FcitxKey_KP_Space, Qt::Key_Space, FcitxKey_KP_Tab, Qt::Key_Tab,
292 FcitxKey_KP_Enter, Qt::Key_Enter,
293 // FcitxKey_KP_F1, Qt::Key_F1,
294 // FcitxKey_KP_F2, Qt::Key_F2,
295 // FcitxKey_KP_F3, Qt::Key_F3,
296 // FcitxKey_KP_F4, Qt::Key_F4,
297 FcitxKey_KP_Home, Qt::Key_Home, FcitxKey_KP_Left, Qt::Key_Left,
298 FcitxKey_KP_Up, Qt::Key_Up, FcitxKey_KP_Right, Qt::Key_Right,
299 FcitxKey_KP_Down, Qt::Key_Down, FcitxKey_KP_Prior, Qt::Key_PageUp,
300 FcitxKey_KP_Next, Qt::Key_PageDown, FcitxKey_KP_End, Qt::Key_End,
301 FcitxKey_KP_Begin, Qt::Key_Clear, FcitxKey_KP_Insert, Qt::Key_Insert,
302 FcitxKey_KP_Delete, Qt::Key_Delete, FcitxKey_KP_Equal, Qt::Key_Equal,
303 FcitxKey_KP_Multiply, Qt::Key_Asterisk, FcitxKey_KP_Add, Qt::Key_Plus,
304 FcitxKey_KP_Separator, Qt::Key_Comma, FcitxKey_KP_Subtract, Qt::Key_Minus,
305 FcitxKey_KP_Decimal, Qt::Key_Period, FcitxKey_KP_Divide, Qt::Key_Slash,
306
307 // International input method support keys
308
309 // International & multi-key character composition
310 FcitxKey_ISO_Level3_Shift, Qt::Key_AltGr, FcitxKey_Multi_key,
311 Qt::Key_Multi_key, FcitxKey_Codeinput, Qt::Key_Codeinput,
312 FcitxKey_SingleCandidate, Qt::Key_SingleCandidate,
313 FcitxKey_MultipleCandidate, Qt::Key_MultipleCandidate,
314 FcitxKey_PreviousCandidate, Qt::Key_PreviousCandidate,
315
316 // Misc Functions
317 FcitxKey_Mode_switch, Qt::Key_Mode_switch, FcitxKey_script_switch,
318 Qt::Key_Mode_switch,
319
320 // Japanese keyboard support
321 FcitxKey_Kanji, Qt::Key_Kanji, FcitxKey_Muhenkan, Qt::Key_Muhenkan,
322 // FcitxKey_Henkan_Mode, Qt::Key_Henkan_Mode,
323 FcitxKey_Henkan_Mode, Qt::Key_Henkan, FcitxKey_Henkan, Qt::Key_Henkan,
324 FcitxKey_Romaji, Qt::Key_Romaji, FcitxKey_Hiragana, Qt::Key_Hiragana,
325 FcitxKey_Katakana, Qt::Key_Katakana, FcitxKey_Hiragana_Katakana,
326 Qt::Key_Hiragana_Katakana, FcitxKey_Zenkaku, Qt::Key_Zenkaku,
327 FcitxKey_Hankaku, Qt::Key_Hankaku, FcitxKey_Zenkaku_Hankaku,
328 Qt::Key_Zenkaku_Hankaku, FcitxKey_Touroku, Qt::Key_Touroku, FcitxKey_Massyo,
329 Qt::Key_Massyo, FcitxKey_Kana_Lock, Qt::Key_Kana_Lock, FcitxKey_Kana_Shift,
330 Qt::Key_Kana_Shift, FcitxKey_Eisu_Shift, Qt::Key_Eisu_Shift,
331 FcitxKey_Eisu_toggle, Qt::Key_Eisu_toggle,
332 // FcitxKey_Kanji_Bangou, Qt::Key_Kanji_Bangou,
333 // FcitxKey_Zen_Koho, Qt::Key_Zen_Koho,
334 // FcitxKey_Mae_Koho, Qt::Key_Mae_Koho,
335 FcitxKey_Kanji_Bangou, Qt::Key_Codeinput, FcitxKey_Zen_Koho,
336 Qt::Key_MultipleCandidate, FcitxKey_Mae_Koho, Qt::Key_PreviousCandidate,
337
338 #ifdef FcitxKey_KOREAN
339 // Korean keyboard support
340 FcitxKey_Hangul, Qt::Key_Hangul, FcitxKey_Hangul_Start,
341 Qt::Key_Hangul_Start, FcitxKey_Hangul_End, Qt::Key_Hangul_End,
342 FcitxKey_Hangul_Hanja, Qt::Key_Hangul_Hanja, FcitxKey_Hangul_Jamo,
343 Qt::Key_Hangul_Jamo, FcitxKey_Hangul_Romaja, Qt::Key_Hangul_Romaja,
344 // FcitxKey_Hangul_Codeinput, Qt::Key_Hangul_Codeinput,
345 FcitxKey_Hangul_Codeinput, Qt::Key_Codeinput, FcitxKey_Hangul_Jeonja,
346 Qt::Key_Hangul_Jeonja, FcitxKey_Hangul_Banja, Qt::Key_Hangul_Banja,
347 FcitxKey_Hangul_PreHanja, Qt::Key_Hangul_PreHanja,
348 FcitxKey_Hangul_PostHanja, Qt::Key_Hangul_PostHanja,
349 // FcitxKey_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate,
350 // FcitxKey_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate,
351 // FcitxKey_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate,
352 FcitxKey_Hangul_SingleCandidate, Qt::Key_SingleCandidate,
353 FcitxKey_Hangul_MultipleCandidate, Qt::Key_MultipleCandidate,
354 FcitxKey_Hangul_PreviousCandidate, Qt::Key_PreviousCandidate,
355 FcitxKey_Hangul_Special, Qt::Key_Hangul_Special,
356 // FcitxKey_Hangul_switch, Qt::Key_Hangul_switch,
357 FcitxKey_Hangul_switch, Qt::Key_Mode_switch,
358 #endif // FcitxKey_KOREAN
359
360 // dead keys
361 FcitxKey_dead_grave, Qt::Key_Dead_Grave, FcitxKey_dead_acute,
362 Qt::Key_Dead_Acute, FcitxKey_dead_circumflex, Qt::Key_Dead_Circumflex,
363 FcitxKey_dead_tilde, Qt::Key_Dead_Tilde, FcitxKey_dead_macron,
364 Qt::Key_Dead_Macron, FcitxKey_dead_breve, Qt::Key_Dead_Breve,
365 FcitxKey_dead_abovedot, Qt::Key_Dead_Abovedot, FcitxKey_dead_diaeresis,
366 Qt::Key_Dead_Diaeresis, FcitxKey_dead_abovering, Qt::Key_Dead_Abovering,
367 FcitxKey_dead_doubleacute, Qt::Key_Dead_Doubleacute, FcitxKey_dead_caron,
368 Qt::Key_Dead_Caron, FcitxKey_dead_cedilla, Qt::Key_Dead_Cedilla,
369 FcitxKey_dead_ogonek, Qt::Key_Dead_Ogonek, FcitxKey_dead_iota,
370 Qt::Key_Dead_Iota, FcitxKey_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound,
371 FcitxKey_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound,
372 FcitxKey_dead_belowdot, Qt::Key_Dead_Belowdot, FcitxKey_dead_hook,
373 Qt::Key_Dead_Hook, FcitxKey_dead_horn, Qt::Key_Dead_Horn,
374
375 // Special keys from X.org - This include multimedia keys,
376 // wireless/bluetooth/uwb keys, special launcher keys, etc.
377 XF86FcitxKey_Back, Qt::Key_Back, XF86FcitxKey_Forward, Qt::Key_Forward,
378 XF86FcitxKey_Stop, Qt::Key_Stop, XF86FcitxKey_Refresh, Qt::Key_Refresh,
379 XF86FcitxKey_Favorites, Qt::Key_Favorites, XF86FcitxKey_AudioMedia,
380 Qt::Key_LaunchMedia, XF86FcitxKey_OpenURL, Qt::Key_OpenUrl,
381 XF86FcitxKey_HomePage, Qt::Key_HomePage, XF86FcitxKey_Search,
382 Qt::Key_Search, XF86FcitxKey_AudioLowerVolume, Qt::Key_VolumeDown,
383 XF86FcitxKey_AudioMute, Qt::Key_VolumeMute, XF86FcitxKey_AudioRaiseVolume,
384 Qt::Key_VolumeUp, XF86FcitxKey_AudioPlay, Qt::Key_MediaPlay,
385 XF86FcitxKey_AudioStop, Qt::Key_MediaStop, XF86FcitxKey_AudioPrev,
386 Qt::Key_MediaPrevious, XF86FcitxKey_AudioNext, Qt::Key_MediaNext,
387 XF86FcitxKey_AudioRecord, Qt::Key_MediaRecord, XF86FcitxKey_Mail,
388 Qt::Key_LaunchMail, XF86FcitxKey_MyComputer,
389 Qt::Key_Launch0, // ### Qt 6: remap properly
390 XF86FcitxKey_Calculator, Qt::Key_Launch1, XF86FcitxKey_Memo, Qt::Key_Memo,
391 XF86FcitxKey_ToDoList, Qt::Key_ToDoList, XF86FcitxKey_Calendar,
392 Qt::Key_Calendar, XF86FcitxKey_PowerDown, Qt::Key_PowerDown,
393 XF86FcitxKey_ContrastAdjust, Qt::Key_ContrastAdjust, XF86FcitxKey_Standby,
394 Qt::Key_Standby, XF86FcitxKey_MonBrightnessUp, Qt::Key_MonBrightnessUp,
395 XF86FcitxKey_MonBrightnessDown, Qt::Key_MonBrightnessDown,
396 XF86FcitxKey_KbdLightOnOff, Qt::Key_KeyboardLightOnOff,
397 XF86FcitxKey_KbdBrightnessUp, Qt::Key_KeyboardBrightnessUp,
398 XF86FcitxKey_KbdBrightnessDown, Qt::Key_KeyboardBrightnessDown,
399 XF86FcitxKey_PowerOff, Qt::Key_PowerOff, XF86FcitxKey_WakeUp,
400 Qt::Key_WakeUp, XF86FcitxKey_Eject, Qt::Key_Eject, XF86FcitxKey_ScreenSaver,
401 Qt::Key_ScreenSaver, XF86FcitxKey_WWW, Qt::Key_WWW, XF86FcitxKey_Sleep,
402 Qt::Key_Sleep, XF86FcitxKey_LightBulb, Qt::Key_LightBulb, XF86FcitxKey_Shop,
403 Qt::Key_Shop, XF86FcitxKey_History, Qt::Key_History,
404 XF86FcitxKey_AddFavorite, Qt::Key_AddFavorite, XF86FcitxKey_HotLinks,
405 Qt::Key_HotLinks, XF86FcitxKey_BrightnessAdjust, Qt::Key_BrightnessAdjust,
406 XF86FcitxKey_Finance, Qt::Key_Finance, XF86FcitxKey_Community,
407 Qt::Key_Community, XF86FcitxKey_AudioRewind, Qt::Key_AudioRewind,
408 XF86FcitxKey_BackForward, Qt::Key_BackForward, XF86FcitxKey_ApplicationLeft,
409 Qt::Key_ApplicationLeft, XF86FcitxKey_ApplicationRight,
410 Qt::Key_ApplicationRight, XF86FcitxKey_Book, Qt::Key_Book, XF86FcitxKey_CD,
411 Qt::Key_CD, XF86FcitxKey_Calculater, Qt::Key_Calculator, XF86FcitxKey_Clear,
412 Qt::Key_Clear, XF86FcitxKey_ClearGrab, Qt::Key_ClearGrab,
413 XF86FcitxKey_Close, Qt::Key_Close, XF86FcitxKey_Copy, Qt::Key_Copy,
414 XF86FcitxKey_Cut, Qt::Key_Cut, XF86FcitxKey_Display, Qt::Key_Display,
415 XF86FcitxKey_DOS, Qt::Key_DOS, XF86FcitxKey_Documents, Qt::Key_Documents,
416 XF86FcitxKey_Excel, Qt::Key_Excel, XF86FcitxKey_Explorer, Qt::Key_Explorer,
417 XF86FcitxKey_Game, Qt::Key_Game, XF86FcitxKey_Go, Qt::Key_Go,
418 XF86FcitxKey_iTouch, Qt::Key_iTouch, XF86FcitxKey_LogOff, Qt::Key_LogOff,
419 XF86FcitxKey_Market, Qt::Key_Market, XF86FcitxKey_Meeting, Qt::Key_Meeting,
420 XF86FcitxKey_MenuKB, Qt::Key_MenuKB, XF86FcitxKey_MenuPB, Qt::Key_MenuPB,
421 XF86FcitxKey_MySites, Qt::Key_MySites, XF86FcitxKey_News, Qt::Key_News,
422 XF86FcitxKey_OfficeHome, Qt::Key_OfficeHome, XF86FcitxKey_Option,
423 Qt::Key_Option, XF86FcitxKey_Paste, Qt::Key_Paste, XF86FcitxKey_Phone,
424 Qt::Key_Phone, XF86FcitxKey_Reply, Qt::Key_Reply, XF86FcitxKey_Reload,
425 Qt::Key_Reload, XF86FcitxKey_RotateWindows, Qt::Key_RotateWindows,
426 XF86FcitxKey_RotationPB, Qt::Key_RotationPB, XF86FcitxKey_RotationKB,
427 Qt::Key_RotationKB, XF86FcitxKey_Save, Qt::Key_Save, XF86FcitxKey_Send,
428 Qt::Key_Send, XF86FcitxKey_Spell, Qt::Key_Spell, XF86FcitxKey_SplitScreen,
429 Qt::Key_SplitScreen, XF86FcitxKey_Support, Qt::Key_Support,
430 XF86FcitxKey_TaskPane, Qt::Key_TaskPane, XF86FcitxKey_Terminal,
431 Qt::Key_Terminal, XF86FcitxKey_Tools, Qt::Key_Tools, XF86FcitxKey_Travel,
432 Qt::Key_Travel, XF86FcitxKey_Video, Qt::Key_Video, XF86FcitxKey_Word,
433 Qt::Key_Word, XF86FcitxKey_Xfer, Qt::Key_Xfer, XF86FcitxKey_ZoomIn,
434 Qt::Key_ZoomIn, XF86FcitxKey_ZoomOut, Qt::Key_ZoomOut, XF86FcitxKey_Away,
435 Qt::Key_Away, XF86FcitxKey_Messenger, Qt::Key_Messenger,
436 XF86FcitxKey_WebCam, Qt::Key_WebCam, XF86FcitxKey_MailForward,
437 Qt::Key_MailForward, XF86FcitxKey_Pictures, Qt::Key_Pictures,
438 XF86FcitxKey_Music, Qt::Key_Music, XF86FcitxKey_Battery, Qt::Key_Battery,
439 XF86FcitxKey_Bluetooth, Qt::Key_Bluetooth, XF86FcitxKey_WLAN, Qt::Key_WLAN,
440 XF86FcitxKey_UWB, Qt::Key_UWB, XF86FcitxKey_AudioForward,
441 Qt::Key_AudioForward, XF86FcitxKey_AudioRepeat, Qt::Key_AudioRepeat,
442 XF86FcitxKey_AudioRandomPlay, Qt::Key_AudioRandomPlay,
443 XF86FcitxKey_Subtitle, Qt::Key_Subtitle, XF86FcitxKey_AudioCycleTrack,
444 Qt::Key_AudioCycleTrack, XF86FcitxKey_Time, Qt::Key_Time,
445 XF86FcitxKey_Select, Qt::Key_Select, XF86FcitxKey_View, Qt::Key_View,
446 XF86FcitxKey_TopMenu, Qt::Key_TopMenu, XF86FcitxKey_Bluetooth,
447 Qt::Key_Bluetooth, XF86FcitxKey_Suspend, Qt::Key_Suspend,
448 XF86FcitxKey_Hibernate, Qt::Key_Hibernate, XF86FcitxKey_Launch0,
449 Qt::Key_Launch2, // ### Qt 6: remap properly
450 XF86FcitxKey_Launch1, Qt::Key_Launch3, XF86FcitxKey_Launch2,
451 Qt::Key_Launch4, XF86FcitxKey_Launch3, Qt::Key_Launch5,
452 XF86FcitxKey_Launch4, Qt::Key_Launch6, XF86FcitxKey_Launch5,
453 Qt::Key_Launch7, XF86FcitxKey_Launch6, Qt::Key_Launch8,
454 XF86FcitxKey_Launch7, Qt::Key_Launch9, XF86FcitxKey_Launch8,
455 Qt::Key_LaunchA, XF86FcitxKey_Launch9, Qt::Key_LaunchB,
456 XF86FcitxKey_LaunchA, Qt::Key_LaunchC, XF86FcitxKey_LaunchB,
457 Qt::Key_LaunchD, XF86FcitxKey_LaunchC, Qt::Key_LaunchE,
458 XF86FcitxKey_LaunchD, Qt::Key_LaunchF, XF86FcitxKey_LaunchE,
459 Qt::Key_LaunchG, XF86FcitxKey_LaunchF, Qt::Key_LaunchH,
460
461 0, 0};
462
463 static const unsigned short katakanaKeysymsToUnicode[] = {
464 0x0000, 0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1,
465 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3,
466 0x30FC, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD,
467 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD,
468 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC,
469 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE,
470 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9,
471 0x30EA, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C};
472
473 static const unsigned short cyrillicKeysymsToUnicode[] = {
474 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458,
475 0x0459, 0x045a, 0x045b, 0x045c, 0x0000, 0x045e, 0x045f, 0x2116, 0x0402,
476 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a,
477 0x040b, 0x040c, 0x0000, 0x040e, 0x040f, 0x044e, 0x0430, 0x0431, 0x0446,
478 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043a, 0x043b,
479 0x043c, 0x043d, 0x043e, 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443,
480 0x0436, 0x0432, 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447,
481 0x044a, 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
482 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
483 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, 0x042c, 0x042b,
484 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a};
485
486 static const unsigned short greekKeysymsToUnicode[] = {
487 0x0000, 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, 0x038e,
488 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, 0x0000, 0x03ac,
489 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, 0x03cd, 0x03cb, 0x03b0,
490 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0391, 0x0392, 0x0393,
491 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c,
492 0x039d, 0x039e, 0x039f, 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5,
493 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
494 0x0000, 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
495 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0,
496 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9,
497 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
498
499 static const unsigned short technicalKeysymsToUnicode[] = {
500 0x0000, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1, 0x23A3,
501 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8, 0x23AC, 0x0000,
502 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
503 0x0000, 0x2264, 0x2260, 0x2265, 0x222B, 0x2234, 0x221D, 0x221E, 0x0000,
504 0x0000, 0x2207, 0x0000, 0x0000, 0x223C, 0x2243, 0x0000, 0x0000, 0x0000,
505 0x21D4, 0x21D2, 0x2261, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
506 0x221A, 0x0000, 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227,
507 0x2228, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
508 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, 0x0000,
509 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, 0x0000, 0x0000,
510 0x0000, 0x2190, 0x2191, 0x2192, 0x2193, 0x0000};
511
512 static const unsigned short specialKeysymsToUnicode[] = {
513 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x0000, 0x0000,
514 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA,
515 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C,
516 0x2502, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
517
518 static const unsigned short publishingKeysymsToUnicode[] = {
519 0x0000, 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, 0x200a,
520 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, 0x2153, 0x2154,
521 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, 0x2105, 0x0000, 0x0000,
522 0x2012, 0x2329, 0x0000, 0x232a, 0x0000, 0x0000, 0x0000, 0x0000, 0x215b,
523 0x215c, 0x215d, 0x215e, 0x0000, 0x0000, 0x2122, 0x2613, 0x0000, 0x25c1,
524 0x25b7, 0x25cb, 0x25af, 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000,
525 0x2032, 0x2033, 0x0000, 0x271d, 0x0000, 0x25ac, 0x25c0, 0x25b6, 0x25cf,
526 0x25ae, 0x25e6, 0x25ab, 0x25ad, 0x25b3, 0x25bd, 0x2606, 0x2022, 0x25aa,
527 0x25b2, 0x25bc, 0x261c, 0x261e, 0x2663, 0x2666, 0x2665, 0x0000, 0x2720,
528 0x2020, 0x2021, 0x2713, 0x2717, 0x266f, 0x266d, 0x2642, 0x2640, 0x260e,
529 0x2315, 0x2117, 0x2038, 0x201a, 0x201e, 0x0000};
530
531 static const unsigned short aplKeysymsToUnicode[] = {
532 0x0000, 0x0000, 0x0000, 0x003c, 0x0000, 0x0000, 0x003e, 0x0000, 0x2228,
533 0x2227, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
534 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
535 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00af, 0x0000, 0x22a5, 0x2229,
536 0x230a, 0x0000, 0x005f, 0x0000, 0x0000, 0x0000, 0x2218, 0x0000, 0x2395,
537 0x0000, 0x22a4, 0x25cb, 0x0000, 0x0000, 0x0000, 0x2308, 0x0000, 0x0000,
538 0x222a, 0x0000, 0x2283, 0x0000, 0x2282, 0x0000, 0x22a2, 0x0000, 0x0000,
539 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
540 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
541 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
542 0x0000, 0x0000, 0x22a3, 0x0000, 0x0000, 0x0000};
543
544 static const unsigned short koreanKeysymsToUnicode[] = {
545 0x0000, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, 0x3138,
546 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f, 0x3140, 0x3141,
547 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147, 0x3148, 0x3149, 0x314a,
548 0x314b, 0x314c, 0x314d, 0x314e, 0x314f, 0x3150, 0x3151, 0x3152, 0x3153,
549 0x3154, 0x3155, 0x3156, 0x3157, 0x3158, 0x3159, 0x315a, 0x315b, 0x315c,
550 0x315d, 0x315e, 0x315f, 0x3160, 0x3161, 0x3162, 0x3163, 0x11a8, 0x11a9,
551 0x11aa, 0x11ab, 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2,
552 0x11b3, 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb,
553 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x316d, 0x3171,
554 0x3178, 0x317f, 0x3181, 0x3184, 0x3186, 0x318d, 0x318e, 0x11eb, 0x11f0,
555 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9};
556
557 static QChar keysymToUnicode(unsigned char byte3, unsigned char byte4) {
558 switch (byte3) {
559 case 0x04:
560 // katakana
561 if (byte4 > 0xa0 && byte4 < 0xe0)
562 return QChar(katakanaKeysymsToUnicode[byte4 - 0xa0]);
563 else if (byte4 == 0x7e)
564 return QChar(0x203e); // Overline
565 break;
566 case 0x06:
567 // russian, use lookup table
568 if (byte4 > 0xa0)
569 return QChar(cyrillicKeysymsToUnicode[byte4 - 0xa0]);
570 break;
571 case 0x07:
572 // greek
573 if (byte4 > 0xa0)
574 return QChar(greekKeysymsToUnicode[byte4 - 0xa0]);
575 break;
576 case 0x08:
577 // technical
578 if (byte4 > 0xa0)
579 return QChar(technicalKeysymsToUnicode[byte4 - 0xa0]);
580 break;
581 case 0x09:
582 // special
583 if (byte4 >= 0xe0)
584 return QChar(specialKeysymsToUnicode[byte4 - 0xe0]);
585 break;
586 case 0x0a:
587 // publishing
588 if (byte4 > 0xa0)
589 return QChar(publishingKeysymsToUnicode[byte4 - 0xa0]);
590 break;
591 case 0x0b:
592 // APL
593 if (byte4 > 0xa0)
594 return QChar(aplKeysymsToUnicode[byte4 - 0xa0]);
595 break;
596 case 0x0e:
597 // Korean
598 if (byte4 > 0xa0)
599 return QChar(koreanKeysymsToUnicode[byte4 - 0xa0]);
600 break;
601 default:
602 break;
603 }
604 return QChar(0x0);
605 }
606
607 int translateKeySym(uint key) {
608 int code = -1;
609 int i = 0; // any other keys
610 while (KeyTbl[i]) {
611 if (key == KeyTbl[i]) {
612 code = (int)KeyTbl[i + 1];
613 break;
614 }
615 i += 2;
616 }
617 return code;
618 }
619
620 QString translateKeySym(int keysym, uint xmodifiers, int &code,
621 Qt::KeyboardModifiers &modifiers, QByteArray &chars,
622 int &count) {
623 // all keysyms smaller than 0xff00 are actally keys that can be mapped to
624 // unicode chars
625
626 QTextCodec *mapper = QTextCodec::codecForLocale();
627 QChar converted;
628
629 if (/*count == 0 &&*/ keysym < 0xff00) {
630 unsigned char byte3 = (unsigned char)(keysym >> 8);
631 int mib = -1;
632 switch (byte3) {
633 case 0: // Latin 1
634 case 1: // Latin 2
635 case 2: // latin 3
636 case 3: // latin4
637 mib = byte3 + 4;
638 break;
639 case 5: // arabic
640 mib = 82;
641 break;
642 case 12: // Hebrew
643 mib = 85;
644 break;
645 case 13: // Thai
646 mib = 2259;
647 break;
648 case 4: // kana
649 case 6: // cyrillic
650 case 7: // greek
651 case 8: // technical, no mapping here at the moment
652 case 9: // Special
653 case 10: // Publishing
654 case 11: // APL
655 case 14: // Korean, no mapping
656 mib = -1; // manual conversion
657 mapper = 0;
658 converted = keysymToUnicode(byte3, keysym & 0xff);
659 break;
660 case 0x20:
661 // currency symbols
662 if (keysym >= 0x20a0 && keysym <= 0x20ac) {
663 mib = -1; // manual conversion
664 mapper = 0;
665 converted = (uint)keysym;
666 }
667 break;
668 default:
669 break;
670 }
671 if (mib != -1) {
672 mapper = QTextCodec::codecForMib(mib);
673 if (chars.isEmpty())
674 chars.resize(1);
675 chars[0] = (unsigned char)(keysym & 0xff); // get only the fourth
676 // bit for conversion
677 // later
678 count = 1;
679 }
680 } else if (keysym >= 0x1000000 && keysym <= 0x100ffff) {
681 converted = (ushort)(keysym - 0x1000000);
682 mapper = 0;
683 }
684 if (count < (int)chars.size() - 1)
685 chars[count] = '\0';
686
687 QString text;
688 if (!mapper && converted.unicode() != 0x0) {
689 text = converted;
690 } else if (!chars.isEmpty()) {
691 // convert chars (8bit) to text (unicode).
692 if (mapper)
693 text = mapper->toUnicode(chars.constData(), count, 0);
694 if (text.isEmpty()) {
695 // no mapper, or codec couldn't convert to unicode (this
696 // can happen when running in the C locale or with no LANG
697 // set). try converting from latin-1
698 text = QString::fromLatin1(chars);
699 }
700 }
701
702 if (xmodifiers & FcitxKeyState_Alt) {
703 modifiers |= Qt::AltModifier;
704 }
705
706 if (xmodifiers & FcitxKeyState_Shift) {
707 modifiers |= Qt::ShiftModifier;
708 }
709
710 if (xmodifiers & FcitxKeyState_Ctrl) {
711 modifiers |= Qt::ControlModifier;
712 }
713
714 if (xmodifiers & FcitxKeyState_Super) {
715 modifiers |= Qt::MetaModifier;
716 }
717
718 // Commentary in X11/keysymdef says that X codes match ASCII, so it
719 // is safe to use the locale functions to process X codes in ISO8859-1.
720 //
721 // This is mainly for compatibility - applications should not use the
722 // Qt keycodes between 128 and 255, but should rather use the
723 // QKeyEvent::text().
724 //
725 if (keysym < 128 || (keysym < 256 && (!mapper || mapper->mibEnum() == 4))) {
726 // upper-case key, if known
727 code = isprint((int)keysym) ? toupper((int)keysym) : 0;
728 } else if (keysym >= FcitxKey_F1 && keysym <= FcitxKey_F35) {
729 // function keys
730 code = Qt::Key_F1 + ((int)keysym - FcitxKey_F1);
731 } else if (keysym >= FcitxKey_KP_Space && keysym <= FcitxKey_KP_9) {
732 if (keysym >= FcitxKey_KP_0) {
733 // numeric keypad keys
734 code = Qt::Key_0 + ((int)keysym - FcitxKey_KP_0);
735 } else {
736 code = translateKeySym(keysym);
737 }
738 modifiers |= Qt::KeypadModifier;
739 } else if (text.length() == 1 && text.unicode()->unicode() > 0x1f &&
740 text.unicode()->unicode() != 0x7f &&
741 !(keysym >= FcitxKey_dead_grave &&
742 keysym <= FcitxKey_dead_horn)) {
743 code = text.unicode()->toUpper().unicode();
744 } else {
745 // any other keys
746 code = translateKeySym(keysym);
747
748 if (code == Qt::Key_Tab && (modifiers & Qt::ShiftModifier)) {
749 // map shift+tab to shift+backtab, QShortcutMap knows about it
750 // and will handle it.
751 code = Qt::Key_Backtab;
752 text = QString();
753 }
754 }
755
756 return text;
757 }
758
759 bool symToKeyQt(int sym, unsigned int state, int &qtcode,
760 Qt::KeyboardModifiers &mod) {
761 QByteArray chars;
762 int count = 0;
763
764 translateKeySym(sym, state, qtcode, mod, chars, count);
765
766 return qtcode >= 0;
767 }
768
769 bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
770 unsigned int &state) {
771 qEventToSym(qtcode, QString(), mod, sym, state);
772
773 return sym >= 0;
774 }