From ab780ce26db85235baf9e182f3d8aa0a9569d16a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 6 Mar 2018 11:11:07 +0100 Subject: [PATCH] Avoid useless variables initialization Initialize variables only when necessary. --- app/src/inputmanager.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/inputmanager.c b/app/src/inputmanager.c index c5d15924..dd273e93 100644 --- a/app/src/inputmanager.c +++ b/app/src/inputmanager.c @@ -130,23 +130,24 @@ void input_manager_process_text_input(struct input_manager *input_manager, void input_manager_process_key(struct input_manager *input_manager, const SDL_KeyboardEvent *event) { - SDL_Keycode keycode = event->keysym.sym; SDL_bool ctrl = event->keysym.mod & (KMOD_LCTRL | KMOD_RCTRL); - SDL_bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT); - SDL_bool repeat = event->repeat; // capture all Ctrl events if (ctrl) { + SDL_bool repeat = event->repeat; + // only consider keydown events, and ignore repeated events if (repeat || event->type != SDL_KEYDOWN) { return; } + SDL_bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT); if (shift) { // currently, there is no shortcut implying SHIFT return; } + SDL_Keycode keycode = event->keysym.sym; switch (keycode) { case SDLK_h: action_home(input_manager->controller);