[PATCH 2/5] text: Add commit request
Michael Hasselmann
michaelh at openismus.com
Thu Jan 31 10:25:29 PST 2013
On Thu, 2013-01-31 at 15:52 +0100, Jan Arne Petersen wrote:
> From: Jan Arne Petersen <jpetersen at openismus.com>
>
> Allows for atomic state changes. Updated surrounding text, content type
> and micro focus is taken into account all at once at commit.
Does this enforce the atomicity of state changes or does it rely on
well-behaved clients?
> Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
> ---
> clients/editor.c | 2 ++
> clients/keyboard.c | 35 ++++++++++++++++++++++++-----------
> clients/weston-simple-im.c | 9 ++++++++-
> protocol/input-method.xml | 1 +
> protocol/text.xml | 2 ++
> src/text-backend.c | 17 ++++++++++++++++-
> 6 files changed, 53 insertions(+), 13 deletions(-)
>
> diff --git a/clients/editor.c b/clients/editor.c
> index 1eb8f11..5c072f2 100644
> --- a/clients/editor.c
> +++ b/clients/editor.c
> @@ -558,6 +558,8 @@ text_entry_update(struct text_entry *entry)
> entry->text,
> entry->cursor,
> entry->anchor);
> +
> + text_model_commit(entry->model);
> }
>
> static void
> diff --git a/clients/keyboard.c b/clients/keyboard.c
> index 986dcff..8d94870 100644
> --- a/clients/keyboard.c
> +++ b/clients/keyboard.c
> @@ -45,6 +45,7 @@ struct virtual_keyboard {
> uint32_t serial;
> uint32_t content_hint;
> uint32_t content_purpose;
> + char *surrounding_text;
> struct window *window;
> struct widget *widget;
> };
> @@ -496,17 +497,9 @@ input_method_context_surrounding_text(void *data,
> uint32_t anchor)
> {
> struct virtual_keyboard *keyboard = data;
> - const struct layout *layout;
> -
> - layout = get_current_layout(keyboard);
> -
> - fprintf(stderr, "Surrounding text updated: %s\n", text);
> -
> - window_schedule_resize(keyboard->window,
> - layout->columns * key_width,
> - layout->rows * key_height);
>
> - widget_schedule_redraw(keyboard->widget);
> + free(keyboard->surrounding_text);
> + keyboard->surrounding_text = strdup(text);
> }
>
> static void
> @@ -559,11 +552,31 @@ input_method_context_invoke_action(void *data,
> virtual_keyboard_send_preedit(keyboard, index);
> }
>
> +static void
> +input_method_context_commit(void *data,
> + struct input_method_context *context)
> +{
> + struct virtual_keyboard *keyboard = data;
> + const struct layout *layout;
> +
> + layout = get_current_layout(keyboard);
> +
> + if (keyboard->surrounding_text)
> + fprintf(stderr, "Surrounding text updated: %s\n", keyboard->surrounding_text);
> +
> + window_schedule_resize(keyboard->window,
> + layout->columns * key_width,
> + layout->rows * key_height);
> +
> + widget_schedule_redraw(keyboard->widget);
> +}
> +
> static const struct input_method_context_listener input_method_context_listener = {
> input_method_context_surrounding_text,
> input_method_context_reset,
> input_method_context_content_type,
> - input_method_context_invoke_action
> + input_method_context_invoke_action,
> + input_method_context_commit
> };
>
> static void
> diff --git a/clients/weston-simple-im.c b/clients/weston-simple-im.c
> index d038382..fab7fc5 100644
> --- a/clients/weston-simple-im.c
> +++ b/clients/weston-simple-im.c
> @@ -140,11 +140,18 @@ input_method_context_invoke_action(void *data,
> {
> }
>
> +static void
> +input_method_context_commit(void *data,
> + struct input_method_context *context)
> +{
> +}
> +
> static const struct input_method_context_listener input_method_context_listener = {
> input_method_context_surrounding_text,
> input_method_context_reset,
> input_method_context_content_type,
> - input_method_context_invoke_action
> + input_method_context_invoke_action,
> + input_method_context_commit
> };
>
> static void
> diff --git a/protocol/input-method.xml b/protocol/input-method.xml
> index b4ffa72..690aee1 100644
> --- a/protocol/input-method.xml
> +++ b/protocol/input-method.xml
> @@ -131,6 +131,7 @@
> <arg name="button" type="uint"/>
> <arg name="index" type="uint"/>
> </event>
> + <event name="commit"/>
> </interface>
>
> <interface name="input_method" version="1">
> diff --git a/protocol/text.xml b/protocol/text.xml
> index 8004f91..7fdbcf1 100644
> --- a/protocol/text.xml
> +++ b/protocol/text.xml
> @@ -138,6 +138,8 @@
> <arg name="button" type="uint"/>
> <arg name="index" type="uint"/>
> </request>
> + <request name="commit">
> + </request>
> <event name="commit_string">
> <description summary="commit">
> Notify when text should be inserted into the editor widget. The text
> diff --git a/src/text-backend.c b/src/text-backend.c
> index c7761a9..f096a9b 100644
> --- a/src/text-backend.c
> +++ b/src/text-backend.c
> @@ -257,6 +257,20 @@ text_model_invoke_action(struct wl_client *client,
> }
> }
>
> +static void
> +text_model_commit(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_commit(&input_method->context->resource);
> + }
> +}
> +
> static const struct text_model_interface text_model_implementation = {
> text_model_set_surrounding_text,
> text_model_activate,
> @@ -264,7 +278,8 @@ static const struct text_model_interface text_model_implementation = {
> text_model_reset,
> text_model_set_micro_focus,
> text_model_set_content_type,
> - text_model_invoke_action
> + text_model_invoke_action,
> + text_model_commit
> };
>
> static void text_model_factory_create_text_model(struct wl_client *client,
More information about the wayland-devel
mailing list