diff options
author | Jan Arne Petersen <jpetersen@openismus.com> | 2012-09-09 23:08:43 +0200 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-09-12 16:50:44 -0400 |
commit | 43f4aa8cab93ae32e427ab8426261950d83f2755 (patch) | |
tree | 50aa679d41e0e60a24ae3b91c1e166eb0863cade /clients/keyboard.c | |
parent | 892f1c39751ec7bda7f1e44988182764772b3c7c (diff) |
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 <jpetersen@openismus.com>
Diffstat (limited to 'clients/keyboard.c')
-rw-r--r-- | clients/keyboard.c | 24 |
1 files changed, 21 insertions, 3 deletions
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); |