From 43f4aa8cab93ae32e427ab8426261950d83f2755 Mon Sep 17 00:00:00 2001 From: Jan Arne Petersen Date: Sun, 9 Sep 2012 23:08:43 +0200 Subject: text: Add support for pre-edit string Add support of preedit-string to the example editor client. Also add a preedit_string request to the input_method_context interface and use that in the example weston keyboard to first create a pre-edit string when entering keys and commit it on space. Signed-off-by: Jan Arne Petersen --- clients/keyboard.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'clients/keyboard.c') diff --git a/clients/keyboard.c b/clients/keyboard.c index 6e73b333..4bc7d240 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -37,6 +37,7 @@ struct virtual_keyboard { struct input_method *input_method; struct input_method_context *context; struct display *display; + char *preedit_string; }; enum key_type { @@ -214,16 +215,27 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key) switch (key->key_type) { case keytype_default: - input_method_context_commit_string(keyboard->keyboard->context, - label, -1); + keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string, + label); + input_method_context_preedit_string(keyboard->keyboard->context, + keyboard->keyboard->preedit_string, + strlen(keyboard->keyboard->preedit_string)); break; case keytype_backspace: break; case keytype_enter: 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, - " ", -1); + keyboard->keyboard->preedit_string, + strlen(keyboard->keyboard->preedit_string)); + free(keyboard->keyboard->preedit_string); + keyboard->keyboard->preedit_string = strdup(""); break; case keytype_switch: if (keyboard->state == keyboardstate_default) @@ -297,6 +309,11 @@ input_method_activate(void *data, if (keyboard->context) input_method_context_destroy(keyboard->context); + if (keyboard->preedit_string) + free(keyboard->preedit_string); + + keyboard->preedit_string = strdup(""); + keyboard->context = context; input_method_context_add_listener(context, &input_method_context_listener, @@ -390,6 +407,7 @@ main(int argc, char *argv[]) } virtual_keyboard.context = NULL; + virtual_keyboard.preedit_string = NULL; wl_display_add_global_listener(display_get_display(virtual_keyboard.display), global_handler, &virtual_keyboard); -- cgit v1.2.3