comparison src/video/x11/SDL_x11events.c @ 2299:a7cbc25071b6

Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
author Bob Pendleton <bob@pendleton.com>
date Sat, 12 Jan 2008 18:07:06 +0000
parents dbc6d1893869
children c97ad1abe05b
comparison
equal deleted inserted replaced
2298:41d2599b7117 2299:a7cbc25071b6
26 #include <unistd.h> 26 #include <unistd.h>
27 27
28 #include "SDL_syswm.h" 28 #include "SDL_syswm.h"
29 #include "SDL_x11video.h" 29 #include "SDL_x11video.h"
30 #include "../../events/SDL_events_c.h" 30 #include "../../events/SDL_events_c.h"
31
32
33 /* Check to see if this is a repeated key.
34 (idea shamelessly lifted from GII -- thanks guys! :)
35 */
36 static int
37 X11_KeyRepeat(Display * display, XEvent * event)
38 {
39 XEvent peekevent;
40 int repeated;
41
42 repeated = 0;
43 if (XPending(display)) {
44 XPeekEvent(display, &peekevent);
45 if ((peekevent.type == KeyPress) &&
46 (peekevent.xkey.keycode == event->xkey.keycode) &&
47 ((peekevent.xkey.time - event->xkey.time) < 2)) {
48 repeated = 1;
49 XNextEvent(display, &peekevent);
50 }
51 }
52 return (repeated);
53 }
54 31
55 static void 32 static void
56 X11_DispatchEvent(_THIS) 33 X11_DispatchEvent(_THIS)
57 { 34 {
58 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 35 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
192 KeyCode keycode = xevent.xkey.keycode; 169 KeyCode keycode = xevent.xkey.keycode;
193 170
194 #ifdef DEBUG_XEVENTS 171 #ifdef DEBUG_XEVENTS
195 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 172 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
196 #endif 173 #endif
197 if (!X11_KeyRepeat(videodata->display, &xevent)) { 174 SDLKey physicalKey = videodata->keyCodeToSDLKTable[keycode];
198 SDLKey physicalKey = videodata->keyCodeToSDLKTable[keycode]; 175 SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED,
199 SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED, 176 (Uint8) keycode, physicalKey);
200 (Uint8) keycode, physicalKey);
201 #if 1 177 #if 1
202 if (physicalKey == SDLK_UNKNOWN) { 178 if (physicalKey == SDLK_UNKNOWN) {
203 fprintf(stderr, 179 fprintf(stderr,
204 "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. X11 KeyCode is %d, X11 KeySym 0x%X.\n", 180 "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. X11 KeyCode is %d, X11 KeySym 0x%X.\n",
205 (int) keycode, 181 (int) keycode,
206 (unsigned int) XKeycodeToKeysym(videodata-> 182 (unsigned int) XKeycodeToKeysym(videodata->display,
207 display, keycode, 183 keycode, 0));
208 0)); 184 }
209 } 185 #endif
210 #endif
211 }
212 } 186 }
213 break; 187 break;
214 188
215 /* Key release? */ 189 /* Key release? */
216 case KeyRelease:{ 190 case KeyRelease:{
217 KeyCode keycode = xevent.xkey.keycode; 191 KeyCode keycode = xevent.xkey.keycode;
218 192
219 #ifdef DEBUG_XEVENTS 193 #ifdef DEBUG_XEVENTS
220 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); 194 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
221 #endif 195 #endif
222 /* Check to see if this is a repeated key */
223 if (X11_KeyRepeat(videodata->display, &xevent)) {
224 break;
225 }
226
227 SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED, 196 SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED,
228 (Uint8) keycode, 197 (Uint8) keycode,
229 videodata->keyCodeToSDLKTable[keycode]); 198 videodata->keyCodeToSDLKTable[keycode]);
230 } 199 }
231 break; 200 break;