From: Jan Arne Petersen <[email protected]> Add a reset request to the text_model interface and a reset event to the input_method_context interface. Use it to reset the pre-edit buffers in the example keyboard when the cursor is moved in the example editor client.
Signed-off-by: Jan Arne Petersen <[email protected]> --- clients/editor.c | 2 ++ clients/keyboard.c | 18 ++++++++++++++++++ protocol/input-method.xml | 2 ++ protocol/text.xml | 2 ++ src/text-backend.c | 15 +++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/clients/editor.c b/clients/editor.c index 2baf6af..301cbe2 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -548,6 +548,8 @@ text_entry_set_cursor_position(struct text_entry *entry, { entry->cursor = text_layout_xy_to_index(entry->layout, x, y); + text_model_reset(entry->model); + if (entry->cursor >= entry->preedit_cursor) { entry->cursor -= entry->preedit_cursor; } diff --git a/clients/keyboard.c b/clients/keyboard.c index 0cbf531..c90c5b2 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -303,8 +303,26 @@ input_method_context_surrounding_text(void *data, fprintf(stderr, "Surrounding text updated: %s\n", text); } +static void +input_method_context_reset(void *data, + struct input_method_context *context) +{ + struct virtual_keyboard *keyboard = data; + + fprintf(stderr, "Reset pre-edit buffer\n"); + + if (strlen(keyboard->preedit_string)) { + input_method_context_preedit_string(context, + "", + 0); + free(keyboard->preedit_string); + keyboard->preedit_string = strdup(""); + } +} + static const struct input_method_context_listener input_method_context_listener = { input_method_context_surrounding_text, + input_method_context_reset }; static void diff --git a/protocol/input-method.xml b/protocol/input-method.xml index 100fa46..09ab10c 100644 --- a/protocol/input-method.xml +++ b/protocol/input-method.xml @@ -68,6 +68,8 @@ <arg name="cursor" type="uint"/> <arg name="anchor" type="uint"/> </event> + <event name="reset"> + </event> </interface> <interface name="input_method" version="1"> diff --git a/protocol/text.xml b/protocol/text.xml index 62746d3..eded1c8 100644 --- a/protocol/text.xml +++ b/protocol/text.xml @@ -67,6 +67,8 @@ </description> <arg name="seat" type="object" interface="wl_seat"/> </request> + <request name="reset"> + </request> <request name="set_micro_focus"> <arg name="x" type="int"/> <arg name="y" type="int"/> diff --git a/src/text-backend.c b/src/text-backend.c index 0a93b6b..4190fe7 100644 --- a/src/text-backend.c +++ b/src/text-backend.c @@ -173,6 +173,20 @@ text_model_deactivate(struct wl_client *client, } static void +text_model_reset(struct wl_client *client, + struct wl_resource *resource) +{ + struct text_model *text_model = resource->data; + struct input_method *input_method, *next; + + wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { + if (!input_method->context) + continue; + input_method_context_send_reset(&input_method->context->resource); + } +} + +static void text_model_set_micro_focus(struct wl_client *client, struct wl_resource *resource, int32_t x, @@ -198,6 +212,7 @@ static const struct text_model_interface text_model_implementation = { text_model_set_surrounding_text, text_model_activate, text_model_deactivate, + text_model_reset, text_model_set_micro_focus, text_model_set_preedit, text_model_set_content_type -- 1.7.11.4 _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
