aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-04-14 23:49:43 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-04-14 23:49:43 +0100
commitec0923e5cf9715943b198ea5c6f60e1037cef248 (patch)
tree7ccd43c47016ae0f612803df1626b038b0b0c772 /src/main.c
parentb2fc7c3978d2da4d1f559b15ba36f36fafbf297d (diff)
downloadimv-ec0923e5cf9715943b198ea5c6f60e1037cef248.tar.gz
Fix command text input
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c19
1 files changed, 11 insertions, 8 deletions
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;
}