Skip to content

Commit

Permalink
Count repeated identical key events
Browse files Browse the repository at this point in the history
This will allow shortcuts such as MOD+n+n to open the settings panel.

PR #2260 <#2260>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
brunoais authored and rom1v committed Apr 20, 2021
1 parent f06dbd7 commit b8f3064
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions app/src/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8f3064

Please sign in to comment.