Skip to content

Commit

Permalink
Make SDL_EnableKeyRepeat() just use the SDL2 repeat field
Browse files Browse the repository at this point in the history
This isn't a proper implementation which supports the corrent delay and
interval fields, but I still think it's better than nothing.

In particular, while we were trying to suppress key repeat events
before, we still got them because of SDL_TEXTINPUT events, which took
repeat into account, so if repeat is disabled, we just get a bunch of
events with SDLK_UNKNOWN (and a valid unicode char). Now, if key repeat
is enabled, at least those events look sensible, even if the timing is
not exactly what might've been wanted.
  • Loading branch information
sulix authored and slouken committed Nov 23, 2021
1 parent 9e43523 commit 713a2ec
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/SDL12_compat.c
Expand Up @@ -923,6 +923,7 @@ static char *WindowTitle = NULL;
static char *WindowIconTitle = NULL;
static SDL_Surface *VideoIcon20 = NULL;
static int EnabledUnicode = 0;
static SDL_bool EnabledKeyRepeat = SDL_TRUE;
/* Windows SDL1.2 never uses translated keyboard layouts for compatibility with
DirectInput, which didn't support them. Other platforms (MacOS, Linux) seem to,
but with varying levels of bugginess. So default to Translated Layouts on
Expand Down Expand Up @@ -3785,7 +3786,7 @@ EventFilter20to12(void *data, SDL_Event *event20)

case SDL_KEYDOWN:
FlushPendingKeydownEvent(0);
if (event20->key.repeat) {
if (event20->key.repeat && !EnabledKeyRepeat) {
return 1; /* ignore 2.0-style key repeat events */
}

Expand Down Expand Up @@ -6569,21 +6570,22 @@ SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue)
DECLSPEC int SDLCALL
SDL_EnableKeyRepeat(int delay, int interval)
{
FIXME("write me");
(void) delay;
FIXME("Support non-default delay and interval for Key Repeat");
(void) interval;

EnabledKeyRepeat = (delay != 0) ? SDL_TRUE : SDL_FALSE;

return 0;
}

DECLSPEC void SDLCALL
SDL_GetKeyRepeat(int *delay, int *interval)
{
FIXME("write me");
if (delay) {
*delay = SDL12_DEFAULT_REPEAT_DELAY;
*delay = EnabledKeyRepeat ? SDL12_DEFAULT_REPEAT_DELAY : 0;
}
if (interval) {
*interval = SDL12_DEFAULT_REPEAT_INTERVAL;
*interval = EnabledKeyRepeat ? SDL12_DEFAULT_REPEAT_INTERVAL : 0;
}
}

Expand Down

0 comments on commit 713a2ec

Please sign in to comment.