From 9576283907fed9cf7baad1bb15613a811894f719 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sat, 17 Apr 2021 13:15:31 +0100 Subject: [PATCH] Count repeated identical key events This will allow shortcuts such as MOD+n+n to open the settings panel. PR #2260 Signed-off-by: Romain Vimont --- app/src/input_manager.c | 19 +++++++++++++++++-- app/src/input_manager.h | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 574e02d4..b6006285 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -72,6 +72,10 @@ input_manager_init(struct input_manager *im, im->sdl_shortcut_mods.count = shortcut_mods->count; im->vfinger_down = false; + + im->last_keycode = SDLK_UNKNOWN; + im->last_mod = 0; + im->key_repeat = 0; } static void @@ -384,16 +388,27 @@ input_manager_process_key(struct input_manager *im, // control: indicates the state of the command-line option --no-control bool control = im->control; - bool smod = is_shortcut_mod(im, event->keysym.mod); - struct controller *controller = im->controller; SDL_Keycode keycode = event->keysym.sym; + uint16_t mod = event->keysym.mod; bool down = event->type == SDL_KEYDOWN; bool ctrl = event->keysym.mod & KMOD_CTRL; bool shift = event->keysym.mod & KMOD_SHIFT; bool repeat = event->repeat; + bool smod = is_shortcut_mod(im, mod); + + if (down && !repeat) { + if (keycode == im->last_keycode && mod == im->last_mod) { + ++im->key_repeat; + } else { + im->key_repeat = 0; + im->last_keycode = keycode; + im->last_mod = mod; + } + } + // The shortcut modifier is pressed if (smod) { int action = down ? ACTION_DOWN : ACTION_UP; diff --git a/app/src/input_manager.h b/app/src/input_manager.h index 160977b3..5c7e2b91 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -33,6 +33,13 @@ struct input_manager { } sdl_shortcut_mods; bool vfinger_down; + + // Tracks the number of identical consecutive shortcut key down events. + // Not to be confused with event->repeat, which counts the number of + // system-generated repeated key presses. + unsigned key_repeat; + SDL_Keycode last_keycode; + uint16_t last_mod; }; void