comparison src/video/x11/SDL_x11events.c @ 2325:c7bcf84ba1b9

Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text input event with the character รจ. You still get the keypress keyrelease events for the individual keys that go into composing the character.
author Bob Pendleton <bob@pendleton.com>
date Fri, 07 Mar 2008 20:54:11 +0000
parents 3202e4826c57
children 133562468ff2
comparison
equal deleted inserted replaced
2324:3202e4826c57 2325:c7bcf84ba1b9
1 #define DEBUG_XEVENTS
1 /* 2 /*
2 SDL - Simple DirectMedia Layer 3 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga 4 Copyright (C) 1997-2006 Sam Lantinga
4 5
5 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
37 XEvent xevent; 38 XEvent xevent;
38 int i; 39 int i;
39 40
40 SDL_zero(xevent); /* valgrind fix. --ryan. */ 41 SDL_zero(xevent); /* valgrind fix. --ryan. */
41 XNextEvent(videodata->display, &xevent); 42 XNextEvent(videodata->display, &xevent);
43
44 /* filter events catchs XIM events and sends them to the correct
45 handler */
46 if (XFilterEvent(&xevent, None) == True) {
47 #ifdef DEBUG_XEVENTS
48 printf("Filtered event of type = 0x%X\n", xevent.type);
49 #endif
50 return;
51 }
42 52
43 /* Send a SDL_SYSWMEVENT if the application wants them */ 53 /* Send a SDL_SYSWMEVENT if the application wants them */
44 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { 54 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
45 SDL_SysWMmsg wmmsg; 55 SDL_SysWMmsg wmmsg;
46 56
180 /* Key press? */ 190 /* Key press? */
181 case KeyPress:{ 191 case KeyPress:{
182 KeyCode keycode = xevent.xkey.keycode; 192 KeyCode keycode = xevent.xkey.keycode;
183 KeySym keysym = NoSymbol; 193 KeySym keysym = NoSymbol;
184 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; 194 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
185 Uint32 ucs4 = 0; 195 Status status = 0;
186 196
187 #ifdef DEBUG_XEVENTS 197 #ifdef DEBUG_XEVENTS
188 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 198 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
189 #endif 199 #endif
190 SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED, 200 SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED,
191 videodata->key_layout[keycode]); 201 videodata->key_layout[keycode]);
192 #if 1 202 #if 0
193 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) { 203 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
194 int min_keycode, max_keycode; 204 int min_keycode, max_keycode;
195 XDisplayKeycodes(videodata->display, &min_keycode, 205 XDisplayKeycodes(videodata->display, &min_keycode,
196 &max_keycode); 206 &max_keycode);
197 keysym = XKeycodeToKeysym(videodata->display, keycode, 0); 207 keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
199 "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n", 209 "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n",
200 keycode, keycode - min_keycode, keysym, 210 keycode, keycode - min_keycode, keysym,
201 XKeysymToString(keysym)); 211 XKeysymToString(keysym));
202 } 212 }
203 #endif 213 #endif
204 /* Xutf8LookupString(), works for Latin-1 */ 214 /* */
205 SDL_zero(text); 215 SDL_zero(text);
216 #ifdef X_HAVE_UTF8_STRING
217 if (data->ic) {
218 Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
219 &keysym, status);
220 }
221 #else
206 XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL); 222 XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
223 #endif
207 if (*text) { 224 if (*text) {
208 printf("Sending text event %s\n", text); 225 printf("Sending text event %s\n", text);
209 SDL_SendKeyboardText(videodata->keyboard, text); 226 SDL_SendKeyboardText(videodata->keyboard, text);
210 } 227 }
211 } 228 }