Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11keyboard.c @ 3001:7b031c55aebc
Fixed bug #669
Generate a full set of SDLKey mappings when setting up the keyboard layout
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 05 Jan 2009 06:28:50 +0000 |
parents | 99210400e8b9 |
children | dc1eb82ffdaa |
comparison
equal
deleted
inserted
replaced
3000:61081db2385a | 3001:7b031c55aebc |
---|---|
29 | 29 |
30 #include <X11/keysym.h> | 30 #include <X11/keysym.h> |
31 | 31 |
32 #include "imKStoUCS.h" | 32 #include "imKStoUCS.h" |
33 | 33 |
34 static KeySym XKeySymTable[SDL_NUM_SCANCODES] = { | 34 /* *INDENT-OFF* */ |
35 0, 0, 0, 0, | 35 static struct { |
36 XK_a, | 36 KeySym keysym; |
37 XK_b, | 37 SDLKey sdlkey; |
38 XK_c, | 38 } KeySymToSDLKey[] = { |
39 XK_d, | 39 { XK_Return, SDLK_RETURN }, |
40 XK_e, | 40 { XK_Escape, SDLK_ESCAPE }, |
41 XK_f, | 41 { XK_BackSpace, SDLK_BACKSPACE }, |
42 XK_g, | 42 { XK_Tab, SDLK_TAB }, |
43 XK_h, | 43 { XK_Caps_Lock, SDLK_CAPSLOCK }, |
44 XK_i, | 44 { XK_F1, SDLK_F1 }, |
45 XK_j, | 45 { XK_F2, SDLK_F2 }, |
46 XK_k, | 46 { XK_F3, SDLK_F3 }, |
47 XK_l, | 47 { XK_F4, SDLK_F4 }, |
48 XK_m, | 48 { XK_F5, SDLK_F5 }, |
49 XK_n, | 49 { XK_F6, SDLK_F6 }, |
50 XK_o, | 50 { XK_F7, SDLK_F7 }, |
51 XK_p, | 51 { XK_F8, SDLK_F8 }, |
52 XK_q, | 52 { XK_F9, SDLK_F9 }, |
53 XK_r, | 53 { XK_F10, SDLK_F10 }, |
54 XK_s, | 54 { XK_F11, SDLK_F11 }, |
55 XK_t, | 55 { XK_F12, SDLK_F12 }, |
56 XK_u, | 56 { XK_Print, SDLK_PRINTSCREEN }, |
57 XK_v, | 57 { XK_Scroll_Lock, SDLK_SCROLLLOCK }, |
58 XK_w, | 58 { XK_Pause, SDLK_PAUSE }, |
59 XK_x, | 59 { XK_Insert, SDLK_INSERT }, |
60 XK_y, | 60 { XK_Home, SDLK_HOME }, |
61 XK_z, | 61 { XK_Prior, SDLK_PAGEUP }, |
62 XK_1, | 62 { XK_Delete, SDLK_DELETE }, |
63 XK_2, | 63 { XK_End, SDLK_END }, |
64 XK_3, | 64 { XK_Next, SDLK_PAGEDOWN }, |
65 XK_4, | 65 { XK_Right, SDLK_RIGHT }, |
66 XK_5, | 66 { XK_Left, SDLK_LEFT }, |
67 XK_6, | 67 { XK_Down, SDLK_DOWN }, |
68 XK_7, | 68 { XK_Up, SDLK_UP }, |
69 XK_8, | 69 { XK_Num_Lock, SDLK_NUMLOCKCLEAR }, |
70 XK_9, | 70 { XK_KP_Divide, SDLK_KP_DIVIDE }, |
71 XK_0, | 71 { XK_KP_Multiply, SDLK_KP_MULTIPLY }, |
72 XK_Return, | 72 { XK_KP_Subtract, SDLK_KP_MINUS }, |
73 XK_Escape, | 73 { XK_KP_Add, SDLK_KP_PLUS }, |
74 XK_BackSpace, | 74 { XK_KP_Enter, SDLK_KP_ENTER }, |
75 XK_Tab, | 75 { XK_KP_Delete, SDLK_KP_PERIOD }, |
76 XK_space, | 76 { XK_KP_End, SDLK_KP_1 }, |
77 XK_minus, | 77 { XK_KP_Down, SDLK_KP_2 }, |
78 XK_equal, | 78 { XK_KP_Next, SDLK_KP_3 }, |
79 XK_bracketleft, | 79 { XK_KP_Left, SDLK_KP_4 }, |
80 XK_bracketright, | 80 { XK_KP_Begin, SDLK_KP_5 }, |
81 XK_backslash, | 81 { XK_KP_Right, SDLK_KP_6 }, |
82 0, /* SDL_SCANCODE_NONUSHASH ? */ | 82 { XK_KP_Home, SDLK_KP_7 }, |
83 XK_semicolon, | 83 { XK_KP_Up, SDLK_KP_8 }, |
84 XK_apostrophe, | 84 { XK_KP_Prior, SDLK_KP_9 }, |
85 XK_grave, | 85 { XK_KP_Insert, SDLK_KP_0 }, |
86 XK_comma, | 86 { XK_KP_Decimal, SDLK_KP_PERIOD }, |
87 XK_period, | 87 { XK_KP_1, SDLK_KP_1 }, |
88 XK_slash, | 88 { XK_KP_2, SDLK_KP_2 }, |
89 XK_Caps_Lock, | 89 { XK_KP_3, SDLK_KP_3 }, |
90 XK_F1, | 90 { XK_KP_4, SDLK_KP_4 }, |
91 XK_F2, | 91 { XK_KP_5, SDLK_KP_5 }, |
92 XK_F3, | 92 { XK_KP_6, SDLK_KP_6 }, |
93 XK_F4, | 93 { XK_KP_7, SDLK_KP_7 }, |
94 XK_F5, | 94 { XK_KP_8, SDLK_KP_8 }, |
95 XK_F6, | 95 { XK_KP_9, SDLK_KP_9 }, |
96 XK_F7, | 96 { XK_KP_0, SDLK_KP_0 }, |
97 XK_F8, | 97 { XK_KP_Decimal, SDLK_KP_PERIOD }, |
98 XK_F9, | 98 { XK_Hyper_R, SDLK_APPLICATION }, |
99 XK_F10, | 99 { XK_KP_Equal, SDLK_KP_EQUALS }, |
100 XK_F11, | 100 { XK_F13, SDLK_F13 }, |
101 XK_F12, | 101 { XK_F14, SDLK_F14 }, |
102 XK_Print, | 102 { XK_F15, SDLK_F15 }, |
103 XK_Scroll_Lock, | 103 { XK_F16, SDLK_F16 }, |
104 XK_Pause, | 104 { XK_F17, SDLK_F17 }, |
105 XK_Insert, | 105 { XK_F18, SDLK_F18 }, |
106 XK_Home, | 106 { XK_F19, SDLK_F19 }, |
107 XK_Prior, | 107 { XK_F20, SDLK_F20 }, |
108 XK_Delete, | 108 { XK_F21, SDLK_F21 }, |
109 XK_End, | 109 { XK_F22, SDLK_F22 }, |
110 XK_Next, | 110 { XK_F23, SDLK_F23 }, |
111 XK_Right, | 111 { XK_F24, SDLK_F24 }, |
112 XK_Left, | 112 { XK_Execute, SDLK_EXECUTE }, |
113 XK_Down, | 113 { XK_Help, SDLK_HELP }, |
114 XK_Up, | 114 { XK_Menu, SDLK_MENU }, |
115 XK_Num_Lock, | 115 { XK_Select, SDLK_SELECT }, |
116 XK_KP_Divide, | 116 { XK_Cancel, SDLK_STOP }, |
117 XK_KP_Multiply, | 117 { XK_Redo, SDLK_AGAIN }, |
118 XK_KP_Subtract, | 118 { XK_Undo, SDLK_UNDO }, |
119 XK_KP_Add, | 119 { XK_Find, SDLK_FIND }, |
120 XK_KP_Enter, | 120 { XK_KP_Separator, SDLK_KP_COMMA }, |
121 XK_KP_1, | 121 { XK_Sys_Req, SDLK_SYSREQ }, |
122 XK_KP_2, | 122 { XK_Control_L, SDLK_LCTRL }, |
123 XK_KP_3, | 123 { XK_Shift_L, SDLK_LSHIFT }, |
124 XK_KP_4, | 124 { XK_Alt_L, SDLK_LALT }, |
125 XK_KP_5, | 125 { XK_Meta_L, SDLK_LGUI }, |
126 XK_KP_6, | 126 { XK_Super_L, SDLK_LGUI }, |
127 XK_KP_7, | 127 { XK_Control_R, SDLK_RCTRL }, |
128 XK_KP_8, | 128 { XK_Shift_R, SDLK_RSHIFT }, |
129 XK_KP_9, | 129 { XK_Alt_R, SDLK_RALT }, |
130 XK_KP_0, | 130 { XK_Meta_R, SDLK_RGUI }, |
131 XK_KP_Decimal, | 131 { XK_Super_R, SDLK_RGUI }, |
132 0, /* SDL_SCANCODE_NONUSBACKSLASH ? */ | 132 { XK_Mode_switch, SDLK_MODE }, |
133 XK_Hyper_R, | |
134 0, /* SDL_SCANCODE_POWER ? */ | |
135 XK_KP_Equal, | |
136 XK_F13, | |
137 XK_F14, | |
138 XK_F15, | |
139 XK_F16, | |
140 XK_F17, | |
141 XK_F18, | |
142 XK_F19, | |
143 XK_F20, | |
144 XK_F21, | |
145 XK_F22, | |
146 XK_F23, | |
147 XK_F24, | |
148 XK_Execute, | |
149 XK_Help, | |
150 XK_Menu, | |
151 XK_Select, | |
152 XK_Cancel, | |
153 XK_Redo, | |
154 XK_Undo, | |
155 0, /* SDL_SCANCODE_CUT ? */ | |
156 0, /* SDL_SCANCODE_COPY ? */ | |
157 0, /* SDL_SCANCODE_PASTE ? */ | |
158 XK_Find, | |
159 0, /* SDL_SCANCODE_MUTE ? */ | |
160 0, /* SDL_SCANCODE_VOLUMEUP ? */ | |
161 0, /* SDL_SCANCODE_VOLUMEDOWN ? */ | |
162 0, 0, 0, | |
163 XK_KP_Separator, | |
164 0, /* SDL_SCANCODE_KP_EQUALSAS400 ? */ | |
165 0, /* SDL_SCANCODE_INTERNATIONAL1 ? */ | |
166 0, /* SDL_SCANCODE_INTERNATIONAL2 ? */ | |
167 0, /* SDL_SCANCODE_INTERNATIONAL3 ? */ | |
168 0, /* SDL_SCANCODE_INTERNATIONAL4 ? */ | |
169 0, /* SDL_SCANCODE_INTERNATIONAL5 ? */ | |
170 0, /* SDL_SCANCODE_INTERNATIONAL6 ? */ | |
171 0, /* SDL_SCANCODE_INTERNATIONAL7 ? */ | |
172 0, /* SDL_SCANCODE_INTERNATIONAL8 ? */ | |
173 0, /* SDL_SCANCODE_INTERNATIONAL9 ? */ | |
174 0, /* SDL_SCANCODE_LANG1 ? */ | |
175 0, /* SDL_SCANCODE_LANG2 ? */ | |
176 0, /* SDL_SCANCODE_LANG3 ? */ | |
177 0, /* SDL_SCANCODE_LANG4 ? */ | |
178 0, /* SDL_SCANCODE_LANG5 ? */ | |
179 0, /* SDL_SCANCODE_LANG6 ? */ | |
180 0, /* SDL_SCANCODE_LANG7 ? */ | |
181 0, /* SDL_SCANCODE_LANG8 ? */ | |
182 0, /* SDL_SCANCODE_LANG9 ? */ | |
183 0, /* SDL_SCANCODE_ALTERASE ? */ | |
184 XK_Sys_Req, | |
185 0, /* SDL_SCANCODE_CANCEL ? - XK_Cancel was used above... */ | |
186 0, /* SDL_SCANCODE_CLEAR ? */ | |
187 0, /* SDL_SCANCODE_PRIOR ? - XK_Prior was used above... */ | |
188 0, /* SDL_SCANCODE_RETURN2 ? */ | |
189 0, /* SDL_SCANCODE_SEPARATOR ? */ | |
190 0, /* SDL_SCANCODE_OUT ? */ | |
191 0, /* SDL_SCANCODE_OPER ? */ | |
192 0, /* SDL_SCANCODE_CLEARAGAIN ? */ | |
193 0, /* SDL_SCANCODE_CRSEL ? */ | |
194 0, /* SDL_SCANCODE_EXSEL ? */ | |
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
196 0, /* SDL_SCANCODE_KP_00 ? */ | |
197 0, /* SDL_SCANCODE_KP_000 ? */ | |
198 0, /* SDL_SCANCODE_THOUSANDSSEPARATOR ? */ | |
199 0, /* SDL_SCANCODE_DECIMALSEPARATOR ? */ | |
200 0, /* SDL_SCANCODE_CURRENCYUNIT ? */ | |
201 0, /* SDL_SCANCODE_CURRENCYSUBUNIT ? */ | |
202 0, /* SDL_SCANCODE_KP_LEFTPAREN ? */ | |
203 0, /* SDL_SCANCODE_KP_RIGHTPAREN ? */ | |
204 0, /* SDL_SCANCODE_KP_LEFTBRACE ? */ | |
205 0, /* SDL_SCANCODE_KP_RIGHTBRACE ? */ | |
206 0, /* SDL_SCANCODE_KP_TAB ? */ | |
207 0, /* SDL_SCANCODE_KP_BACKSPACE ? */ | |
208 0, /* SDL_SCANCODE_KP_A ? */ | |
209 0, /* SDL_SCANCODE_KP_B ? */ | |
210 0, /* SDL_SCANCODE_KP_C ? */ | |
211 0, /* SDL_SCANCODE_KP_D ? */ | |
212 0, /* SDL_SCANCODE_KP_E ? */ | |
213 0, /* SDL_SCANCODE_KP_F ? */ | |
214 0, /* SDL_SCANCODE_KP_XOR ? */ | |
215 0, /* SDL_SCANCODE_KP_POWER ? */ | |
216 0, /* SDL_SCANCODE_KP_PERCENT ? */ | |
217 0, /* SDL_SCANCODE_KP_LESS ? */ | |
218 0, /* SDL_SCANCODE_KP_GREATER ? */ | |
219 0, /* SDL_SCANCODE_KP_AMPERSAND ? */ | |
220 0, /* SDL_SCANCODE_KP_DBLAMPERSAND ? */ | |
221 0, /* SDL_SCANCODE_KP_VERTICALBAR ? */ | |
222 0, /* SDL_SCANCODE_KP_DBLVERTICALBAR ? */ | |
223 0, /* SDL_SCANCODE_KP_COLON ? */ | |
224 0, /* SDL_SCANCODE_KP_HASH ? */ | |
225 0, /* SDL_SCANCODE_KP_SPACE ? */ | |
226 0, /* SDL_SCANCODE_KP_AT ? */ | |
227 0, /* SDL_SCANCODE_KP_EXCLAM ? */ | |
228 0, /* SDL_SCANCODE_KP_MEMSTORE ? */ | |
229 0, /* SDL_SCANCODE_KP_MEMRECALL ? */ | |
230 0, /* SDL_SCANCODE_KP_MEMCLEAR ? */ | |
231 0, /* SDL_SCANCODE_KP_MEMADD ? */ | |
232 0, /* SDL_SCANCODE_KP_MEMSUBTRACT ? */ | |
233 0, /* SDL_SCANCODE_KP_MEMMULTIPLY ? */ | |
234 0, /* SDL_SCANCODE_KP_MEMDIVIDE ? */ | |
235 0, /* SDL_SCANCODE_KP_PLUSMINUS ? */ | |
236 0, /* SDL_SCANCODE_KP_CLEAR ? */ | |
237 0, /* SDL_SCANCODE_KP_CLEARENTRY ? */ | |
238 0, /* SDL_SCANCODE_KP_BINARY ? */ | |
239 0, /* SDL_SCANCODE_KP_OCTAL ? */ | |
240 0, /* SDL_SCANCODE_KP_DECIMAL ? */ | |
241 0, /* SDL_SCANCODE_KP_HEXADECIMAL ? */ | |
242 0, 0, | |
243 XK_Control_L, | |
244 XK_Shift_L, | |
245 XK_Alt_L, | |
246 XK_Meta_L, | |
247 XK_Control_R, | |
248 XK_Shift_R, | |
249 XK_Alt_R, | |
250 XK_Meta_R, | |
251 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
252 XK_Mode_switch /*XK_ISO_Level3_Shift */ , | |
253 0, /* SDL_SCANCODE_AUDIONEXT ? */ | |
254 0, /* SDL_SCANCODE_AUDIOPREV ? */ | |
255 0, /* SDL_SCANCODE_AUDIOSTOP ? */ | |
256 0, /* SDL_SCANCODE_AUDIOPLAY ? */ | |
257 0, /* SDL_SCANCODE_AUDIOMUTE ? */ | |
258 0, /* SDL_SCANCODE_MEDIASELECT ? */ | |
259 0, /* SDL_SCANCODE_WWW ? */ | |
260 0, /* SDL_SCANCODE_MAIL ? */ | |
261 0, /* SDL_SCANCODE_CALCULATOR ? */ | |
262 0, /* SDL_SCANCODE_COMPUTER ? */ | |
263 0, /* SDL_SCANCODE_AC_SEARCH ? */ | |
264 0, /* SDL_SCANCODE_AC_HOME ? */ | |
265 0, /* SDL_SCANCODE_AC_BACK ? */ | |
266 0, /* SDL_SCANCODE_AC_FORWARD ? */ | |
267 0, /* SDL_SCANCODE_AC_STOP ? */ | |
268 0, /* SDL_SCANCODE_AC_REFRESH ? */ | |
269 0, /* SDL_SCANCODE_AC_BOOKMARKS ? */ | |
270 0, /* SDL_SCANCODE_BRIGHTNESSDOWN ? */ | |
271 0, /* SDL_SCANCODE_BRIGHTNESSUP ? */ | |
272 0, /* SDL_SCANCODE_DISPLAYSWITCH ? */ | |
273 0, /* SDL_SCANCODE_KBDILLUMTOGGLE ? */ | |
274 0, /* SDL_SCANCODE_KBDILLUMDOWN ? */ | |
275 0, /* SDL_SCANCODE_KBDILLUMUP ? */ | |
276 0, /* SDL_SCANCODE_EJECT ? */ | |
277 0, /* SDL_SCANCODE_SLEEP ? */ | |
278 }; | 133 }; |
279 | 134 |
280 /* *INDENT-OFF* */ | |
281 static struct | 135 static struct |
282 { | 136 { |
283 SDL_scancode *table; | 137 SDL_scancode *table; |
284 int table_size; | 138 int table_size; |
285 } scancode_set[] = { | 139 } scancode_set[] = { |
287 { xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) }, | 141 { xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) }, |
288 { xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) }, | 142 { xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) }, |
289 }; | 143 }; |
290 /* *INDENT-OFF* */ | 144 /* *INDENT-OFF* */ |
291 | 145 |
146 static SDLKey | |
147 X11_KeyCodeToSDLKey(Display *display, KeyCode keycode) | |
148 { | |
149 KeySym keysym; | |
150 unsigned int ucs4; | |
151 int i; | |
152 | |
153 keysym = XKeycodeToKeysym(display, keycode, 0); | |
154 if (keysym == NoSymbol) { | |
155 return SDLK_UNKNOWN; | |
156 } | |
157 | |
158 ucs4 = X11_KeySymToUcs4(keysym); | |
159 if (ucs4) { | |
160 return (SDLKey) ucs4; | |
161 } | |
162 | |
163 for (i = 0; i < SDL_arraysize(KeySymToSDLKey); ++i) { | |
164 if (keysym == KeySymToSDLKey[i].keysym) { | |
165 return KeySymToSDLKey[i].sdlkey; | |
166 } | |
167 } | |
168 return SDLK_UNKNOWN; | |
169 } | |
170 | |
292 int | 171 int |
293 X11_InitKeyboard(_THIS) | 172 X11_InitKeyboard(_THIS) |
294 { | 173 { |
295 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 174 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
296 SDL_Keyboard keyboard; | 175 SDL_Keyboard keyboard; |
297 int i, j; | 176 int i, j; |
298 int min_keycode, max_keycode; | 177 int min_keycode, max_keycode; |
299 SDL_scancode fingerprint_scancodes[] = { | 178 struct { |
300 SDL_SCANCODE_HOME, | 179 SDL_scancode scancode; |
301 SDL_SCANCODE_PAGEUP, | 180 KeySym keysym; |
302 SDL_SCANCODE_PAGEDOWN | 181 int value; |
182 } fingerprint[] = { | |
183 { SDL_SCANCODE_HOME, XK_Home, 0 }, | |
184 { SDL_SCANCODE_PAGEUP, XK_Prior, 0 }, | |
185 { SDL_SCANCODE_PAGEDOWN, XK_Next, 0 }, | |
303 }; | 186 }; |
304 int fingerprint[3]; | |
305 SDL_bool fingerprint_detected; | 187 SDL_bool fingerprint_detected; |
306 | 188 |
307 XAutoRepeatOn(data->display); | 189 XAutoRepeatOn(data->display); |
308 | 190 |
309 /* Try to determine which scancodes are being used based on fingerprint */ | 191 /* Try to determine which scancodes are being used based on fingerprint */ |
310 fingerprint_detected = SDL_FALSE; | 192 fingerprint_detected = SDL_FALSE; |
311 XDisplayKeycodes(data->display, &min_keycode, &max_keycode); | 193 XDisplayKeycodes(data->display, &min_keycode, &max_keycode); |
312 for (i = 0; i < SDL_arraysize(fingerprint_scancodes); ++i) { | 194 for (i = 0; i < SDL_arraysize(fingerprint); ++i) { |
313 fingerprint[i] = | 195 fingerprint[i].value = |
314 XKeysymToKeycode(data->display, | 196 XKeysymToKeycode(data->display, fingerprint[i].keysym) - |
315 XKeySymTable[fingerprint_scancodes[i]]) - | |
316 min_keycode; | 197 min_keycode; |
317 } | 198 } |
318 for (i = 0; i < SDL_arraysize(scancode_set); ++i) { | 199 for (i = 0; i < SDL_arraysize(scancode_set); ++i) { |
319 /* Make sure the scancode set isn't too big */ | 200 /* Make sure the scancode set isn't too big */ |
320 if ((max_keycode - min_keycode + 1) <= scancode_set[i].table_size) { | 201 if ((max_keycode - min_keycode + 1) <= scancode_set[i].table_size) { |
321 continue; | 202 continue; |
322 } | 203 } |
323 for (j = 0; j < SDL_arraysize(fingerprint); ++j) { | 204 for (j = 0; j < SDL_arraysize(fingerprint); ++j) { |
324 if (fingerprint[j] < 0 | 205 if (fingerprint[j].value < 0 |
325 || fingerprint[j] >= scancode_set[i].table_size) { | 206 || fingerprint[j].value >= scancode_set[i].table_size) { |
326 break; | 207 break; |
327 } | 208 } |
328 if (scancode_set[i].table[fingerprint[j]] != | 209 if (scancode_set[i].table[fingerprint[j].value] != |
329 fingerprint_scancodes[j]) { | 210 fingerprint[j].scancode) { |
330 break; | 211 break; |
331 } | 212 } |
332 } | 213 } |
333 if (j == SDL_arraysize(fingerprint)) { | 214 if (j == SDL_arraysize(fingerprint)) { |
334 /* printf("Using scancode set %d\n", i); */ | 215 /* printf("Using scancode set %d\n", i); */ |
338 break; | 219 break; |
339 } | 220 } |
340 } | 221 } |
341 | 222 |
342 if (!fingerprint_detected) { | 223 if (!fingerprint_detected) { |
224 SDLKey keymap[SDL_NUM_SCANCODES]; | |
225 | |
343 printf | 226 printf |
344 ("Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n"); | 227 ("Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n"); |
345 | 228 |
346 /* Determine key_layout - only works on US QWERTY layout */ | 229 /* Determine key_layout - only works on US QWERTY layout */ |
230 SDL_GetDefaultKeymap(keymap); | |
347 for (i = min_keycode; i <= max_keycode; ++i) { | 231 for (i = min_keycode; i <= max_keycode; ++i) { |
348 KeySym sym; | 232 KeySym sym; |
349 sym = XKeycodeToKeysym(data->display, i, 0); | 233 sym = XKeycodeToKeysym(data->display, i, 0); |
350 if (sym) { | 234 if (sym != NoSymbol) { |
235 SDLKey key; | |
351 printf("code = %d, sym = 0x%X (%s) ", i - min_keycode, sym, | 236 printf("code = %d, sym = 0x%X (%s) ", i - min_keycode, sym, |
352 XKeysymToString(sym)); | 237 XKeysymToString(sym)); |
353 for (j = 0; j < SDL_arraysize(XKeySymTable); ++j) { | 238 key = X11_KeyCodeToSDLKey(data->display, i); |
354 if (XKeySymTable[j] == sym) { | 239 for (j = 0; j < SDL_arraysize(keymap); ++j) { |
240 if (keymap[j] == key) { | |
355 data->key_layout[i] = (SDL_scancode) j; | 241 data->key_layout[i] = (SDL_scancode) j; |
356 break; | 242 break; |
357 } | 243 } |
358 } | 244 } |
359 if (j == SDL_arraysize(XKeySymTable)) { | 245 if (j == SDL_arraysize(keymap)) { |
360 printf("scancode not found\n"); | 246 printf("scancode not found\n"); |
361 } else { | 247 } else { |
362 printf("scancode = %d (%s)\n", j, SDL_GetScancodeName(j)); | 248 printf("scancode = %d (%s)\n", j, SDL_GetScancodeName(j)); |
363 } | 249 } |
364 } | 250 } |
380 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 266 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
381 int i; | 267 int i; |
382 SDL_scancode scancode; | 268 SDL_scancode scancode; |
383 SDLKey keymap[SDL_NUM_SCANCODES]; | 269 SDLKey keymap[SDL_NUM_SCANCODES]; |
384 | 270 |
385 SDL_GetDefaultKeymap(keymap); | 271 SDL_zero(keymap); |
386 | 272 |
387 for (i = 0; i < SDL_arraysize(data->key_layout); i++) { | 273 for (i = 0; i < SDL_arraysize(data->key_layout); i++) { |
388 | 274 |
389 /* Make sure this scancode is a valid character scancode */ | 275 /* Make sure this is a valid scancode */ |
390 scancode = data->key_layout[i]; | 276 scancode = data->key_layout[i]; |
391 if (scancode == SDL_SCANCODE_UNKNOWN || | 277 if (scancode == SDL_SCANCODE_UNKNOWN) { |
392 (keymap[scancode] & SDLK_SCANCODE_MASK)) { | |
393 continue; | 278 continue; |
394 } | 279 } |
395 | 280 |
396 keymap[scancode] = | 281 keymap[scancode] = X11_KeyCodeToSDLKey(data->display, (KeyCode)i); |
397 (SDLKey) X11_KeySymToUcs4(XKeycodeToKeysym(data->display, i, 0)); | |
398 } | 282 } |
399 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); | 283 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); |
400 } | 284 } |
401 | 285 |
402 void | 286 void |