From ec0923e5cf9715943b198ea5c6f60e1037cef248 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Fri, 14 Apr 2017 23:49:43 +0100 Subject: Fix command text input --- src/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 09394c5..d0cfb78 100644 --- a/src/main.c +++ b/src/main.c @@ -299,6 +299,7 @@ int main(int argc, char** argv) /* start outside of command mode */ g_state.command_buffer = NULL; + SDL_StopTextInput(); /* initialize variables holding image dimentions */ int iw = 0, ih = 0; @@ -655,22 +656,30 @@ static void parse_args(int *argc, char ***argv) void handle_event(SDL_Event *event) { + const int command_buffer_len = 1024; switch(event->type) { case SDL_QUIT: imv_command_exec(g_state.cmds, "quit"); break; + case SDL_TEXTINPUT: + strncat(g_state.command_buffer, event->text.text, command_buffer_len - 1); + g_state.need_redraw = 1; + break; + case SDL_KEYDOWN: SDL_ShowCursor(SDL_DISABLE); if(g_state.command_buffer) { /* in command mode, update the buffer */ if(event->key.keysym.sym == SDLK_ESCAPE) { + SDL_StopTextInput(); free(g_state.command_buffer); g_state.command_buffer = NULL; g_state.need_redraw = 1; } else if(event->key.keysym.sym == SDLK_RETURN) { imv_command_exec(g_state.cmds, g_state.command_buffer); + SDL_StopTextInput(); free(g_state.command_buffer); g_state.command_buffer = NULL; g_state.need_redraw = 1; @@ -680,13 +689,6 @@ void handle_event(SDL_Event *event) g_state.command_buffer[len - 1] = '\0'; g_state.need_redraw = 1; } - } else if(event->key.keysym.sym >= ' ' && event->key.keysym.sym <= '~') { - const size_t len = strlen(g_state.command_buffer); - if(len + 1 < 1024) { - g_state.command_buffer[len] = event->key.keysym.sym; - g_state.command_buffer[len+1] = '\0'; - g_state.need_redraw = 1; - } } return; @@ -695,7 +697,8 @@ void handle_event(SDL_Event *event) switch (event->key.keysym.sym) { case SDLK_SEMICOLON: if(event->key.keysym.mod & KMOD_SHIFT) { - g_state.command_buffer = malloc(1024); + SDL_StartTextInput(); + g_state.command_buffer = malloc(command_buffer_len); g_state.command_buffer[0] = '\0'; g_state.need_redraw = 1; } -- cgit v1.2.3