Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11keyboard.c @ 2295:dbc6d1893869
Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Tue, 08 Jan 2008 00:10:46 +0000 |
parents | a344e42bce3b |
children | 0869721b488f |
comparison
equal
deleted
inserted
replaced
2294:386ebf50dd91 | 2295:dbc6d1893869 |
---|---|
23 | 23 |
24 #include "SDL_x11video.h" | 24 #include "SDL_x11video.h" |
25 | 25 |
26 #include "../../events/SDL_keyboard_c.h" | 26 #include "../../events/SDL_keyboard_c.h" |
27 | 27 |
28 void | 28 #include <X11/keysym.h> |
29 | |
30 #include "imKStoUCS.h" | |
31 | |
32 /* Used for two purposes: - by X11_GetLayoutKey(), with physical = | |
33 false, to convert a KeySym to the corresponding layout key code | |
34 (SDLK_ ones and some character ones - most character KeySyms are | |
35 handled by X11_KeySymToUcs4() after this function returns | |
36 SDLK_UNKNOWN for them). - by X11_InitKeyboard(), with physical = | |
37 true, to build a makeshift translation table based on the KeySyms | |
38 when none of the predefined KeyCode- to-SDLKey tables fits. This | |
39 is *not* correct anywhere but on a US layout, since the | |
40 translation table deals with physical key codes, while the X11 | |
41 KeySym corresponds to our concept of a layout key code, but it's | |
42 better than nothing. | |
43 */ | |
44 | |
45 /* KeyCode-to-SDLKey translation tables for various X servers. Which one to use | |
46 is decided in X11_InitKeyboard(). | |
47 */ | |
48 | |
49 static SDLKey macKeyCodeToSDLK[]; | |
50 static SDLKey xorgLinuxKeyCodeToSDLK[]; | |
51 | |
52 static SDLKey *keyCodeToSDLKeyTables[] = { | |
53 xorgLinuxKeyCodeToSDLK, | |
54 macKeyCodeToSDLK, | |
55 NULL | |
56 }; | |
57 | |
58 /* *INDENT-OFF* */ | |
59 | |
60 /* These are just Mac virtual key codes + 8 (see SDL/src/video/cocoa/ | |
61 SDL_cocoakeys.h for more info). Observed to work with Apple X11 on | |
62 Mac OS X 10.4. May also work on older Linux distributions on Mac | |
63 hardware. | |
64 */ | |
65 static SDLKey macKeyCodeToSDLK[] = { | |
66 /* 0 */ SDLK_UNKNOWN, | |
67 /* 1 */ SDLK_UNKNOWN, | |
68 /* 2 */ SDLK_UNKNOWN, | |
69 /* 3 */ SDLK_UNKNOWN, | |
70 /* 4 */ SDLK_UNKNOWN, | |
71 /* 5 */ SDLK_UNKNOWN, | |
72 /* 6 */ SDLK_UNKNOWN, | |
73 /* 7 */ SDLK_UNKNOWN, | |
74 /* 8 */ SDLK_A, | |
75 /* 9 */ SDLK_S, | |
76 /* 10 */ SDLK_D, | |
77 /* 11 */ SDLK_F, | |
78 /* 12 */ SDLK_H, | |
79 /* 13 */ SDLK_G, | |
80 /* 14 */ SDLK_Z, | |
81 /* 15 */ SDLK_X, | |
82 /* 16 */ SDLK_C, | |
83 /* 17 */ SDLK_V, | |
84 /* 18 */ SDLK_GRAVE, | |
85 /* 19 */ SDLK_B, | |
86 /* 20 */ SDLK_Q, | |
87 /* 21 */ SDLK_W, | |
88 /* 22 */ SDLK_E, | |
89 /* 23 */ SDLK_R, | |
90 /* 24 */ SDLK_Y, | |
91 /* 25 */ SDLK_T, | |
92 /* 26 */ SDLK_1, | |
93 /* 27 */ SDLK_2, | |
94 /* 28 */ SDLK_3, | |
95 /* 29 */ SDLK_4, | |
96 /* 30 */ SDLK_6, | |
97 /* 31 */ SDLK_5, | |
98 /* 32 */ SDLK_EQUALS, | |
99 /* 33 */ SDLK_9, | |
100 /* 34 */ SDLK_7, | |
101 /* 35 */ SDLK_HYPHENMINUS, | |
102 /* 36 */ SDLK_8, | |
103 /* 37 */ SDLK_0, | |
104 /* 38 */ SDLK_RIGHTBRACKET, | |
105 /* 39 */ SDLK_O, | |
106 /* 40 */ SDLK_U, | |
107 /* 41 */ SDLK_LEFTBRACKET, | |
108 /* 42 */ SDLK_I, | |
109 /* 43 */ SDLK_P, | |
110 /* 44 */ SDLK_RETURN, | |
111 /* 45 */ SDLK_L, | |
112 /* 46 */ SDLK_J, | |
113 /* 47 */ SDLK_APOSTROPHE, | |
114 /* 48 */ SDLK_K, | |
115 /* 49 */ SDLK_SEMICOLON, | |
116 /* 50 */ SDLK_BACKSLASH, | |
117 /* 51 */ SDLK_COMMA, | |
118 /* 52 */ SDLK_SLASH, | |
119 /* 53 */ SDLK_N, | |
120 /* 54 */ SDLK_M, | |
121 /* 55 */ SDLK_PERIOD, | |
122 /* 56 */ SDLK_TAB, | |
123 /* 57 */ SDLK_SPACE, | |
124 /* 58 */ SDLK_NONUSBACKSLASH, | |
125 /* 59 */ SDLK_BACKSPACE, | |
126 /* 60 */ SDLK_KP_ENTER, | |
127 /* 61 */ SDLK_ESCAPE, | |
128 /* 62 */ SDLK_RMETA, | |
129 /* 63 */ SDLK_LMETA, | |
130 /* 64 */ SDLK_LSHIFT, | |
131 /* 65 */ SDLK_CAPSLOCK, | |
132 /* 66 */ SDLK_LALT, | |
133 /* 67 */ SDLK_LCTRL, | |
134 /* 68 */ SDLK_RSHIFT, | |
135 /* 69 */ SDLK_RALT, | |
136 /* 70 */ SDLK_RCTRL, | |
137 /* 71 */ SDLK_NONE, | |
138 /* 72 */ SDLK_UNKNOWN, | |
139 /* 73 */ SDLK_KP_PERIOD, | |
140 /* 74 */ SDLK_UNKNOWN, | |
141 /* 75 */ SDLK_KP_MULTIPLY, | |
142 /* 76 */ SDLK_UNKNOWN, | |
143 /* 77 */ SDLK_KP_PLUS, | |
144 /* 78 */ SDLK_UNKNOWN, | |
145 /* 79 */ SDLK_KP_NUMLOCKCLEAR, | |
146 /* 80 */ SDLK_VOLUMEUP, | |
147 /* 81 */ SDLK_VOLUMEDOWN, | |
148 /* 82 */ SDLK_MUTE, | |
149 /* 83 */ SDLK_KP_DIVIDE, | |
150 /* 84 */ SDLK_KP_ENTER, | |
151 /* 85 */ SDLK_UNKNOWN, | |
152 /* 86 */ SDLK_KP_MINUS, | |
153 /* 87 */ SDLK_UNKNOWN, | |
154 /* 88 */ SDLK_UNKNOWN, | |
155 /* 89 */ SDLK_KP_EQUALS, | |
156 /* 90 */ SDLK_KP_0, | |
157 /* 91 */ SDLK_KP_1, | |
158 /* 92 */ SDLK_KP_2, | |
159 /* 93 */ SDLK_KP_3, | |
160 /* 94 */ SDLK_KP_4, | |
161 /* 95 */ SDLK_KP_5, | |
162 /* 96 */ SDLK_KP_6, | |
163 /* 97 */ SDLK_KP_7, | |
164 /* 98 */ SDLK_UNKNOWN, | |
165 /* 99 */ SDLK_KP_8, | |
166 /* 100 */ SDLK_KP_9, | |
167 /* 101 */ SDLK_INTERNATIONAL3, | |
168 /* 102 */ SDLK_INTERNATIONAL1, | |
169 /* 103 */ SDLK_KP_COMMA, | |
170 /* 104 */ SDLK_F5, | |
171 /* 105 */ SDLK_F6, | |
172 /* 106 */ SDLK_F7, | |
173 /* 107 */ SDLK_F3, | |
174 /* 108 */ SDLK_F8, | |
175 /* 109 */ SDLK_F9, | |
176 /* 110 */ SDLK_LANG2, | |
177 /* 111 */ SDLK_F11, | |
178 /* 112 */ SDLK_LANG1, | |
179 /* 113 */ SDLK_PRINTSCREEN, | |
180 /* 114 */ SDLK_F16, | |
181 /* 115 */ SDLK_SCROLLLOCK, | |
182 /* 116 */ SDLK_UNKNOWN, | |
183 /* 117 */ SDLK_F10, | |
184 /* 118 */ SDLK_APPLICATION, | |
185 /* 119 */ SDLK_F12, | |
186 /* 120 */ SDLK_UNKNOWN, | |
187 /* 121 */ SDLK_PAUSE, | |
188 /* 122 */ SDLK_INSERT, | |
189 /* 123 */ SDLK_HOME, | |
190 /* 124 */ SDLK_PAGEUP, | |
191 /* 125 */ SDLK_DELETE, | |
192 /* 126 */ SDLK_F4, | |
193 /* 127 */ SDLK_END, | |
194 /* 128 */ SDLK_F2, | |
195 /* 129 */ SDLK_PAGEDOWN, | |
196 /* 130 */ SDLK_F1, | |
197 /* 131 */ SDLK_LEFT, | |
198 /* 132 */ SDLK_RIGHT, | |
199 /* 133 */ SDLK_DOWN, | |
200 /* 134 */ SDLK_UP, | |
201 /* 135 */ SDLK_POWER, | |
202 /* 136 */ SDLK_UNKNOWN, /* codes higher than 135 shouldn't occur as Mac virtual keycodes only go to 127 */ | |
203 /* 137 */ SDLK_UNKNOWN, | |
204 /* 138 */ SDLK_UNKNOWN, | |
205 /* 139 */ SDLK_UNKNOWN, | |
206 /* 140 */ SDLK_UNKNOWN, | |
207 /* 141 */ SDLK_UNKNOWN, | |
208 /* 142 */ SDLK_UNKNOWN, | |
209 /* 143 */ SDLK_UNKNOWN, | |
210 /* 144 */ SDLK_UNKNOWN, | |
211 /* 145 */ SDLK_UNKNOWN, | |
212 /* 146 */ SDLK_UNKNOWN, | |
213 /* 147 */ SDLK_UNKNOWN, | |
214 /* 148 */ SDLK_UNKNOWN, | |
215 /* 149 */ SDLK_UNKNOWN, | |
216 /* 150 */ SDLK_UNKNOWN, | |
217 /* 151 */ SDLK_UNKNOWN, | |
218 /* 152 */ SDLK_UNKNOWN, | |
219 /* 153 */ SDLK_UNKNOWN, | |
220 /* 154 */ SDLK_UNKNOWN, | |
221 /* 155 */ SDLK_UNKNOWN, | |
222 /* 156 */ SDLK_UNKNOWN, | |
223 /* 157 */ SDLK_UNKNOWN, | |
224 /* 158 */ SDLK_UNKNOWN, | |
225 /* 159 */ SDLK_UNKNOWN, | |
226 /* 160 */ SDLK_UNKNOWN, | |
227 /* 161 */ SDLK_UNKNOWN, | |
228 /* 162 */ SDLK_UNKNOWN, | |
229 /* 163 */ SDLK_UNKNOWN, | |
230 /* 164 */ SDLK_UNKNOWN, | |
231 /* 165 */ SDLK_UNKNOWN, | |
232 /* 166 */ SDLK_UNKNOWN, | |
233 /* 167 */ SDLK_UNKNOWN, | |
234 /* 168 */ SDLK_UNKNOWN, | |
235 /* 169 */ SDLK_UNKNOWN, | |
236 /* 170 */ SDLK_UNKNOWN, | |
237 /* 171 */ SDLK_UNKNOWN, | |
238 /* 172 */ SDLK_UNKNOWN, | |
239 /* 173 */ SDLK_UNKNOWN, | |
240 /* 174 */ SDLK_UNKNOWN, | |
241 /* 175 */ SDLK_UNKNOWN, | |
242 /* 176 */ SDLK_UNKNOWN, | |
243 /* 177 */ SDLK_UNKNOWN, | |
244 /* 178 */ SDLK_UNKNOWN, | |
245 /* 179 */ SDLK_UNKNOWN, | |
246 /* 180 */ SDLK_UNKNOWN, | |
247 /* 181 */ SDLK_UNKNOWN, | |
248 /* 182 */ SDLK_UNKNOWN, | |
249 /* 183 */ SDLK_UNKNOWN, | |
250 /* 184 */ SDLK_UNKNOWN, | |
251 /* 185 */ SDLK_UNKNOWN, | |
252 /* 186 */ SDLK_UNKNOWN, | |
253 /* 187 */ SDLK_UNKNOWN, | |
254 /* 188 */ SDLK_UNKNOWN, | |
255 /* 189 */ SDLK_UNKNOWN, | |
256 /* 190 */ SDLK_UNKNOWN, | |
257 /* 191 */ SDLK_UNKNOWN, | |
258 /* 192 */ SDLK_UNKNOWN, | |
259 /* 193 */ SDLK_UNKNOWN, | |
260 /* 194 */ SDLK_UNKNOWN, | |
261 /* 195 */ SDLK_UNKNOWN, | |
262 /* 196 */ SDLK_UNKNOWN, | |
263 /* 197 */ SDLK_UNKNOWN, | |
264 /* 198 */ SDLK_UNKNOWN, | |
265 /* 199 */ SDLK_UNKNOWN, | |
266 /* 200 */ SDLK_UNKNOWN, | |
267 /* 201 */ SDLK_UNKNOWN, | |
268 /* 202 */ SDLK_UNKNOWN, | |
269 /* 203 */ SDLK_UNKNOWN, | |
270 /* 204 */ SDLK_UNKNOWN, | |
271 /* 205 */ SDLK_UNKNOWN, | |
272 /* 206 */ SDLK_UNKNOWN, | |
273 /* 207 */ SDLK_UNKNOWN, | |
274 /* 208 */ SDLK_UNKNOWN, | |
275 /* 209 */ SDLK_UNKNOWN, | |
276 /* 210 */ SDLK_UNKNOWN, | |
277 /* 211 */ SDLK_UNKNOWN, | |
278 /* 212 */ SDLK_UNKNOWN, | |
279 /* 213 */ SDLK_UNKNOWN, | |
280 /* 214 */ SDLK_UNKNOWN, | |
281 /* 215 */ SDLK_UNKNOWN, | |
282 /* 216 */ SDLK_UNKNOWN, | |
283 /* 217 */ SDLK_UNKNOWN, | |
284 /* 218 */ SDLK_UNKNOWN, | |
285 /* 219 */ SDLK_UNKNOWN, | |
286 /* 220 */ SDLK_UNKNOWN, | |
287 /* 221 */ SDLK_UNKNOWN, | |
288 /* 222 */ SDLK_UNKNOWN, | |
289 /* 223 */ SDLK_UNKNOWN, | |
290 /* 224 */ SDLK_UNKNOWN, | |
291 /* 225 */ SDLK_UNKNOWN, | |
292 /* 226 */ SDLK_UNKNOWN, | |
293 /* 227 */ SDLK_UNKNOWN, | |
294 /* 228 */ SDLK_UNKNOWN, | |
295 /* 229 */ SDLK_UNKNOWN, | |
296 /* 230 */ SDLK_UNKNOWN, | |
297 /* 231 */ SDLK_UNKNOWN, | |
298 /* 232 */ SDLK_UNKNOWN, | |
299 /* 233 */ SDLK_UNKNOWN, | |
300 /* 234 */ SDLK_UNKNOWN, | |
301 /* 235 */ SDLK_UNKNOWN, | |
302 /* 236 */ SDLK_UNKNOWN, | |
303 /* 237 */ SDLK_UNKNOWN, | |
304 /* 238 */ SDLK_UNKNOWN, | |
305 /* 239 */ SDLK_UNKNOWN, | |
306 /* 240 */ SDLK_UNKNOWN, | |
307 /* 241 */ SDLK_UNKNOWN, | |
308 /* 242 */ SDLK_UNKNOWN, | |
309 /* 243 */ SDLK_UNKNOWN, | |
310 /* 244 */ SDLK_UNKNOWN, | |
311 /* 245 */ SDLK_UNKNOWN, | |
312 /* 246 */ SDLK_UNKNOWN, | |
313 /* 247 */ SDLK_UNKNOWN, | |
314 /* 248 */ SDLK_UNKNOWN, | |
315 /* 249 */ SDLK_UNKNOWN, | |
316 /* 250 */ SDLK_UNKNOWN, | |
317 /* 251 */ SDLK_UNKNOWN, | |
318 /* 252 */ SDLK_UNKNOWN, | |
319 /* 253 */ SDLK_UNKNOWN, | |
320 /* 254 */ SDLK_UNKNOWN, | |
321 /* 255 */ SDLK_UNKNOWN | |
322 }; | |
323 | |
324 /* Found mostly by experimentation with X.org on Linux (Fedora Core 4 and | |
325 Ubuntu Dapper) on PC and PPC Mac hardware, some parts (especially about | |
326 the "multimedia"/"internet" keys) from various sources on the web. | |
327 */ | |
328 static SDLKey xorgLinuxKeyCodeToSDLK[] = { | |
329 /* 0 */ SDLK_UNKNOWN, | |
330 /* 1 */ SDLK_UNKNOWN, | |
331 /* 2 */ SDLK_UNKNOWN, | |
332 /* 3 */ SDLK_UNKNOWN, | |
333 /* 4 */ SDLK_UNKNOWN, | |
334 /* 5 */ SDLK_UNKNOWN, | |
335 /* 6 */ SDLK_UNKNOWN, | |
336 /* 7 */ SDLK_UNKNOWN, | |
337 /* 8 */ SDLK_UNKNOWN, | |
338 /* 9 */ SDLK_ESCAPE, | |
339 /* 10 */ SDLK_1, | |
340 /* 11 */ SDLK_2, | |
341 /* 12 */ SDLK_3, | |
342 /* 13 */ SDLK_4, | |
343 /* 14 */ SDLK_5, | |
344 /* 15 */ SDLK_6, | |
345 /* 16 */ SDLK_7, | |
346 /* 17 */ SDLK_8, | |
347 /* 18 */ SDLK_9, | |
348 /* 19 */ SDLK_0, | |
349 /* 20 */ SDLK_HYPHENMINUS, | |
350 /* 21 */ SDLK_EQUALS, | |
351 /* 22 */ SDLK_BACKSPACE, | |
352 /* 23 */ SDLK_TAB, | |
353 /* 24 */ SDLK_Q, | |
354 /* 25 */ SDLK_W, | |
355 /* 26 */ SDLK_E, | |
356 /* 27 */ SDLK_R, | |
357 /* 28 */ SDLK_T, | |
358 /* 29 */ SDLK_Y, | |
359 /* 30 */ SDLK_U, | |
360 /* 31 */ SDLK_I, | |
361 /* 32 */ SDLK_O, | |
362 /* 33 */ SDLK_P, | |
363 /* 34 */ SDLK_LEFTBRACKET, | |
364 /* 35 */ SDLK_RIGHTBRACKET, | |
365 /* 36 */ SDLK_RETURN, | |
366 /* 37 */ SDLK_LCTRL, | |
367 /* 38 */ SDLK_A, | |
368 /* 39 */ SDLK_S, | |
369 /* 40 */ SDLK_D, | |
370 /* 41 */ SDLK_F, | |
371 /* 42 */ SDLK_G, | |
372 /* 43 */ SDLK_H, | |
373 /* 44 */ SDLK_J, | |
374 /* 45 */ SDLK_K, | |
375 /* 46 */ SDLK_L, | |
376 /* 47 */ SDLK_SEMICOLON, | |
377 /* 48 */ SDLK_APOSTROPHE, | |
378 /* 49 */ SDLK_GRAVE, | |
379 /* 50 */ SDLK_LSHIFT, | |
380 /* 51 */ SDLK_BACKSLASH, | |
381 /* 52 */ SDLK_Z, | |
382 /* 53 */ SDLK_X, | |
383 /* 54 */ SDLK_C, | |
384 /* 55 */ SDLK_V, | |
385 /* 56 */ SDLK_B, | |
386 /* 57 */ SDLK_N, | |
387 /* 58 */ SDLK_M, | |
388 /* 59 */ SDLK_COMMA, | |
389 /* 60 */ SDLK_PERIOD, | |
390 /* 61 */ SDLK_SLASH, | |
391 /* 62 */ SDLK_RSHIFT, | |
392 /* 63 */ SDLK_KP_MULTIPLY, | |
393 /* 64 */ SDLK_LALT, | |
394 /* 65 */ SDLK_SPACE, | |
395 /* 66 */ SDLK_CAPSLOCK, | |
396 /* 67 */ SDLK_F1, | |
397 /* 68 */ SDLK_F2, | |
398 /* 69 */ SDLK_F3, | |
399 /* 70 */ SDLK_F4, | |
400 /* 71 */ SDLK_F5, | |
401 /* 72 */ SDLK_F6, | |
402 /* 73 */ SDLK_F7, | |
403 /* 74 */ SDLK_F8, | |
404 /* 75 */ SDLK_F9, | |
405 /* 76 */ SDLK_F10, | |
406 /* 77 */ SDLK_KP_NUMLOCKCLEAR, | |
407 /* 78 */ SDLK_SCROLLLOCK, | |
408 /* 79 */ SDLK_KP_7, | |
409 /* 80 */ SDLK_KP_8, | |
410 /* 81 */ SDLK_KP_9, | |
411 /* 82 */ SDLK_KP_MINUS, | |
412 /* 83 */ SDLK_KP_4, | |
413 /* 84 */ SDLK_KP_5, | |
414 /* 85 */ SDLK_KP_6, | |
415 /* 86 */ SDLK_KP_PLUS, | |
416 /* 87 */ SDLK_KP_1, | |
417 /* 88 */ SDLK_KP_2, | |
418 /* 89 */ SDLK_KP_3, | |
419 /* 90 */ SDLK_KP_0, | |
420 /* 91 */ SDLK_KP_PERIOD, | |
421 /* 92 */ SDLK_SYSREQ, | |
422 /* 93 */ SDLK_MODE, /* is translated to XK_Mode_switch by my X server, but I have no keyboard that generates this code, so I'm not sure if this is correct */ | |
423 /* 94 */ SDLK_NONUSBACKSLASH, | |
424 /* 95 */ SDLK_F11, | |
425 /* 96 */ SDLK_F12, | |
426 /* 97 */ SDLK_HOME, | |
427 /* 98 */ SDLK_UP, | |
428 /* 99 */ SDLK_PAGEUP, | |
429 /* 100 */ SDLK_LEFT, | |
430 /* 101 */ SDLK_BRIGHTNESSDOWN, /* on PowerBook G4 */ | |
431 /* 102 */ SDLK_RIGHT, | |
432 /* 103 */ SDLK_END, | |
433 /* 104 */ SDLK_DOWN, | |
434 /* 105 */ SDLK_PAGEDOWN, | |
435 /* 106 */ SDLK_INSERT, | |
436 /* 107 */ SDLK_DELETE, | |
437 /* 108 */ SDLK_KP_ENTER, | |
438 /* 109 */ SDLK_RCTRL, | |
439 /* 110 */ SDLK_PAUSE, | |
440 /* 111 */ SDLK_PRINTSCREEN, | |
441 /* 112 */ SDLK_KP_DIVIDE, | |
442 /* 113 */ SDLK_RALT, | |
443 /* 114 */ SDLK_UNKNOWN, | |
444 /* 115 */ SDLK_LMETA, | |
445 /* 116 */ SDLK_RMETA, | |
446 /* 117 */ SDLK_APPLICATION, | |
447 /* 118 */ SDLK_F13, | |
448 /* 119 */ SDLK_F14, | |
449 /* 120 */ SDLK_F15, | |
450 /* 121 */ SDLK_F16, | |
451 /* 122 */ SDLK_F17, | |
452 /* 123 */ SDLK_UNKNOWN, | |
453 /* 124 */ SDLK_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDLK_* for it is */ | |
454 /* 125 */ SDLK_UNKNOWN, | |
455 /* 126 */ SDLK_KP_EQUALS, | |
456 /* 127 */ SDLK_UNKNOWN, | |
457 /* 128 */ SDLK_UNKNOWN, | |
458 /* 129 */ SDLK_UNKNOWN, | |
459 /* 130 */ SDLK_UNKNOWN, | |
460 /* 131 */ SDLK_UNKNOWN, | |
461 /* 132 */ SDLK_UNKNOWN, | |
462 /* 133 */ SDLK_INTERNATIONAL3, /* Yen */ | |
463 /* 134 */ SDLK_UNKNOWN, | |
464 /* 135 */ SDLK_AGAIN, | |
465 /* 136 */ SDLK_UNDO, | |
466 /* 137 */ SDLK_UNKNOWN, | |
467 /* 138 */ SDLK_UNKNOWN, | |
468 /* 139 */ SDLK_UNKNOWN, | |
469 /* 140 */ SDLK_UNKNOWN, | |
470 /* 141 */ SDLK_UNKNOWN, | |
471 /* 142 */ SDLK_UNKNOWN, | |
472 /* 143 */ SDLK_UNKNOWN, | |
473 /* 144 */ SDLK_AUDIOPREV, | |
474 /* 145 */ SDLK_UNKNOWN, | |
475 /* 146 */ SDLK_UNKNOWN, | |
476 /* 147 */ SDLK_UNKNOWN, | |
477 /* 148 */ SDLK_UNKNOWN, | |
478 /* 149 */ SDLK_UNKNOWN, | |
479 /* 150 */ SDLK_UNKNOWN, | |
480 /* 151 */ SDLK_UNKNOWN, | |
481 /* 152 */ SDLK_UNKNOWN, | |
482 /* 153 */ SDLK_AUDIONEXT, | |
483 /* 154 */ SDLK_UNKNOWN, | |
484 /* 155 */ SDLK_UNKNOWN, | |
485 /* 156 */ SDLK_UNKNOWN, | |
486 /* 157 */ SDLK_KP_EQUALS, /* on PowerBook G4 */ | |
487 /* 158 */ SDLK_UNKNOWN, | |
488 /* 159 */ SDLK_UNKNOWN, | |
489 /* 160 */ SDLK_MUTE, | |
490 /* 161 */ SDLK_CALC, | |
491 /* 162 */ SDLK_AUDIOPLAY, | |
492 /* 163 */ SDLK_UNKNOWN, | |
493 /* 164 */ SDLK_AUDIOSTOP, | |
494 /* 165 */ SDLK_UNKNOWN, | |
495 /* 166 */ SDLK_UNKNOWN, | |
496 /* 167 */ SDLK_UNKNOWN, | |
497 /* 168 */ SDLK_UNKNOWN, | |
498 /* 169 */ SDLK_UNKNOWN, | |
499 /* 170 */ SDLK_UNKNOWN, | |
500 /* 171 */ SDLK_UNKNOWN, | |
501 /* 172 */ SDLK_UNKNOWN, | |
502 /* 173 */ SDLK_UNKNOWN, | |
503 /* 174 */ SDLK_VOLUMEDOWN, | |
504 /* 175 */ SDLK_UNKNOWN, | |
505 /* 176 */ SDLK_VOLUMEUP, | |
506 /* 177 */ SDLK_UNKNOWN, | |
507 /* 178 */ SDLK_WWW, | |
508 /* 179 */ SDLK_UNKNOWN, | |
509 /* 180 */ SDLK_UNKNOWN, | |
510 /* 181 */ SDLK_UNKNOWN, | |
511 /* 182 */ SDLK_UNKNOWN, | |
512 /* 183 */ SDLK_UNKNOWN, | |
513 /* 184 */ SDLK_UNKNOWN, | |
514 /* 185 */ SDLK_UNKNOWN, | |
515 /* 186 */ SDLK_UNKNOWN, | |
516 /* 187 */ SDLK_HELP, | |
517 /* 188 */ SDLK_UNKNOWN, | |
518 /* 189 */ SDLK_UNKNOWN, | |
519 /* 190 */ SDLK_UNKNOWN, | |
520 /* 191 */ SDLK_UNKNOWN, | |
521 /* 192 */ SDLK_UNKNOWN, | |
522 /* 193 */ SDLK_UNKNOWN, | |
523 /* 194 */ SDLK_UNKNOWN, | |
524 /* 195 */ SDLK_UNKNOWN, | |
525 /* 196 */ SDLK_UNKNOWN, | |
526 /* 197 */ SDLK_UNKNOWN, | |
527 /* 198 */ SDLK_UNKNOWN, | |
528 /* 199 */ SDLK_UNKNOWN, | |
529 /* 200 */ SDLK_UNKNOWN, | |
530 /* 201 */ SDLK_UNKNOWN, | |
531 /* 202 */ SDLK_UNKNOWN, | |
532 /* 203 */ SDLK_UNKNOWN, | |
533 /* 204 */ SDLK_EJECT, /* on PowerBook G4 */ | |
534 /* 205 */ SDLK_UNKNOWN, | |
535 /* 206 */ SDLK_UNKNOWN, | |
536 /* 207 */ SDLK_UNKNOWN, | |
537 /* 208 */ SDLK_UNKNOWN, | |
538 /* 209 */ SDLK_UNKNOWN, | |
539 /* 210 */ SDLK_UNKNOWN, | |
540 /* 211 */ SDLK_UNKNOWN, | |
541 /* 212 */ SDLK_BRIGHTNESSUP, /* on PowerBook G4 */ | |
542 /* 213 */ SDLK_UNKNOWN, | |
543 /* 214 */ SDLK_DISPLAYSWITCH, /* on PowerBook G4 */ | |
544 /* 215 */ SDLK_KBDILLUMTOGGLE, | |
545 /* 216 */ SDLK_KBDILLUMDOWN, | |
546 /* 217 */ SDLK_KBDILLUMUP, | |
547 /* 218 */ SDLK_UNKNOWN, | |
548 /* 219 */ SDLK_UNKNOWN, | |
549 /* 220 */ SDLK_UNKNOWN, | |
550 /* 221 */ SDLK_UNKNOWN, | |
551 /* 222 */ SDLK_POWER, | |
552 /* 223 */ SDLK_SLEEP, | |
553 /* 224 */ SDLK_UNKNOWN, | |
554 /* 225 */ SDLK_UNKNOWN, | |
555 /* 226 */ SDLK_UNKNOWN, | |
556 /* 227 */ SDLK_UNKNOWN, | |
557 /* 228 */ SDLK_UNKNOWN, | |
558 /* 229 */ SDLK_SEARCH, | |
559 /* 230 */ SDLK_BOOKMARKS, | |
560 /* 231 */ SDLK_BROWSERRELOAD, | |
561 /* 232 */ SDLK_BROWSERSTOP, | |
562 /* 233 */ SDLK_BROWSERFORWARD, | |
563 /* 234 */ SDLK_BROWSERBACK, | |
564 /* 235 */ SDLK_COMPUTER, | |
565 /* 236 */ SDLK_EMAIL, | |
566 /* 237 */ SDLK_MEDIA, | |
567 /* 238 */ SDLK_UNKNOWN, | |
568 /* 239 */ SDLK_UNKNOWN, | |
569 /* 240 */ SDLK_UNKNOWN, | |
570 /* 241 */ SDLK_UNKNOWN, | |
571 /* 242 */ SDLK_UNKNOWN, | |
572 /* 243 */ SDLK_UNKNOWN, | |
573 /* 244 */ SDLK_UNKNOWN, | |
574 /* 245 */ SDLK_UNKNOWN, | |
575 /* 246 */ SDLK_UNKNOWN, | |
576 /* 247 */ SDLK_UNKNOWN, | |
577 /* 248 */ SDLK_UNKNOWN, | |
578 /* 249 */ SDLK_UNKNOWN, | |
579 /* 250 */ SDLK_UNKNOWN, | |
580 /* 251 */ SDLK_UNKNOWN, | |
581 /* 252 */ SDLK_UNKNOWN, | |
582 /* 253 */ SDLK_UNKNOWN, | |
583 /* 254 */ SDLK_UNKNOWN, | |
584 /* 255 */ SDLK_UNKNOWN | |
585 }; | |
586 | |
587 /* *INDENT-ON* */ | |
588 | |
589 /*---------------------------------------------------------------------------*/ | |
590 | |
591 /* Used by X11_KeySymToSDLKey(). This is a hybrid of a KeySym-to-layout-key | |
592 mapping (needed in X11_GetLayoutKey()) and a fallback KeySym-to-physical-key | |
593 mapping under the assumption of a US keyboard layout (needed in | |
594 X11_InitKeyboard()). If for a given KeySym... | |
595 - the layout and physical codes are the same (must be an SDLK_ constant): | |
596 there is one entry, | |
597 - the layout and physical codes differ: there are two entries, with the | |
598 layout one first, | |
599 - there is only a physical code in the table (must be an SDLK_ constant): | |
600 it's marked by X11_KEY_PHYSICAL_ONLY_BIT (this is the case when the layout | |
601 key code is handled by KeySymToUcs4()), | |
602 - there is only a layout code in the table (can't be an SDLK_ constant): | |
603 recognizable by the absence of SDL_KEY_CAN_BE_PHYSICAL_BIT. | |
604 This list is sorted by KeySym to allow a binary search. | |
605 */ | |
606 #define X11_KEY_PHYSICAL_ONLY_BIT SDL_KEY_LAYOUT_SPECIAL_BIT | |
607 /* SDL_KEY_LAYOUT_SPECIAL_BIT cannot possibly occur in an SDLK_ constant, so we may repurpose that bit for our own use. */ | |
608 static struct | |
609 { | |
610 KeySym sym; | |
611 SDLKey key; | |
612 } keySymToSDLKey[] = { | |
613 /* 0x00xx */ | |
614 { | |
615 XK_space, SDLK_SPACE}, { | |
616 XK_apostrophe, SDLK_APOSTROPHE | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
617 XK_comma, SDLK_COMMA | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
618 XK_minus, SDLK_HYPHENMINUS | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
619 XK_period, SDLK_PERIOD | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
620 XK_slash, SDLK_SLASH | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
621 XK_0, SDLK_0 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
622 XK_1, SDLK_1 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
623 XK_2, SDLK_2 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
624 XK_3, SDLK_3 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
625 XK_4, SDLK_4 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
626 XK_5, SDLK_5 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
627 XK_6, SDLK_6 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
628 XK_7, SDLK_7 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
629 XK_8, SDLK_8 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
630 XK_9, SDLK_9 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
631 XK_semicolon, SDLK_SEMICOLON | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
632 XK_less, SDLK_NONUSBACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
633 XK_equal, SDLK_EQUALS | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
634 XK_bracketleft, SDLK_LEFTBRACKET | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
635 XK_backslash, SDLK_BACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
636 XK_bracketright, SDLK_RIGHTBRACKET | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
637 XK_grave, SDLK_GRAVE | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
638 XK_a, SDLK_A | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
639 XK_b, SDLK_B | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
640 XK_c, SDLK_C | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
641 XK_d, SDLK_D | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
642 XK_e, SDLK_E | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
643 XK_f, SDLK_F | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
644 XK_g, SDLK_G | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
645 XK_h, SDLK_H | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
646 XK_i, SDLK_I | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
647 XK_j, SDLK_J | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
648 XK_k, SDLK_K | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
649 XK_l, SDLK_L | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
650 XK_m, SDLK_M | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
651 XK_n, SDLK_N | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
652 XK_o, SDLK_O | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
653 XK_p, SDLK_P | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
654 XK_q, SDLK_Q | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
655 XK_r, SDLK_R | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
656 XK_s, SDLK_S | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
657 XK_t, SDLK_T | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
658 XK_u, SDLK_U | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
659 XK_v, SDLK_V | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
660 XK_w, SDLK_W | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
661 XK_x, SDLK_X | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
662 XK_y, SDLK_Y | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
663 XK_z, SDLK_Z | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
664 XK_section, SDLK_NONUSBACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT}, | |
665 /* 0xFExx */ | |
666 { | |
667 XK_ISO_Level3_Shift, SDLK_RALT}, { | |
668 XK_dead_grave, '`'}, { | |
669 XK_dead_acute, 0xB4}, { | |
670 XK_dead_circumflex, '^'}, { | |
671 XK_dead_tilde, '~'}, { | |
672 XK_dead_macron, 0xAF}, { | |
673 XK_dead_breve, 0x2D8}, { | |
674 XK_dead_abovedot, 0x2D9}, { | |
675 XK_dead_diaeresis, 0xA8}, { | |
676 XK_dead_abovering, 0x2DA}, { | |
677 XK_dead_doubleacute, 0x2DD}, { | |
678 XK_dead_caron, 0x2C7}, { | |
679 XK_dead_cedilla, 0xB8}, { | |
680 XK_dead_ogonek, 0x2DB}, { | |
681 XK_dead_iota, 0x3B9}, { | |
682 XK_dead_voiced_sound, 0x309B}, { | |
683 XK_dead_semivoiced_sound, 0x309C}, { | |
684 XK_dead_belowdot, 0xB7}, /* that's actually MIDDLE DOT, but I haven't found a non-combining DOT BELOW */ | |
685 /* XK_dead_hook, XK_dead_horn: I haven't found non-combining HOOK and HORN characters */ | |
686 /* 0xFFxx */ | |
687 { | |
688 XK_BackSpace, SDLK_BACKSPACE}, { | |
689 XK_Tab, SDLK_TAB}, { | |
690 XK_Return, SDLK_RETURN}, { | |
691 XK_Pause, SDLK_PAUSE}, { | |
692 XK_Scroll_Lock, SDLK_SCROLLLOCK}, { | |
693 XK_Escape, SDLK_ESCAPE}, { | |
694 XK_Home, SDLK_HOME}, { | |
695 XK_Left, SDLK_LEFT}, { | |
696 XK_Up, SDLK_UP}, { | |
697 XK_Right, SDLK_RIGHT}, { | |
698 XK_Down, SDLK_DOWN}, { | |
699 XK_Page_Up, SDLK_PAGEUP}, { | |
700 XK_Page_Down, SDLK_PAGEDOWN}, { | |
701 XK_End, SDLK_END}, { | |
702 XK_Print, SDLK_PRINTSCREEN}, { | |
703 XK_Insert, SDLK_INSERT}, { | |
704 XK_Menu, SDLK_APPLICATION}, { | |
705 XK_Break, SDLK_PAUSE}, { | |
706 XK_Mode_switch, SDLK_MODE}, { | |
707 XK_Num_Lock, SDLK_KP_NUMLOCKCLEAR}, { | |
708 XK_KP_Enter, SDLK_KP_ENTER}, { | |
709 XK_KP_Home, SDLK_KP_7 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
710 XK_KP_Left, SDLK_KP_4 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
711 XK_KP_Up, SDLK_KP_8 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
712 XK_KP_Right, SDLK_KP_6 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
713 XK_KP_Down, SDLK_KP_2 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
714 XK_KP_Page_Up, SDLK_KP_9 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
715 XK_KP_Page_Down, SDLK_KP_3 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
716 XK_KP_End, SDLK_KP_1 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
717 XK_KP_Begin, SDLK_KP_5 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
718 XK_KP_Insert, SDLK_KP_0 | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
719 XK_KP_Delete, SDLK_KP_PERIOD | X11_KEY_PHYSICAL_ONLY_BIT}, { | |
720 XK_KP_Multiply, '*'}, { | |
721 XK_KP_Multiply, SDLK_KP_MULTIPLY}, { | |
722 XK_KP_Add, '+'}, { | |
723 XK_KP_Add, SDLK_KP_PLUS}, { | |
724 XK_KP_Separator, '.'}, { | |
725 XK_KP_Separator, SDLK_KP_PERIOD}, { | |
726 XK_KP_Subtract, '-'}, { | |
727 XK_KP_Subtract, SDLK_KP_MINUS}, { | |
728 XK_KP_Decimal, '.'}, { | |
729 XK_KP_Decimal, SDLK_KP_PERIOD}, { | |
730 XK_KP_Divide, '/'}, { | |
731 XK_KP_Divide, SDLK_KP_DIVIDE}, { | |
732 XK_KP_0, '0'}, { | |
733 XK_KP_0, SDLK_KP_0}, { | |
734 XK_KP_1, '1'}, { | |
735 XK_KP_1, SDLK_KP_1}, { | |
736 XK_KP_2, '2'}, { | |
737 XK_KP_2, SDLK_KP_2}, { | |
738 XK_KP_3, '3'}, { | |
739 XK_KP_3, SDLK_KP_3}, { | |
740 XK_KP_4, '4'}, { | |
741 XK_KP_4, SDLK_KP_4}, { | |
742 XK_KP_5, '5'}, { | |
743 XK_KP_5, SDLK_KP_5}, { | |
744 XK_KP_6, '6'}, { | |
745 XK_KP_6, SDLK_KP_6}, { | |
746 XK_KP_7, '7'}, { | |
747 XK_KP_7, SDLK_KP_7}, { | |
748 XK_KP_8, '8'}, { | |
749 XK_KP_8, SDLK_KP_8}, { | |
750 XK_KP_9, '9'}, { | |
751 XK_KP_9, SDLK_KP_9}, { | |
752 XK_KP_Equal, '='}, { | |
753 XK_KP_Equal, SDLK_KP_EQUALS}, { | |
754 XK_F1, SDLK_F1}, { | |
755 XK_F2, SDLK_F2}, { | |
756 XK_F3, SDLK_F3}, { | |
757 XK_F4, SDLK_F4}, { | |
758 XK_F5, SDLK_F5}, { | |
759 XK_F6, SDLK_F6}, { | |
760 XK_F7, SDLK_F7}, { | |
761 XK_F8, SDLK_F8}, { | |
762 XK_F9, SDLK_F9}, { | |
763 XK_F10, SDLK_F10}, { | |
764 XK_F11, SDLK_F11}, { | |
765 XK_F12, SDLK_F12}, { | |
766 XK_F13, SDLK_F13}, { | |
767 XK_F14, SDLK_F14}, { | |
768 XK_F15, SDLK_F15}, { | |
769 XK_F16, SDLK_F16}, { | |
770 XK_F17, SDLK_F17}, { | |
771 XK_F18, SDLK_F18}, { | |
772 XK_F19, SDLK_F19}, { | |
773 XK_F20, SDLK_F20}, { | |
774 XK_F21, SDLK_F21}, { | |
775 XK_F22, SDLK_F22}, { | |
776 XK_F23, SDLK_F23}, { | |
777 XK_F24, SDLK_F24}, { | |
778 XK_Shift_L, SDLK_LSHIFT}, { | |
779 XK_Shift_R, SDLK_RSHIFT}, { | |
780 XK_Control_L, SDLK_LCTRL}, { | |
781 XK_Control_R, SDLK_RCTRL}, { | |
782 XK_Caps_Lock, SDLK_CAPSLOCK}, { | |
783 XK_Shift_Lock, SDLK_CAPSLOCK}, { | |
784 XK_Meta_L, SDLK_LMETA}, { | |
785 XK_Meta_R, SDLK_RMETA}, { | |
786 XK_Alt_L, SDLK_LALT}, { | |
787 XK_Alt_R, SDLK_RALT}, { | |
788 XK_Super_L, SDLK_LMETA}, { | |
789 XK_Super_R, SDLK_RMETA}, { | |
790 XK_Hyper_L, SDLK_LMETA}, { | |
791 XK_Hyper_R, SDLK_RMETA}, { | |
792 XK_Delete, SDLK_DELETE}, { | |
793 0x1000003, SDLK_KP_ENTER} /* keyboard enter on Mac OS X */ | |
794 }; | |
795 | |
796 static SDLKey | |
797 X11_KeySymToSDLKey(KeySym sym, SDL_bool physical) | |
798 { | |
799 /* Do a binary search for sym in the keySymToSDLKey table */ | |
800 SDLKey key = SDLK_UNKNOWN; | |
801 int start = -1; | |
802 int end = SDL_arraysize(keySymToSDLKey); | |
803 int i; | |
804 /* Invariant: keySymToSDLKey[start].sym < sym < | |
805 keySymToSDLKey[end].sym (imagine ...[-1] = -inf and | |
806 ...[arraysize] = inf, these entries needn't be there in reality | |
807 because they're never accessed) */ | |
808 while (end > start + 1) { | |
809 i = (start + end) / 2; | |
810 if (keySymToSDLKey[i].sym == sym) { | |
811 /* found an entry, if it's the second of two back up to the first */ | |
812 if (keySymToSDLKey[i - 1].sym == sym) | |
813 i--; | |
814 /* if there are two, the physical one is the second */ | |
815 if (physical && keySymToSDLKey[i + 1].sym == sym) | |
816 i++; | |
817 key = keySymToSDLKey[i].key; | |
818 break; | |
819 } else if (keySymToSDLKey[i].sym < sym) | |
820 start = i; | |
821 else | |
822 end = i; | |
823 } | |
824 | |
825 /* if we're being asked for a layout key code, but the table only | |
826 has a physical one, or vice versa, return SDLK_UNKNOWN) */ | |
827 | |
828 if (!physical && ((key & X11_KEY_PHYSICAL_ONLY_BIT) != 0) | |
829 || physical && ((key & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0)) | |
830 key = SDLK_UNKNOWN; | |
831 key &= ~X11_KEY_PHYSICAL_ONLY_BIT; | |
832 return key; | |
833 } | |
834 | |
835 int | |
29 X11_InitKeyboard(_THIS) | 836 X11_InitKeyboard(_THIS) |
30 { | 837 { |
31 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 838 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
32 SDL_Keyboard keyboard; | 839 SDL_Keyboard keyboard; |
840 SDLKey **table; | |
841 SDLKey *foundTable; | |
842 int i; | |
843 int code; | |
844 SDLKey sdlkey; | |
845 | |
846 /* A random collection of KeySym/SDLKey pairs that should be valid | |
847 in any keyboard layout (if this isn't the case on yours, | |
848 please adjust). Using XKeysymToKeycode on these KeySyms | |
849 creates a "fingerprint" of the X server's key-to-KeyCode | |
850 mapping which is then matched against all our predefined | |
851 KeyCodeToSDLK tables to find the right one (if any). | |
852 */ | |
853 struct | |
854 { | |
855 KeySym sym; | |
856 SDLKey key; | |
857 } fingerprint[] = { | |
858 { | |
859 XK_Tab, SDLK_TAB}, { | |
860 XK_Return, SDLK_RETURN}, { | |
861 XK_Escape, SDLK_ESCAPE}, { | |
862 XK_space, SDLK_SPACE} | |
863 }; | |
33 | 864 |
34 SDL_zero(keyboard); | 865 SDL_zero(keyboard); |
35 data->keyboard = SDL_AddKeyboard(&keyboard, -1); | 866 data->keyboard = SDL_AddKeyboard(&keyboard, -1); |
867 | |
868 /* Determine which X11 KeyCode to SDL physical key code table to use */ | |
869 | |
870 foundTable = NULL; | |
871 table = keyCodeToSDLKeyTables; | |
872 while ((NULL == foundTable) && (NULL != (*table))) { | |
873 foundTable = *table; | |
874 for (i = 0; i < SDL_arraysize(fingerprint); i++) { | |
875 code = XKeysymToKeycode(data->display, fingerprint[i].sym); | |
876 if ((code != 0) && ((*table)[code] != fingerprint[i].key)) { | |
877 foundTable = NULL; | |
878 break; | |
879 } | |
880 } | |
881 table++; | |
882 } | |
883 | |
884 if (NULL != foundTable) { | |
885 /* Found a suitable one among the predefined tables */ | |
886 data->keyCodeToSDLKTable = foundTable; | |
887 } else { | |
888 /* No suitable table found - build a makeshift table based on | |
889 the KeySyms, assuming a US keyboard layout */ | |
890 | |
891 #if 1 | |
892 fprintf(stderr, | |
893 "The key codes of your X server are unknown to SDL. Keys may not be recognized properly. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>.\n"); | |
894 #endif | |
895 data->keyCodeToSDLKTable = | |
896 SDL_malloc(SDL_arraysize(xorgLinuxKeyCodeToSDLK)); | |
897 if (data->keyCodeToSDLKTable == NULL) { | |
898 SDL_OutOfMemory(); | |
899 return -1; | |
900 } | |
901 for (code = SDL_arraysize(xorgLinuxKeyCodeToSDLK); code >= 0; code--) { | |
902 data->keyCodeToSDLKTable[code] = | |
903 X11_KeySymToSDLKey(XKeycodeToKeysym(data->display, code, 0), | |
904 SDL_TRUE); | |
905 } | |
906 } | |
907 | |
908 /* Set some non-default key names */ | |
909 | |
910 for (code = 0; code < SDL_arraysize(xorgLinuxKeyCodeToSDLK); code++) { | |
911 sdlkey = data->keyCodeToSDLKTable[code]; | |
912 switch (sdlkey) { | |
913 /* The SDLK_*META keys are used as XK_Meta_* by some X | |
914 servers, as XK_Super_* by others */ | |
915 case SDLK_LMETA: | |
916 case SDLK_RMETA: | |
917 switch (XKeycodeToKeysym(data->display, code, 0)) { | |
918 /* nothing to do for XK_Meta_* because that's already the default name */ | |
919 case XK_Super_L: | |
920 SDL_SetKeyName(sdlkey, "left super"); | |
921 break; | |
922 case XK_Super_R: | |
923 SDL_SetKeyName(sdlkey, "right super"); | |
924 break; | |
925 } | |
926 break; | |
927 } | |
928 } | |
929 SDL_SetKeyName(SDLK_APPLICATION, "menu"); | |
930 | |
931 return 0; | |
932 } | |
933 | |
934 SDLKey | |
935 X11_GetLayoutKey(_THIS, SDLKey physicalKey) | |
936 { | |
937 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
938 int code = 0; | |
939 KeySym sym; | |
940 SDLKey layoutKey; | |
941 | |
942 switch (physicalKey) { | |
943 case SDLK_UNKNOWN: | |
944 return physicalKey; | |
945 | |
946 /* Shortcut handling of keypad numbers because on my PC their | |
947 primary KeySyms are not the numbers that I want but | |
948 XK_KP_Home, XK_KP_Up etc. The downside is that this gets us | |
949 latin numerals even on e.g. an Arabic layout. */ | |
950 case SDLK_KP_1: | |
951 return '1'; | |
952 case SDLK_KP_2: | |
953 return '2'; | |
954 case SDLK_KP_3: | |
955 return '3'; | |
956 case SDLK_KP_4: | |
957 return '4'; | |
958 case SDLK_KP_5: | |
959 return '5'; | |
960 case SDLK_KP_6: | |
961 return '6'; | |
962 case SDLK_KP_7: | |
963 return '7'; | |
964 case SDLK_KP_8: | |
965 return '8'; | |
966 case SDLK_KP_9: | |
967 return '9'; | |
968 case SDLK_KP_0: | |
969 return '0'; | |
970 case SDLK_KP_PERIOD: | |
971 return '.'; | |
972 default: | |
973 break; /* just to avoid a compiler warning */ | |
974 } | |
975 | |
976 /* Look up physicalKey to get an X11 KeyCode - linear search isn't | |
977 terribly efficient, this might have to be optimized. */ | |
978 while ((code < SDL_arraysize(xorgLinuxKeyCodeToSDLK) && physicalKey) | |
979 != data->keyCodeToSDLKTable[code]) { | |
980 code++; | |
981 } | |
982 | |
983 if (code == SDL_arraysize(xorgLinuxKeyCodeToSDLK)) { | |
984 return physicalKey; | |
985 } | |
986 /* Get the corresponding KeySym - this is where the keyboard | |
987 layout comes into play */ | |
988 sym = XKeycodeToKeysym(data->display, code, 0); | |
989 | |
990 /* Try our own KeySym-to-layout-key-code table: it handles all | |
991 keys whose layout code is an SDLK_ one, including a few where | |
992 X11_KeySymToUcs4() would yield a character, but not a suitable | |
993 one as a key name (e.g. space), and some that are character | |
994 keys for our purposes, but aren't handled by X11_KeySymToUcs4() | |
995 (dead keys, keypad operations). */ | |
996 | |
997 layoutKey = X11_KeySymToSDLKey(sym, SDL_FALSE); | |
998 | |
999 /* If it wasn't handled by X11_KeySymToSDLKey(), it's most | |
1000 probably a plain character KeySym that X11_KeySymToUcs4() | |
1001 (ripped from X.org) knows. */ | |
1002 | |
1003 if (layoutKey == SDLK_UNKNOWN) { | |
1004 unsigned int ucs = X11_KeySymToUcs4(sym); | |
1005 if (ucs != 0) | |
1006 layoutKey = (SDLKey) ucs; | |
1007 } | |
1008 | |
1009 /* Still no success? Give up. */ | |
1010 if (layoutKey == SDLK_UNKNOWN) { | |
1011 return physicalKey; | |
1012 } | |
1013 | |
1014 return layoutKey; | |
36 } | 1015 } |
37 | 1016 |
38 void | 1017 void |
39 X11_QuitKeyboard(_THIS) | 1018 X11_QuitKeyboard(_THIS) |
40 { | 1019 { |
41 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 1020 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
42 | 1021 |
1022 if (data->keyCodeToSDLKTable != NULL) { | |
1023 /* If it's not one of the predefined tables, it was malloced | |
1024 and must be freed */ | |
1025 SDLKey **table = keyCodeToSDLKeyTables; | |
1026 while (*table != NULL && *table != data->keyCodeToSDLKTable) { | |
1027 table++; | |
1028 } | |
1029 if (*table == NULL) | |
1030 SDL_free(data->keyCodeToSDLKTable); | |
1031 data->keyCodeToSDLKTable = NULL; | |
1032 } | |
1033 | |
43 SDL_DelKeyboard(data->keyboard); | 1034 SDL_DelKeyboard(data->keyboard); |
44 } | 1035 } |
45 | 1036 |
46 /* vi: set ts=4 sw=4 expandtab: */ | 1037 /* vi: set ts=4 sw=4 expandtab: */ |