text: Add reset requets to protocol
authorJan Arne Petersen <jpetersen@openismus.com>
Sun, 9 Sep 2012 21:08:46 +0000 (23:08 +0200)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 12 Sep 2012 20:52:53 +0000 (16:52 -0400)
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 <jpetersen@openismus.com>
clients/editor.c
clients/keyboard.c
protocol/input-method.xml
protocol/text.xml
src/text-backend.c

index 2baf6af..301cbe2 100644 (file)
@@ -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;
        }
index 0cbf531..c90c5b2 100644 (file)
@@ -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
index 100fa46..09ab10c 100644 (file)
@@ -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">
index 62746d3..eded1c8 100644 (file)
@@ -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"/>
index 0a93b6b..4190fe7 100644 (file)
@@ -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