Skip to content

Commit

Permalink
Ignore shortcut keycodes
Browse files Browse the repository at this point in the history
Never inject keycodes used as shortcut modifiers.

Refs #4732 <#4732>
  • Loading branch information
rom1v committed Mar 7, 2024
1 parent c352d43 commit 9f00458
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ is_shortcut_mod(struct sc_input_manager *im, uint16_t sdl_mod) {
return sdl_mod & im->sdl_shortcut_mods;
}

static bool
is_shortcut_key(struct sc_input_manager *im, SDL_Keycode keycode) {
return (im->sdl_shortcut_mods & KMOD_LCTRL && keycode == SDLK_LCTRL)
|| (im->sdl_shortcut_mods & KMOD_RCTRL && keycode == SDLK_RCTRL)
|| (im->sdl_shortcut_mods & KMOD_LALT && keycode == SDLK_LALT)
|| (im->sdl_shortcut_mods & KMOD_RALT && keycode == SDLK_RALT)
|| (im->sdl_shortcut_mods & KMOD_LGUI && keycode == SDLK_LGUI)
|| (im->sdl_shortcut_mods & KMOD_RGUI && keycode == SDLK_RGUI);
}

void
sc_input_manager_init(struct sc_input_manager *im,
const struct sc_input_manager_params *params) {
Expand Down Expand Up @@ -395,7 +405,12 @@ sc_input_manager_process_key(struct sc_input_manager *im,
bool shift = event->keysym.mod & KMOD_SHIFT;
bool repeat = event->repeat;

bool smod = is_shortcut_mod(im, mod);
// Either the modifier includes a shortcut modifier, or the key
// press/release is a modifier key.
// The second condition is necessary to ignore the release of the modifier
// key (because in this case mod is 0).
bool is_shortcut = is_shortcut_mod(im, mod)
|| is_shortcut_key(im, keycode);

if (down && !repeat) {
if (keycode == im->last_keycode && mod == im->last_mod) {
Expand All @@ -407,8 +422,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
}
}

// The shortcut modifier is pressed
if (smod) {
if (is_shortcut) {
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
switch (keycode) {
case SDLK_h:
Expand Down

0 comments on commit 9f00458

Please sign in to comment.