Commit b444cb02 authored by Sam Lantinga's avatar Sam Lantinga

Now gets correct keyboard state when starting up on X11

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40112
parent 8b57da4c
...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>. ...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>.
Major changes since SDL 1.0.0: Major changes since SDL 1.0.0:
</H2> </H2>
<UL> <UL>
<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers <LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
<LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.) <LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.)
<LI> 1.2.2: Improved OSS audio driver support, thanks to 4Front Tech. <LI> 1.2.2: Improved OSS audio driver support, thanks to 4Front Tech.
......
...@@ -843,6 +843,10 @@ void X11_SetKeyboardState(Display *display, const char *key_vec) ...@@ -843,6 +843,10 @@ void X11_SetKeyboardState(Display *display, const char *key_vec)
KeyCode xcode[SDLK_LAST]; KeyCode xcode[SDLK_LAST];
Uint8 new_kstate[SDLK_LAST]; Uint8 new_kstate[SDLK_LAST];
Uint8 *kstate = SDL_GetKeyState(NULL); Uint8 *kstate = SDL_GetKeyState(NULL);
SDLMod modstate;
Window junk_window;
int x, y;
unsigned int mask;
/* The first time the window is mapped, we initialize key state */ /* The first time the window is mapped, we initialize key state */
if ( ! key_vec ) { if ( ! key_vec ) {
...@@ -850,11 +854,31 @@ void X11_SetKeyboardState(Display *display, const char *key_vec) ...@@ -850,11 +854,31 @@ void X11_SetKeyboardState(Display *display, const char *key_vec)
XQueryKeymap(display, keys_return); XQueryKeymap(display, keys_return);
gen_event = 0; gen_event = 0;
} else { } else {
#if 1 /* We no longer generate key down events, just update state */
gen_event = 0;
#else
gen_event = 1; gen_event = 1;
#endif
} }
/* Zero the new state and generate it */ /* Get the keyboard modifier state */
memset(new_kstate, 0, sizeof(new_kstate)); modstate = 0;
get_modifier_masks(display);
if ( XQueryPointer(display, DefaultRootWindow(display),
&junk_window, &junk_window, &x, &y, &x, &y, &mask) ) {
if ( mask & LockMask ) {
modstate |= KMOD_CAPS;
}
if ( mask & mode_switch_mask ) {
modstate |= KMOD_MODE;
}
if ( mask & num_mask ) {
modstate |= KMOD_NUM;
}
}
/* Zero the new keyboard state and generate it */
memset(new_kstate, SDL_RELEASED, sizeof(new_kstate));
/* /*
* An obvious optimisation is to check entire longwords at a time in * An obvious optimisation is to check entire longwords at a time in
* both loops, but we can't be sure the arrays are aligned so it's not * both loops, but we can't be sure the arrays are aligned so it's not
...@@ -869,17 +893,47 @@ void X11_SetKeyboardState(Display *display, const char *key_vec) ...@@ -869,17 +893,47 @@ void X11_SetKeyboardState(Display *display, const char *key_vec)
SDL_keysym sk; SDL_keysym sk;
KeyCode kc = i << 3 | j; KeyCode kc = i << 3 | j;
X11_TranslateKey(display, NULL, kc, &sk); X11_TranslateKey(display, NULL, kc, &sk);
new_kstate[sk.sym] = 1; new_kstate[sk.sym] = SDL_PRESSED;
xcode[sk.sym] = kc; xcode[sk.sym] = kc;
} }
} }
} }
for(i = SDLK_FIRST+1; i < SDLK_LAST; i++) { for(i = SDLK_FIRST+1; i < SDLK_LAST; i++) {
int st; int state = new_kstate[i];
SDL_keysym sk;
if ( state == SDL_PRESSED ) {
if(kstate[i] == new_kstate[i]) switch (i) {
case SDLK_LSHIFT:
modstate |= KMOD_LSHIFT;
break;
case SDLK_RSHIFT:
modstate |= KMOD_RSHIFT;
break;
case SDLK_LCTRL:
modstate |= KMOD_LCTRL;
break;
case SDLK_RCTRL:
modstate |= KMOD_RCTRL;
break;
case SDLK_LALT:
modstate |= KMOD_LALT;
break;
case SDLK_RALT:
modstate |= KMOD_RALT;
break;
case SDLK_LMETA:
modstate |= KMOD_LMETA;
break;
case SDLK_RMETA:
modstate |= KMOD_RMETA;
break;
default:
break;
}
}
if ( kstate[i] == state )
continue; continue;
/* /*
* Send a fake keyboard event correcting the difference between * Send a fake keyboard event correcting the difference between
* SDL's keyboard state and the actual. Note that there is no * SDL's keyboard state and the actual. Note that there is no
...@@ -887,16 +941,31 @@ void X11_SetKeyboardState(Display *display, const char *key_vec) ...@@ -887,16 +941,31 @@ void X11_SetKeyboardState(Display *display, const char *key_vec)
* keys are released when focus is lost only keypresses should * keys are released when focus is lost only keypresses should
* be sent here * be sent here
*/ */
st = new_kstate[i] ? SDL_PRESSED : SDL_RELEASED;
memset(&sk, 0, sizeof(sk));
sk.sym = i;
sk.scancode = xcode[i]; /* only valid for key press */
if ( gen_event ) { if ( gen_event ) {
SDL_PrivateKeyboard(st, &sk); SDL_keysym sk;
memset(&sk, 0, sizeof(sk));
sk.sym = i;
sk.scancode = xcode[i]; /* only valid for key press */
SDL_PrivateKeyboard(state, &sk);
} else { } else {
kstate[i] = new_kstate[i]; kstate[i] = state;
} }
} }
/* Hack - set toggle key state */
if ( modstate & KMOD_CAPS ) {
kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
} else {
kstate[SDLK_CAPSLOCK] = SDL_RELEASED;
}
if ( modstate & KMOD_NUM ) {
kstate[SDLK_NUMLOCK] = SDL_PRESSED;
} else {
kstate[SDLK_NUMLOCK] = SDL_RELEASED;
}
/* Set the final modifier state */
SDL_SetModState(modstate);
} }
void X11_InitOSKeymap(_THIS) void X11_InitOSKeymap(_THIS)
......
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