From 88d6dc2ef7ebee4b04b079455727034a0f594aae Mon Sep 17 00:00:00 2001 From: Jeinzi Date: Sat, 1 Sep 2018 00:34:50 +0200 Subject: Added support for multiple commands per bind. --- src/imv.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/imv.c') diff --git a/src/imv.c b/src/imv.c index dc3dedf..768ae21 100644 --- a/src/imv.c +++ b/src/imv.c @@ -760,10 +760,14 @@ static void handle_event(struct imv *imv, SDL_Event *event) } switch(event->type) { - case SDL_QUIT: - imv_command_exec(imv->commands, "quit", imv); + case SDL_QUIT: { + /* new scope needed in order to declare variables in a switch statement */ + struct list *commands = list_create(); + list_append(commands, "quit"); + imv_command_exec(imv->commands, commands, imv); + list_free(commands); break; - + } case SDL_TEXTINPUT: strncat(imv->input_buffer, event->text.text, command_buffer_len - 1); imv->need_redraw = true; @@ -780,8 +784,11 @@ static void handle_event(struct imv *imv, SDL_Event *event) imv->input_buffer = NULL; imv->need_redraw = true; } else if(event->key.keysym.sym == SDLK_RETURN) { - imv_command_exec(imv->commands, imv->input_buffer, imv); + struct list *commands = list_create(); + list_append(commands, imv->input_buffer); + imv_command_exec(imv->commands, commands, imv); SDL_StopTextInput(); + list_free(commands); free(imv->input_buffer); imv->input_buffer = NULL; imv->need_redraw = true; @@ -806,9 +813,9 @@ static void handle_event(struct imv *imv, SDL_Event *event) } break; default: { /* braces to allow const char *cmd definition */ - const char *cmd = imv_bind_handle_event(imv->binds, event); - if(cmd) { - imv_command_exec(imv->commands, cmd, imv); + struct list *cmds = imv_bind_handle_event(imv->binds, event); + if(cmds) { + imv_command_exec(imv->commands, cmds, imv); } } } -- cgit v1.2.3