Use callbacks for key repeat control.

This commit is contained in:
Bill Currie 2013-01-14 12:53:42 +09:00
parent cf0729c818
commit 2a3986368e
2 changed files with 23 additions and 20 deletions

View File

@ -45,7 +45,6 @@
cvar_t *in_snd_block;
static keydest_t old_key_dest = key_none;
static int have_focus = 1;
@ -71,6 +70,16 @@ event_focusin (void)
}
}
static void
sdl_keydest_callback (keydest_t key_dest)
{
if (key_dest == key_game)
SDL_EnableKeyRepeat (0, SDL_DEFAULT_REPEAT_INTERVAL);
else
SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
}
void
IN_LL_ProcessEvents (void)
{
@ -81,16 +90,6 @@ IN_LL_ProcessEvents (void)
while (SDL_PollEvent (&event)) {
// Ugly key repeat handling. Should use a key_dest callback...
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game)
SDL_EnableKeyRepeat (0, SDL_DEFAULT_REPEAT_INTERVAL);
else
SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
}
switch (event.type) {
case SDL_ACTIVEEVENT:
if (event.active.state == SDL_APPINPUTFOCUS) {
@ -589,6 +588,7 @@ IN_LL_Init (void)
{
SDL_EnableUNICODE (1); // Enable UNICODE translation for keyboard input
Key_KeydestCallback (sdl_keydest_callback);
if (COM_CheckParm ("-nomouse"))
return;

View File

@ -84,7 +84,6 @@ cvar_t *in_mouse_accel;
static qboolean dga_avail;
static qboolean dga_active;
static keydest_t old_key_dest = key_none;
static int p_mouse_x, p_mouse_y;
static int input_grabbed = 0;
@ -597,20 +596,22 @@ XLateKey (XKeyEvent * ev, int *k, int *u)
*u = unicode;
}
static void
x11_keydest_callback (keydest_t key_dst)
{
if (key_dest == key_game) {
XAutoRepeatOff (x_disp);
} else {
XAutoRepeatOn (x_disp);
}
}
static void
event_key (XEvent *event)
{
int key, unicode;
x_time = event->xkey.time;
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game) {
XAutoRepeatOff (x_disp);
} else {
XAutoRepeatOn (x_disp);
}
}
XLateKey (&event->xkey, &key, &unicode);
Key_Event (key, unicode, event->type == KeyPress);
}
@ -842,6 +843,8 @@ IN_LL_Init (void)
in_mouse_avail = 1;
}
Key_KeydestCallback (x11_keydest_callback);
Cmd_AddCommand ("in_paste_buffer", in_paste_buffer_f,
"Paste the contents of X's C&P buffer to the console");
}