From 50e1bf16fee2ca95e71b392c2a0bee97cd129bed Mon Sep 17 00:00:00 2001 From: svdijk Date: Sun, 5 Jan 2014 20:22:34 +0100 Subject: [PATCH] Fix key-repeats in the console (for instance the backspace key) --- src/backends/generic/header/input.h | 7 ++++++- src/backends/generic/vid.c | 9 +++++---- src/backends/sdl/input.c | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/backends/generic/header/input.h b/src/backends/generic/header/input.h index 844101af..fa6ef17b 100644 --- a/src/backends/generic/header/input.h +++ b/src/backends/generic/header/input.h @@ -41,6 +41,11 @@ typedef struct in_state int *in_speed_state; } in_state_t; +/* + * Keyboard initialisation. Called by the client. + */ +void IN_KeyboardInit(Key_Event_fp_t fp); + /* * Updates the state of the input queue */ @@ -49,7 +54,7 @@ void IN_Update(void); /* * Initializes the input backend */ -void IN_BackendInit(in_state_t *in_state_p, Key_Event_fp_t fp); +void IN_BackendInit(in_state_t *in_state_p); /* * Shuts the backend down diff --git a/src/backends/generic/vid.c b/src/backends/generic/vid.c index cfa2238a..218fc3f9 100644 --- a/src/backends/generic/vid.c +++ b/src/backends/generic/vid.c @@ -178,10 +178,7 @@ VID_LoadRefresh(void) in_state.in_speed_state = &in_speed.state; // Initiate the input backend - IN_BackendInit (&in_state, Do_Key_Event); - - // Initiate keyboard at the input backend - Key_ClearStates(); + IN_BackendInit (&in_state); // Declare the refresher as active ref_active = true; @@ -193,6 +190,10 @@ VID_LoadRefresh(void) return false; } + // Initiate keyboard at the input backend + IN_KeyboardInit(Do_Key_Event); + Key_ClearStates(); + Com_Printf("------------------------------------\n\n"); return true; } diff --git a/src/backends/sdl/input.c b/src/backends/sdl/input.c index 0a0e8cd7..b907015b 100644 --- a/src/backends/sdl/input.c +++ b/src/backends/sdl/input.c @@ -560,15 +560,15 @@ IN_MLookUp(void) /* ------------------------------------------------------------------ */ /* - * Initializes the backend + * Keyboard initialisation. Called by the client. */ void -IN_BackendInit(in_state_t *in_state_p, Key_Event_fp_t fp) +IN_KeyboardInit(Key_Event_fp_t fp) { - in_state = in_state_p; Key_Event_fp = fp; - mouse_x = mouse_y = 0; + /* SDL stuff. Moved here from IN_BackendInit because + * this must be done after video is initialized. */ #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetRelativeMouseMode(SDL_TRUE); have_grab = GLimp_InputIsGrabbed(); @@ -577,6 +577,16 @@ IN_BackendInit(in_state_t *in_state_p, Key_Event_fp_t fp) SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); have_grab = (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); #endif +} + +/* + * Initializes the backend + */ +void +IN_BackendInit(in_state_t *in_state_p) +{ + in_state = in_state_p; + mouse_x = mouse_y = 0; exponential_speedup = Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE); freelook = Cvar_Get("freelook", "1", 0);