Skip to content
Permalink
Browse files

Resolved bug #130

Use XFilterEvent() to handle dead-key composition under X11
Cleaned up the code in preparation for 1.3 API changes
  • Loading branch information
slouken committed Feb 4, 2006
1 parent 873e2d1 commit 7ed1f5fa3b61fc0e49b54e1cdf35c896cbc022cb
@@ -397,6 +397,8 @@ printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym),
if ( state == SDL_PRESSED ) {
keysym->mod = (SDLMod)modstate;
switch (keysym->sym) {
case SDLK_UNKNOWN:
break;
case SDLK_NUMLOCK:
modstate ^= KMOD_NUM;
if ( ! (modstate&KMOD_NUM) )
@@ -442,6 +444,8 @@ printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym),
}
} else {
switch (keysym->sym) {
case SDLK_UNKNOWN:
break;
case SDLK_NUMLOCK:
case SDLK_CAPSLOCK:
/* Only send keydown events */
@@ -499,17 +503,19 @@ printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym),
return(0);
}

/* Drop events that don't change state */
if ( SDL_KeyState[keysym->sym] == state ) {
if ( keysym->sym != SDLK_UNKNOWN ) {
/* Drop events that don't change state */
if ( SDL_KeyState[keysym->sym] == state ) {
#if 0
printf("Keyboard event didn't change state - dropped!\n");
#endif
return(0);
}
return(0);
}

/* Update internal keyboard state */
SDL_ModState = (SDLMod)modstate;
SDL_KeyState[keysym->sym] = state;
/* Update internal keyboard state */
SDL_ModState = (SDLMod)modstate;
SDL_KeyState[keysym->sym] = state;
}

/* Post the event, if desired */
posted = 0;
@@ -37,8 +37,7 @@
/* Heheh we're using X11 event code */
extern int X11_Pending(Display *display);
extern void X11_InitKeymap(void);
extern SDL_keysym *X11_TranslateKey(Display *display, XIC ic, XKeyEvent *xkey,
KeyCode kc, SDL_keysym *keysym);
extern SDLKey X11_TranslateKeycode(Display *display, KeyCode kc);

static int DGA_DispatchEvent(_THIS)
{
@@ -74,20 +73,64 @@ static int DGA_DispatchEvent(_THIS)
}
break;

/* Key press or release? */
case KeyPress:
/* Key press? */
case KeyPress: {
SDL_keysym keysym;
KeyCode keycode;
XKeyEvent xkey;

SDL_NAME(XDGAKeyEventToXKeyEvent)(&xevent.xkey, &xkey);
keycode = xkey.keycode;
#ifdef DEBUG_XEVENTS
printf("KeyPress (X11 keycode = 0x%X)\n", xkey.keycode);
#endif
/* Get the translated SDL virtual keysym */
keysym.scancode = keycode;
keysym.sym = X11_TranslateKeycode(DGA_Display, keycode);
keysym.mod = KMOD_NONE;
keysym.unicode = 0;

/* Look up the translated value for the key event */
if ( SDL_TranslateUNICODE ) {
static XComposeStatus state;
char keybuf[32];

if ( pXLookupString(&xkey, keybuf, sizeof(keybuf), NULL, &state) ) {
/*
* FIXME: XLookupString() may yield more than one
* character, so we need a mechanism to allow for
* this (perhaps null keypress events with a
* unicode value)
*/
keysym.unicode = (Uint8)keybuf[0];
}
}
posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
}
break;

/* Key release? */
case KeyRelease: {
SDL_keysym keysym;
KeyCode keycode;
XKeyEvent xkey;

SDL_NAME(XDGAKeyEventToXKeyEvent)(&xevent.xkey, &xkey);
posted = SDL_PrivateKeyboard((xevent.type == KeyPress),
X11_TranslateKey(DGA_Display, NULL/*no XIC*/,
&xkey, xkey.keycode,
&keysym));
keycode = xkey.keycode;
#ifdef DEBUG_XEVENTS
printf("KeyRelease (X11 keycode = 0x%X)\n", xkey.keycode);
#endif
/* Get the translated SDL virtual keysym */
keysym.scancode = keycode;
keysym.sym = X11_TranslateKeycode(DGA_Display, keycode);
keysym.mod = KMOD_NONE;
keysym.unicode = 0;
posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
}
break;

break;

}
return(posted);
}

0 comments on commit 7ed1f5f

Please sign in to comment.