Commit 83dd6ffb authored by Sam Lantinga's avatar Sam Lantinga

Resolved bug #130

Use XFilterEvent() to handle dead-key composition under X11
Cleaned up the code in preparation for 1.3 API changes

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401331
parent 2a89b508
......@@ -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);
}
......
This diff is collapsed.
......@@ -25,5 +25,5 @@
/* Functions to be exported */
extern void X11_InitOSKeymap(_THIS);
extern void X11_PumpEvents(_THIS);
extern void X11_SetKeyboardState(Display *display, XIC ic, const char *key_vec);
extern void X11_SetKeyboardState(Display *display, const char *key_vec);
......@@ -43,6 +43,7 @@ SDL_X11_SYM(1,int,XDeleteProperty,(Display*,Window,Atom))
SDL_X11_SYM(1,int,XDestroyWindow,(Display*,Window))
SDL_X11_SYM(1,char*,XDisplayName,(_Xconst char*))
SDL_X11_SYM(1,int,XEventsQueued,(Display*,int))
SDL_X11_SYM(1,Bool,XFilterEvent,(XEvent *event, Window w))
SDL_X11_SYM(1,int,XFlush,(Display*))
SDL_X11_SYM(1,int,XFree,(void*))
SDL_X11_SYM(1,int,XFreeColormap,(Display*,Colormap))
......
......@@ -953,7 +953,7 @@ static int X11_CreateWindow(_THIS, SDL_Surface *screen,
}
/* Update the internal keyboard state */
X11_SetKeyboardState(SDL_Display, SDL_IC, NULL);
X11_SetKeyboardState(SDL_Display, NULL);
/* When the window is first mapped, ignore non-modifier keys */
{
......
......@@ -151,8 +151,8 @@ struct SDL_PrivateVideoData {
#define SDL_Window (this->hidden->SDL_Window)
#define WM_DELETE_WINDOW (this->hidden->WM_DELETE_WINDOW)
#define SDL_BlankCursor (this->hidden->BlankCursor)
#define SDL_IM (this->hidden->X11_IM)
#define SDL_IC (this->hidden->X11_IC)
#define SDL_IM (this->hidden->X11_IM)
#define SDL_IC (this->hidden->X11_IC)
#define SDL_windowid (this->hidden->SDL_windowid)
#define using_dga (this->hidden->using_dga)
#define use_mitshm (this->hidden->use_mitshm)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment