Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11events.c @ 4565:e2d46c5c7483
Fixed key repeat detection on X11, and simplified the code for everyone else.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 21 Jul 2010 21:47:12 -0700 |
parents | 95352c671a6e |
children | c24ba2cc9583 |
comparison
equal
deleted
inserted
replaced
4563:ffd169948438 | 4565:e2d46c5c7483 |
---|---|
33 | 33 |
34 #include "SDL_timer.h" | 34 #include "SDL_timer.h" |
35 #include "SDL_syswm.h" | 35 #include "SDL_syswm.h" |
36 | 36 |
37 /*#define DEBUG_XEVENTS*/ | 37 /*#define DEBUG_XEVENTS*/ |
38 | |
39 /* Check to see if this is a repeated key. | |
40 (idea shamelessly lifted from GII -- thanks guys! :) | |
41 */ | |
42 static SDL_bool X11_KeyRepeat(Display *display, XEvent *event) | |
43 { | |
44 XEvent peekevent; | |
45 | |
46 if (XPending(display)) { | |
47 XPeekEvent(display, &peekevent); | |
48 if ((peekevent.type == KeyPress) && | |
49 (peekevent.xkey.keycode == event->xkey.keycode) && | |
50 ((peekevent.xkey.time-event->xkey.time) < 2)) { | |
51 return SDL_TRUE; | |
52 } | |
53 } | |
54 return SDL_FALSE; | |
55 } | |
38 | 56 |
39 static void | 57 static void |
40 X11_DispatchEvent(_THIS) | 58 X11_DispatchEvent(_THIS) |
41 { | 59 { |
42 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; | 60 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; |
174 | 192 |
175 /* Key press? */ | 193 /* Key press? */ |
176 case KeyPress:{ | 194 case KeyPress:{ |
177 KeyCode keycode = xevent.xkey.keycode; | 195 KeyCode keycode = xevent.xkey.keycode; |
178 KeySym keysym = NoSymbol; | 196 KeySym keysym = NoSymbol; |
197 SDL_scancode scancode; | |
179 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; | 198 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; |
180 Status status = 0; | 199 Status status = 0; |
181 | 200 |
182 #ifdef DEBUG_XEVENTS | 201 #ifdef DEBUG_XEVENTS |
183 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); | 202 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); |
184 #endif | 203 #endif |
185 /* FIXME: How do we tell if this was a key repeat? */ | 204 SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]); |
186 SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode], SDL_FALSE); | |
187 #if 1 | 205 #if 1 |
188 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) { | 206 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) { |
189 int min_keycode, max_keycode; | 207 int min_keycode, max_keycode; |
190 XDisplayKeycodes(display, &min_keycode, &max_keycode); | 208 XDisplayKeycodes(display, &min_keycode, &max_keycode); |
191 keysym = XKeycodeToKeysym(display, keycode, 0); | 209 keysym = XKeycodeToKeysym(display, keycode, 0); |
216 KeyCode keycode = xevent.xkey.keycode; | 234 KeyCode keycode = xevent.xkey.keycode; |
217 | 235 |
218 #ifdef DEBUG_XEVENTS | 236 #ifdef DEBUG_XEVENTS |
219 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); | 237 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); |
220 #endif | 238 #endif |
221 SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode], SDL_FALSE); | 239 if (X11_KeyRepeat(display, &xevent)) { |
240 /* We're about to get a repeated key down, ignore the key up */ | |
241 break; | |
242 } | |
243 SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]); | |
222 } | 244 } |
223 break; | 245 break; |
224 | 246 |
225 /* Have we been iconified? */ | 247 /* Have we been iconified? */ |
226 case UnmapNotify:{ | 248 case UnmapNotify:{ |