From 5ec05fb25144f083ff894f27c206b05f723fb125 Mon Sep 17 00:00:00 2001 From: Jan Arne Petersen Date: Mon, 5 Nov 2012 03:26:42 +0100 Subject: [PATCH] keyboard: commit preedit before sending key events Commit the current preedit text before sending control key events. Signed-off-by: Jan Arne Petersen --- clients/keyboard.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/clients/keyboard.c b/clients/keyboard.c index 4f62d9c3..1b2a9ba7 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -216,6 +216,23 @@ resize_handler(struct widget *widget, /* struct keyboard *keyboard = data; */ } +static void +virtual_keyboard_commit_preedit(struct virtual_keyboard *keyboard) +{ + if (!keyboard->preedit_string || + strlen(keyboard->preedit_string) == 0) + return; + + input_method_context_preedit_string(keyboard->context, + "", + 0); + input_method_context_commit_string(keyboard->context, + keyboard->preedit_string, + strlen(keyboard->preedit_string)); + free(keyboard->preedit_string); + keyboard->preedit_string = strdup(""); +} + static void keyboard_handle_key(struct keyboard *keyboard, const struct key *key) { @@ -241,20 +258,14 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key) } break; case keytype_enter: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_KP_Enter, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_space: keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string, " "); - input_method_context_preedit_string(keyboard->keyboard->context, - "", - 0); - input_method_context_commit_string(keyboard->keyboard->context, - keyboard->keyboard->preedit_string, - strlen(keyboard->keyboard->preedit_string)); - free(keyboard->keyboard->preedit_string); - keyboard->keyboard->preedit_string = strdup(""); + virtual_keyboard_commit_preedit(keyboard->keyboard); break; case keytype_switch: if (keyboard->state == keyboardstate_default) @@ -265,22 +276,27 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key) case keytype_symbols: break; case keytype_tab: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_Tab, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_arrow_up: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_Up, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_arrow_left: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_Left, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_arrow_right: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_Right, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_arrow_down: + virtual_keyboard_commit_preedit(keyboard->keyboard); input_method_context_key(keyboard->keyboard->context, XKB_KEY_Down, WL_KEYBOARD_KEY_STATE_PRESSED); break;