Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402708
This commit is contained in:
Bob Pendleton 2008-01-12 18:07:06 +00:00
parent 4cf4bef5c7
commit 05ad8bbf51
3 changed files with 15 additions and 42 deletions

View file

@ -29,29 +29,6 @@
#include "SDL_x11video.h" #include "SDL_x11video.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
/* Check to see if this is a repeated key.
(idea shamelessly lifted from GII -- thanks guys! :)
*/
static int
X11_KeyRepeat(Display * display, XEvent * event)
{
XEvent peekevent;
int repeated;
repeated = 0;
if (XPending(display)) {
XPeekEvent(display, &peekevent);
if ((peekevent.type == KeyPress) &&
(peekevent.xkey.keycode == event->xkey.keycode) &&
((peekevent.xkey.time - event->xkey.time) < 2)) {
repeated = 1;
XNextEvent(display, &peekevent);
}
}
return (repeated);
}
static void static void
X11_DispatchEvent(_THIS) X11_DispatchEvent(_THIS)
{ {
@ -194,21 +171,18 @@ X11_DispatchEvent(_THIS)
#ifdef DEBUG_XEVENTS #ifdef DEBUG_XEVENTS
printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif #endif
if (!X11_KeyRepeat(videodata->display, &xevent)) { SDLKey physicalKey = videodata->keyCodeToSDLKTable[keycode];
SDLKey physicalKey = videodata->keyCodeToSDLKTable[keycode]; SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED,
SDL_SendKeyboardKey(videodata->keyboard, SDL_PRESSED, (Uint8) keycode, physicalKey);
(Uint8) keycode, physicalKey);
#if 1 #if 1
if (physicalKey == SDLK_UNKNOWN) { if (physicalKey == SDLK_UNKNOWN) {
fprintf(stderr, fprintf(stderr,
"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", "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",
(int) keycode, (int) keycode,
(unsigned int) XKeycodeToKeysym(videodata-> (unsigned int) XKeycodeToKeysym(videodata->display,
display, keycode, keycode, 0));
0));
}
#endif
} }
#endif
} }
break; break;
@ -219,11 +193,6 @@ X11_DispatchEvent(_THIS)
#ifdef DEBUG_XEVENTS #ifdef DEBUG_XEVENTS
printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif #endif
/* Check to see if this is a repeated key */
if (X11_KeyRepeat(videodata->display, &xevent)) {
break;
}
SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED, SDL_SendKeyboardKey(videodata->keyboard, SDL_RELEASED,
(Uint8) keycode, (Uint8) keycode,
videodata->keyCodeToSDLKTable[keycode]); videodata->keyCodeToSDLKTable[keycode]);

View file

@ -851,6 +851,8 @@ X11_InitKeyboard(_THIS)
int code; int code;
SDLKey sdlkey; SDLKey sdlkey;
XAutoRepeatOn(data->display);
/* A random collection of KeySym/SDLKey pairs that should be valid /* A random collection of KeySym/SDLKey pairs that should be valid
in any keyboard layout (if this isn't the case on yours, in any keyboard layout (if this isn't the case on yours,
please adjust). Using XKeysymToKeycode on these KeySyms please adjust). Using XKeysymToKeycode on these KeySyms
@ -904,7 +906,7 @@ X11_InitKeyboard(_THIS)
"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"); "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");
#endif #endif
data->keyCodeToSDLKTable = data->keyCodeToSDLKTable =
SDL_malloc(KeyCodeTableSize * sizeof(SDLKey)); SDL_malloc(KeyCodeTableSize * sizeof(SDLKey));
if (data->keyCodeToSDLKTable == NULL) { if (data->keyCodeToSDLKTable == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;

View file

@ -29,6 +29,8 @@ SDL_X11_SYM(Status,XAllocColorCells,(Display *a,Colormap b,Bool c,unsigned long
SDL_X11_SYM(XSizeHints*,XAllocSizeHints,(void),(),return) SDL_X11_SYM(XSizeHints*,XAllocSizeHints,(void),(),return)
SDL_X11_SYM(XStandardColormap *,XAllocStandardColormap,(void),(),return) SDL_X11_SYM(XStandardColormap *,XAllocStandardColormap,(void),(),return)
SDL_X11_SYM(XWMHints*,XAllocWMHints,(void),(),return) SDL_X11_SYM(XWMHints*,XAllocWMHints,(void),(),return)
SDL_X11_SYM(int,XAutoRepeatOn,(Display* a),(a),return)
SDL_X11_SYM(int,XAutoRepeatOff,(Display* a),(a),return)
SDL_X11_SYM(int,XChangePointerControl,(Display* a,Bool b,Bool c,int d,int e,int f),(a,b,c,d,e,f),return) SDL_X11_SYM(int,XChangePointerControl,(Display* a,Bool b,Bool c,int d,int e,int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XChangeProperty,(Display* a,Window b,Atom c,Atom d,int e,int f,_Xconst unsigned char* g,int h),(a,b,c,d,e,f,g,h),return) SDL_X11_SYM(int,XChangeProperty,(Display* a,Window b,Atom c,Atom d,int e,int f,_Xconst unsigned char* g,int h),(a,b,c,d,e,f,g,h),return)
SDL_X11_SYM(int,XChangeWindowAttributes,(Display* a,Window b,unsigned long c,XSetWindowAttributes* d),(a,b,c,d),return) SDL_X11_SYM(int,XChangeWindowAttributes,(Display* a,Window b,unsigned long c,XSetWindowAttributes* d),(a,b,c,d),return)