Debian Codegraph @

gtk-input-context/client-gtk/qt-keysym-map.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2001 Ellis Whitehead <[email protected]>
3 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * Copyright (C) 2010, Intel Corporation.
5 *
6 * Author: Raymond Liu <[email protected]>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23
24 #include <X11/keysym.h>
25 #include <qstring.h>
26
27 #include "qt-keysym-map.h"
28 #include "debug.h"
29
30
31 typedef struct {
32 uint XKeySym;
33 int QtKey;
34 } KeySymMap;
35
36 // keyboard mapping table, modified from QKeymapper_x11.cpp
37 static const KeySymMap QtKeyXSymMaps[] = {
38
39 // misc keys
40
41 { XK_Escape, Qt::Key_Escape },
42 { XK_Tab, Qt::Key_Tab },
43 { XK_ISO_Left_Tab, Qt::Key_Backtab },
44 { XK_BackSpace, Qt::Key_Backspace },
45 { XK_Return, Qt::Key_Return },
46 { XK_Insert, Qt::Key_Insert },
47 { XK_Delete, Qt::Key_Delete },
48 { XK_Clear, Qt::Key_Delete },
49 { XK_Pause, Qt::Key_Pause },
50 { XK_Print, Qt::Key_Print },
51 { 0x1005FF60, Qt::Key_SysReq }, // hardcoded Sun SysReq
52 { 0x1007ff00, Qt::Key_SysReq }, // hardcoded X386 SysReq
53
54 // cursor movement
55
56 { XK_Home, Qt::Key_Home },
57 { XK_End, Qt::Key_End },
58 { XK_Left, Qt::Key_Left },
59 { XK_Up, Qt::Key_Up },
60 { XK_Right, Qt::Key_Right },
61 { XK_Down, Qt::Key_Down },
62 { XK_Prior, Qt::Key_PageUp },
63 { XK_Next, Qt::Key_PageDown },
64
65 // modifiers
66
67 { XK_Shift_L, Qt::Key_Shift },
68 { XK_Shift_R, Qt::Key_Shift },
69 { XK_Shift_Lock, Qt::Key_Shift },
70 { XK_Control_L, Qt::Key_Control },
71 { XK_Control_R, Qt::Key_Control },
72 { XK_Meta_L, Qt::Key_Meta },
73 { XK_Meta_R, Qt::Key_Meta },
74 { XK_Alt_L, Qt::Key_Alt },
75 { XK_Alt_R, Qt::Key_Alt },
76 { XK_Caps_Lock, Qt::Key_CapsLock },
77 { XK_Num_Lock, Qt::Key_NumLock },
78 { XK_Scroll_Lock, Qt::Key_ScrollLock },
79 { XK_Super_L, Qt::Key_Super_L },
80 { XK_Super_R, Qt::Key_Super_R },
81 { XK_Menu, Qt::Key_Menu },
82 { XK_Hyper_L, Qt::Key_Hyper_L },
83 { XK_Hyper_R, Qt::Key_Hyper_R },
84 { XK_Help, Qt::Key_Help },
85 { 0x1000FF74, Qt::Key_Backtab }, // hardcoded HP backtab
86 { 0x1005FF10, Qt::Key_F11 }, // hardcoded Sun F36 (labeled F11)
87 { 0x1005FF11, Qt::Key_F12 }, // hardcoded Sun F37 (labeled F12)
88
89 // function keys
90
91 { XK_F1, Qt::Key_F1 },
92 { XK_F2, Qt::Key_F2 },
93 { XK_F3, Qt::Key_F3 },
94 { XK_F4, Qt::Key_F4 },
95 { XK_F5, Qt::Key_F5 },
96 { XK_F6, Qt::Key_F6 },
97 { XK_F7, Qt::Key_F7 },
98 { XK_F8, Qt::Key_F8 },
99 { XK_F9, Qt::Key_F9 },
100 { XK_F10, Qt::Key_F10 },
101 { XK_F11, Qt::Key_F11 },
102 { XK_F12, Qt::Key_F12 },
103 { XK_F13, Qt::Key_F13 },
104 { XK_F14, Qt::Key_F14 },
105 { XK_F15, Qt::Key_F15 },
106 { XK_F16, Qt::Key_F16 },
107 { XK_F17, Qt::Key_F17 },
108 { XK_F18, Qt::Key_F18 },
109 { XK_F19, Qt::Key_F19 },
110 { XK_F20, Qt::Key_F20 },
111
112 // numeric and function keypad keys
113
114 { XK_KP_Space, Qt::Key_Space },
115 { XK_KP_Tab, Qt::Key_Tab },
116 { XK_KP_Enter, Qt::Key_Enter },
117 { XK_KP_F1, Qt::Key_F1 },
118 { XK_KP_F2, Qt::Key_F2 },
119 { XK_KP_F3, Qt::Key_F3 },
120 { XK_KP_F4, Qt::Key_F4 },
121
122 { XK_KP_Home, Qt::Key_Home },
123 { XK_KP_Left, Qt::Key_Left },
124 { XK_KP_Up, Qt::Key_Up },
125 { XK_KP_Right, Qt::Key_Right },
126 { XK_KP_Down, Qt::Key_Down },
127 { XK_KP_Prior, Qt::Key_PageUp },
128 { XK_KP_Next, Qt::Key_PageDown },
129 { XK_KP_End, Qt::Key_End },
130 { XK_KP_Begin, Qt::Key_Clear },
131 { XK_KP_Insert, Qt::Key_Insert },
132 { XK_KP_Delete, Qt::Key_Delete },
133 { XK_KP_Equal, Qt::Key_Equal },
134 { XK_KP_Multiply, Qt::Key_Asterisk },
135 { XK_KP_Add, Qt::Key_Plus },
136 { XK_KP_Separator, Qt::Key_Comma },
137 { XK_KP_Subtract, Qt::Key_Minus },
138 { XK_KP_Decimal, Qt::Key_Period },
139 { XK_KP_Divide, Qt::Key_Slash },
140
141 { XK_KP_0, Qt::Key_0 },
142 { XK_KP_1, Qt::Key_1 },
143 { XK_KP_2, Qt::Key_2 },
144 { XK_KP_3, Qt::Key_3 },
145 { XK_KP_4, Qt::Key_4 },
146 { XK_KP_5, Qt::Key_5 },
147 { XK_KP_6, Qt::Key_6 },
148 { XK_KP_7, Qt::Key_7 },
149 { XK_KP_8, Qt::Key_8 },
150 { XK_KP_9, Qt::Key_9 },
151
152 //International input method support keys
153 //International & multi-key character composition
154
155 { XK_ISO_Level3_Shift, Qt::Key_AltGr },
156 { XK_Multi_key, Qt::Key_Multi_key },
157 { XK_Codeinput, Qt::Key_Codeinput },
158 { XK_SingleCandidate, Qt::Key_SingleCandidate },
159 { XK_MultipleCandidate, Qt::Key_MultipleCandidate },
160 { XK_PreviousCandidate, Qt::Key_PreviousCandidate },
161
162 // Misc Functions
163 { XK_Mode_switch, Qt::Key_Mode_switch },
164 { XK_script_switch, Qt::Key_Mode_switch },
165
166 // Japanese keyboard support
167 { XK_Kanji, Qt::Key_Kanji },
168 { XK_Muhenkan, Qt::Key_Muhenkan },
169 //{ XK_Henkan_Mode, Qt::Key_Henkan_Mode },
170 { XK_Henkan_Mode, Qt::Key_Henkan },
171 { XK_Henkan, Qt::Key_Henkan },
172 { XK_Romaji, Qt::Key_Romaji },
173 { XK_Hiragana, Qt::Key_Hiragana },
174 { XK_Katakana, Qt::Key_Katakana },
175 { XK_Hiragana_Katakana, Qt::Key_Hiragana_Katakana },
176 { XK_Zenkaku, Qt::Key_Zenkaku },
177 { XK_Hankaku, Qt::Key_Hankaku },
178 { XK_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku },
179 { XK_Touroku, Qt::Key_Touroku },
180 { XK_Massyo, Qt::Key_Massyo },
181 { XK_Kana_Lock, Qt::Key_Kana_Lock },
182 { XK_Kana_Shift, Qt::Key_Kana_Shift },
183 { XK_Eisu_Shift, Qt::Key_Eisu_Shift },
184 { XK_Eisu_toggle, Qt::Key_Eisu_toggle },
185 //{ XK_Kanji_Bangou, Qt::Key_Kanji_Bangou },
186 //{ XK_Zen_Koho, Qt::Key_Zen_Koho },
187 //{ XK_Mae_Koho, Qt::Key_Mae_Koho },
188 { XK_Kanji_Bangou, Qt::Key_Codeinput },
189 { XK_Zen_Koho, Qt::Key_MultipleCandidate },
190 { XK_Mae_Koho, Qt::Key_PreviousCandidate },
191
192 #ifdef XK_KOREAN
193 // Korean keyboard support
194 { XK_Hangul, Qt::Key_Hangul },
195 { XK_Hangul_Start, Qt::Key_Hangul_Start },
196 { XK_Hangul_End, Qt::Key_Hangul_End },
197 { XK_Hangul_Hanja, Qt::Key_Hangul_Hanja },
198 { XK_Hangul_Jamo, Qt::Key_Hangul_Jamo },
199 { XK_Hangul_Romaja, Qt::Key_Hangul_Romaja },
200 //{ XK_Hangul_Codeinput, Qt::Key_Hangul_Codeinput },
201 { XK_Hangul_Codeinput, Qt::Key_Codeinput },
202 { XK_Hangul_Jeonja, Qt::Key_Hangul_Jeonja },
203 { XK_Hangul_Banja, Qt::Key_Hangul_Banja },
204 { XK_Hangul_PreHanja, Qt::Key_Hangul_PreHanja },
205 { XK_Hangul_PostHanja, Qt::Key_Hangul_PostHanja },
206 //{ XK_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate },
207 //{ XK_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate },
208 //{ XK_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate },
209 { XK_Hangul_SingleCandidate, Qt::Key_SingleCandidate },
210 { XK_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate },
211 { XK_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate },
212 { XK_Hangul_Special, Qt::Key_Hangul_Special },
213 //{ XK_Hangul_switch, Qt::Key_Hangul_switch },
214 { XK_Hangul_switch, Qt::Key_Mode_switch },
215 #endif // XK_KOREAN
216
217 // dead keys
218 { XK_dead_grave, Qt::Key_Dead_Grave },
219 { XK_dead_acute, Qt::Key_Dead_Acute },
220 { XK_dead_circumflex, Qt::Key_Dead_Circumflex },
221 { XK_dead_tilde, Qt::Key_Dead_Tilde },
222 { XK_dead_macron, Qt::Key_Dead_Macron },
223 { XK_dead_breve, Qt::Key_Dead_Breve },
224 { XK_dead_abovedot, Qt::Key_Dead_Abovedot },
225 { XK_dead_diaeresis, Qt::Key_Dead_Diaeresis },
226 { XK_dead_abovering, Qt::Key_Dead_Abovering },
227 { XK_dead_doubleacute, Qt::Key_Dead_Doubleacute },
228 { XK_dead_caron, Qt::Key_Dead_Caron },
229 { XK_dead_cedilla, Qt::Key_Dead_Cedilla },
230 { XK_dead_ogonek, Qt::Key_Dead_Ogonek },
231 { XK_dead_iota, Qt::Key_Dead_Iota },
232 { XK_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound },
233 { XK_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound },
234 { XK_dead_belowdot, Qt::Key_Dead_Belowdot },
235 { XK_dead_hook, Qt::Key_Dead_Hook },
236 { XK_dead_horn, Qt::Key_Dead_Horn },
237
238 { 0, 0}
239 };
240
241 int
242 QtKeyToXKeySym(int qtKey) {
243
244 // TODO: Need to complete this function for all scenario.
245 int i;
246 int count = sizeof(QtKeyXSymMaps)/sizeof(KeySymMap);
247
248 if (qtKey < 0x1000) {
249 //return QChar(qtKey).toLower().unicode();
250 return qtKey;
251 }
252
253 for(i = 0; i < count; i++ ) {
254 if( QtKeyXSymMaps[i].QtKey == qtKey ) {
255 return QtKeyXSymMaps[i].XKeySym;
256 }
257 }
258
259 return 0;
260 }
261
262
263 int
264 XKeySymToQTKey(uint keySym)
265 {
266 int i;
267 int count = sizeof(QtKeyXSymMaps)/sizeof(KeySymMap);
268
269 if ((keySym < 0x1000)) {
270 //if (keySym >= 'a' && keySym <= 'z')
271 // return QChar(keySym).toUpper().toAscii();
272 return keySym;
273 }
274
275 #ifdef Q_WS_WIN
276 if(keySym < 0x3000)
277 return keySym;
278 #else
279 if (keySym < 0x3000 )
280 return keySym | Qt::UNICODE_ACCEL;
281
282 for(i = 0; i < count; i++)
283 if(QtKeyXSymMaps[i].XKeySym == keySym)
284 return QtKeyXSymMaps[i].QtKey;
285 #endif
286 return Qt::Key_unknown;
287 }
288