[PATCH 10/18] text: Rename text_model to text_input

Jan Arne Petersen jpetersen at openismus.com
Sun Apr 7 15:12:03 PDT 2013


From: Jan Arne Petersen <jpetersen at openismus.com>

Also rename text_model_factory to text_input_manager.

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 clients/editor.c   | 142 +++++++++++++++----------------
 clients/keyboard.c |  10 +--
 protocol/text.xml  |  61 +++++++-------
 src/text-backend.c | 242 ++++++++++++++++++++++++++---------------------------
 tests/text-test.c  | 106 +++++++++++------------
 5 files changed, 282 insertions(+), 279 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index c921c43..027b562 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -57,7 +57,7 @@ struct text_entry {
 		int32_t cursor;
 		int32_t anchor;
 	} pending_commit;
-	struct text_model *model;
+	struct text_input *text_input;
 	PangoLayout *layout;
 	struct {
 		xkb_mod_mask_t shift_mask;
@@ -69,7 +69,7 @@ struct text_entry {
 };
 
 struct editor {
-	struct text_model_factory *text_model_factory;
+	struct text_input_manager *text_input_manager;
 	struct display *display;
 	struct window *window;
 	struct widget *widget;
@@ -129,8 +129,8 @@ static void text_entry_reset_preedit(struct text_entry *entry);
 static void text_entry_commit_and_reset(struct text_entry *entry);
 
 static void
-text_model_commit_string(void *data,
-			 struct text_model *text_model,
+text_input_commit_string(void *data,
+			 struct text_input *text_input,
 			 uint32_t serial,
 			 const char *text)
 {
@@ -149,8 +149,8 @@ text_model_commit_string(void *data,
 }
 
 static void
-text_model_preedit_string(void *data,
-			  struct text_model *text_model,
+text_input_preedit_string(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  const char *text,
 			  const char *commit)
@@ -169,8 +169,8 @@ text_model_preedit_string(void *data,
 }
 
 static void
-text_model_delete_surrounding_text(void *data,
-				   struct text_model *text_model,
+text_input_delete_surrounding_text(void *data,
+				   struct text_input *text_input,
 				   uint32_t serial,
 				   int32_t index,
 				   uint32_t length)
@@ -201,8 +201,8 @@ text_model_delete_surrounding_text(void *data,
 }
 
 static void
-text_model_cursor_position(void *data,
-			   struct text_model *text_model,
+text_input_cursor_position(void *data,
+			   struct text_input *text_input,
 			   uint32_t serial,
 			   int32_t index,
 			   int32_t anchor)
@@ -214,8 +214,8 @@ text_model_cursor_position(void *data,
 }
 
 static void
-text_model_preedit_styling(void *data,
-			   struct text_model *text_model,
+text_input_preedit_styling(void *data,
+			   struct text_input *text_input,
 			   uint32_t serial,
 			   uint32_t index,
 			   uint32_t length,
@@ -229,24 +229,24 @@ text_model_preedit_styling(void *data,
 		entry->preedit_info.attr_list = pango_attr_list_new();
 
 	switch (style) {
-		case TEXT_MODEL_PREEDIT_STYLE_DEFAULT:
-		case TEXT_MODEL_PREEDIT_STYLE_UNDERLINE:
+		case TEXT_INPUT_PREEDIT_STYLE_DEFAULT:
+		case TEXT_INPUT_PREEDIT_STYLE_UNDERLINE:
 			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
 			break;
-		case TEXT_MODEL_PREEDIT_STYLE_INCORRECT:
+		case TEXT_INPUT_PREEDIT_STYLE_INCORRECT:
 			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
 			attr2 = pango_attr_underline_color_new(65535, 0, 0);
 			break;
-		case TEXT_MODEL_PREEDIT_STYLE_SELECTION:
+		case TEXT_INPUT_PREEDIT_STYLE_SELECTION:
 			attr1 = pango_attr_background_new(0.3 * 65535, 0.3 * 65535, 65535);
 			attr2 = pango_attr_foreground_new(65535, 65535, 65535);
 			break;
-		case TEXT_MODEL_PREEDIT_STYLE_HIGHLIGHT:
-		case TEXT_MODEL_PREEDIT_STYLE_ACTIVE:
+		case TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT:
+		case TEXT_INPUT_PREEDIT_STYLE_ACTIVE:
 			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
 			attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
 			break;
-		case TEXT_MODEL_PREEDIT_STYLE_INACTIVE:
+		case TEXT_INPUT_PREEDIT_STYLE_INACTIVE:
 			attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
 			attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535);
 			break;
@@ -266,8 +266,8 @@ text_model_preedit_styling(void *data,
 }
 
 static void
-text_model_preedit_cursor(void *data,
-			  struct text_model *text_model,
+text_input_preedit_cursor(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  int32_t index)
 {
@@ -277,8 +277,8 @@ text_model_preedit_cursor(void *data,
 }
 
 static void
-text_model_modifiers_map(void *data,
-			 struct text_model *text_model,
+text_input_modifiers_map(void *data,
+			 struct text_input *text_input,
 			 struct wl_array *map)
 {
 	struct text_entry *entry = data;
@@ -287,8 +287,8 @@ text_model_modifiers_map(void *data,
 }
 
 static void
-text_model_keysym(void *data,
-		  struct text_model *text_model,
+text_input_keysym(void *data,
+		  struct text_input *text_input,
 		  uint32_t serial,
 		  uint32_t time,
 		  uint32_t key,
@@ -356,8 +356,8 @@ text_model_keysym(void *data,
 }
 
 static void
-text_model_enter(void *data,
-		 struct text_model *text_model,
+text_input_enter(void *data,
+		 struct text_input *text_input,
 		 struct wl_surface *surface)
 {
 	struct text_entry *entry = data;
@@ -371,8 +371,8 @@ text_model_enter(void *data,
 }
 
 static void
-text_model_leave(void *data,
-		 struct text_model *text_model)
+text_input_leave(void *data,
+		 struct text_input *text_input)
 {
 	struct text_entry *entry = data;
 
@@ -380,21 +380,21 @@ text_model_leave(void *data,
 
 	entry->active = 0;
 
-	text_model_hide_input_panel(text_model);
+	text_input_hide_input_panel(text_input);
 
 	widget_schedule_redraw(entry->widget);
 }
 
 static void
-text_model_input_panel_state(void *data,
-			     struct text_model *text_model,
+text_input_input_panel_state(void *data,
+			     struct text_input *text_input,
 			     uint32_t state)
 {
 }
 
 static void
-text_model_language(void *data,
-		    struct text_model *text_model,
+text_input_language(void *data,
+		    struct text_input *text_input,
 		    uint32_t serial,
 		    const char *language)
 {
@@ -402,8 +402,8 @@ text_model_language(void *data,
 }
 
 static void
-text_model_text_direction(void *data,
-			  struct text_model *text_model,
+text_input_text_direction(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  uint32_t direction)
 {
@@ -413,13 +413,13 @@ text_model_text_direction(void *data,
 
 
 	switch (direction) {
-		case TEXT_MODEL_TEXT_DIRECTION_LTR:
+		case TEXT_INPUT_TEXT_DIRECTION_LTR:
 			pango_direction = PANGO_DIRECTION_LTR;
 			break;
-		case TEXT_MODEL_TEXT_DIRECTION_RTL:
+		case TEXT_INPUT_TEXT_DIRECTION_RTL:
 			pango_direction = PANGO_DIRECTION_RTL;
 			break;
-		case TEXT_MODEL_TEXT_DIRECTION_AUTO:
+		case TEXT_INPUT_TEXT_DIRECTION_AUTO:
 		default:
 			pango_direction = PANGO_DIRECTION_NEUTRAL;
 	}
@@ -427,20 +427,20 @@ text_model_text_direction(void *data,
 	pango_context_set_base_dir(context, pango_direction);
 }
 
-static const struct text_model_listener text_model_listener = {
-	text_model_enter,
-	text_model_leave,
-	text_model_modifiers_map,
-	text_model_input_panel_state,
-	text_model_preedit_string,
-	text_model_preedit_styling,
-	text_model_preedit_cursor,
-	text_model_commit_string,
-	text_model_cursor_position,
-	text_model_delete_surrounding_text,
-	text_model_keysym,
-	text_model_language,
-	text_model_text_direction
+static const struct text_input_listener text_input_listener = {
+	text_input_enter,
+	text_input_leave,
+	text_input_modifiers_map,
+	text_input_input_panel_state,
+	text_input_preedit_string,
+	text_input_preedit_styling,
+	text_input_preedit_cursor,
+	text_input_commit_string,
+	text_input_cursor_position,
+	text_input_delete_surrounding_text,
+	text_input_keysym,
+	text_input_language,
+	text_input_text_direction
 };
 
 static struct text_entry*
@@ -456,8 +456,8 @@ text_entry_create(struct editor *editor, const char *text)
 	entry->active = 0;
 	entry->cursor = strlen(text);
 	entry->anchor = entry->cursor;
-	entry->model = text_model_factory_create_text_model(editor->text_model_factory);
-	text_model_add_listener(entry->model, &text_model_listener, entry);
+	entry->text_input = text_input_manager_create_text_input(editor->text_input_manager);
+	text_input_add_listener(entry->text_input, &text_input_listener, entry);
 
 	widget_set_redraw_handler(entry->widget, text_entry_redraw_handler);
 	widget_set_button_handler(entry->widget, text_entry_button_handler);
@@ -469,7 +469,7 @@ static void
 text_entry_destroy(struct text_entry *entry)
 {
 	widget_destroy(entry->widget);
-	text_model_destroy(entry->model);
+	text_input_destroy(entry->text_input);
 	g_clear_object(&entry->layout);
 	free(entry->text);
 	free(entry);
@@ -537,17 +537,17 @@ text_entry_activate(struct text_entry *entry,
 	struct wl_surface *surface = window_get_wl_surface(entry->window);
 
 	if (entry->click_to_show && entry->active) {
-		text_model_show_input_panel(entry->model);
+		text_input_show_input_panel(entry->text_input);
 
 		return;
 	}
 
 	if (!entry->click_to_show)
-		text_model_show_input_panel(entry->model);
+		text_input_show_input_panel(entry->text_input);
 
 	entry->serial++;
 
-	text_model_activate(entry->model,
+	text_input_activate(entry->text_input,
 			    entry->serial,
 			    seat,
 			    surface);
@@ -557,7 +557,7 @@ static void
 text_entry_deactivate(struct text_entry *entry,
 		      struct wl_seat *seat)
 {
-	text_model_deactivate(entry->model,
+	text_input_deactivate(entry->text_input,
 			      seat);
 }
 
@@ -627,20 +627,20 @@ text_entry_update_layout(struct text_entry *entry)
 static void
 text_entry_update(struct text_entry *entry)
 {
-	text_model_set_content_type(entry->model,
-				    TEXT_MODEL_CONTENT_HINT_NONE,
+	text_input_set_content_type(entry->text_input,
+				    TEXT_INPUT_CONTENT_HINT_NONE,
 				    entry->content_purpose);
 
-	text_model_set_surrounding_text(entry->model,
+	text_input_set_surrounding_text(entry->text_input,
 					entry->text,
 					entry->cursor,
 					entry->anchor);
 
 	if (entry->preferred_language)
-		text_model_set_preferred_language(entry->model,
+		text_input_set_preferred_language(entry->text_input,
 						  entry->preferred_language);
 
-	text_model_commit_state(entry->model);
+	text_input_commit_state(entry->text_input);
 }
 
 static void
@@ -702,7 +702,7 @@ text_entry_commit_and_reset(struct text_entry *entry)
 	}
 
 	entry->serial++;
-	text_model_reset(entry->model, entry->serial);
+	text_input_reset(entry->text_input, entry->serial);
 }
 
 static void
@@ -746,7 +746,7 @@ text_entry_try_invoke_preedit_action(struct text_entry *entry,
 	}
 
 	if (state == WL_POINTER_BUTTON_STATE_RELEASED)
-		text_model_invoke_action(entry->model,
+		text_input_invoke_action(entry->text_input,
 					 button,
 					 cursor - entry->cursor);
 
@@ -1073,10 +1073,10 @@ global_handler(struct display *display, uint32_t name,
 {
 	struct editor *editor = data;
 
-	if (!strcmp(interface, "text_model_factory")) {
-		editor->text_model_factory =
+	if (!strcmp(interface, "text_input_manager")) {
+		editor->text_input_manager =
 			display_bind(display, name,
-				     &text_model_factory_interface, 1);
+				     &text_input_manager_interface, 1);
 	}
 }
 
@@ -1122,7 +1122,7 @@ main(int argc, char *argv[])
 	if (preferred_language)
 		editor.entry->preferred_language = strdup(preferred_language);
 	editor.editor = text_entry_create(&editor, "Numeric");
-	editor.editor->content_purpose = TEXT_MODEL_CONTENT_PURPOSE_NUMBER;
+	editor.editor->content_purpose = TEXT_INPUT_CONTENT_PURPOSE_NUMBER;
 	editor.editor->click_to_show = click_to_show;
 
 	window_set_title(editor.window, "Text Editor");
diff --git a/clients/keyboard.c b/clients/keyboard.c
index 1394d70..b2f66f0 100644
--- a/clients/keyboard.c
+++ b/clients/keyboard.c
@@ -211,7 +211,7 @@ static const struct layout normal_layout = {
 	12,
 	4,
 	"en",
-	TEXT_MODEL_TEXT_DIRECTION_LTR
+	TEXT_INPUT_TEXT_DIRECTION_LTR
 };
 
 static const struct layout numeric_layout = {
@@ -220,7 +220,7 @@ static const struct layout numeric_layout = {
 	12,
 	2,
 	"en",
-	TEXT_MODEL_TEXT_DIRECTION_LTR
+	TEXT_INPUT_TEXT_DIRECTION_LTR
 };
 
 static const struct layout arabic_layout = {
@@ -229,7 +229,7 @@ static const struct layout arabic_layout = {
 	13,
 	4,
 	"ar",
-	TEXT_MODEL_TEXT_DIRECTION_RTL
+	TEXT_INPUT_TEXT_DIRECTION_RTL
 };
 
 static const char *style_labels[] = {
@@ -314,8 +314,8 @@ static const struct layout *
 get_current_layout(struct virtual_keyboard *keyboard)
 {
 	switch (keyboard->content_purpose) {
-		case TEXT_MODEL_CONTENT_PURPOSE_DIGITS:
-		case TEXT_MODEL_CONTENT_PURPOSE_NUMBER:
+		case TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
+		case TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
 			return &numeric_layout;
 		default:
 			if (keyboard->preferred_language &&
diff --git a/protocol/text.xml b/protocol/text.xml
index 97ac8b4..85d67ff 100644
--- a/protocol/text.xml
+++ b/protocol/text.xml
@@ -26,24 +26,27 @@
     THIS SOFTWARE.
   </copyright>
 
-  <interface name="text_model" version="1">
-    <description summary="text model">
-      A model for text input. Adds support for text input and input methods to
-      applications. A text_model object is created from a text_model_factory and
-      corresponds typically to a text entry in an application. Requests are used
-      to activate/deactivate the model and set information like surrounding and
-      selected text or the content type. The information about entered text is
-      sent to the model via the pre-edit and commit events. Using this interface
-      removes the need for applications to directly process hardware key events
-      and compose text out of them.
+  <interface name="text_input" version="1">
+    <description summary="text input">
+      An object used for text input. Adds support for text input and input 
+      methods to applications. A text-input object is created from a
+      text_input_manager and corresponds typically to a text entry in an
+      application.
+      Requests are used to activate/deactivate the text-input object and set
+      state information like surrounding and selected text or the content type.
+      The information about entered text is sent to the text-input object via
+      the pre-edit and commit events. Using this interface removes the need
+      for applications to directly process hardware key events and compose text
+      out of them.
     </description>
     <request name="activate">
       <description summary="request activation">
-        Requests the model to be activated (typically when the text entry gets
-        focus). The seat argument is a wl_seat which maintains the focus for
-        this activation. The surface argument is a wl_surface assigned to the
-        model and tracked for focus lost. The activated event is emitted on
-        successful activation.
+        Requests the text-input object to be activated (typically when the 
+        text entry gets focus).
+        The seat argument is a wl_seat which maintains the focus for this
+        activation. The surface argument is a wl_surface assigned to the
+        text-input object and tracked for focus lost. The enter event
+        is emitted on successful activation.
       </description>
       <arg name="serial" type="uint"/>
       <arg name="seat" type="object" interface="wl_seat"/>
@@ -51,9 +54,9 @@
     </request>
     <request name="deactivate">
       <description summary="request deactivation">
-        Requests the model to be deactivated (typically when the text entry
-        lost focus). The seat argument is a wl_seat which was used for
-        activation.
+        Requests the text-input object to be deactivated (typically when the
+        text entry lost focus). The seat argument is a wl_seat which was used
+        for activation.
       </description>
       <arg name="seat" type="object" interface="wl_seat"/>
     </request>
@@ -166,15 +169,15 @@
     </request>
     <event name="enter">
       <description summary="enter event">
-        Notify the model when it is activated. Typically in response to an
-        activate request.
+        Notify the text-input object when it received focus. Typically in
+        response to an activate request.
       </description>
       <arg name="surface" type="object" interface="wl_surface"/>
     </event>
     <event name="leave">
       <description summary="leave event">
-        Notify the model when it is deactivated. Either in response to a
-        deactivate request or when the assigned surface lost focus or was
+        Notify the text-input object when it lost focus. Either in response
+        to a deactivate request or when the assigned surface lost focus or was
         destroyed.
       </description>
     </event>
@@ -312,15 +315,15 @@
     </event>
   </interface>
 
-  <interface name="text_model_factory" version="1">
-    <description summary="text model factory">
-      A factory for text models. This object is a global singleton.
+  <interface name="text_input_manager" version="1">
+    <description summary="text input manager">
+      A factory for text-input objects. This object is a global singleton.
     </description>
-    <request name="create_text_model">
-      <description summary="create text model">
-        Creates a new text model object.
+    <request name="create_text_input">
+      <description summary="create text input">
+        Creates a new text-input object.
       </description>
-      <arg name="id" type="new_id" interface="text_model"/>
+      <arg name="id" type="new_id" interface="text_input"/>
     </request>
   </interface>
 </protocol>
diff --git a/src/text-backend.c b/src/text-backend.c
index c083683..13fff24 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -32,7 +32,7 @@ struct input_method;
 struct input_method_context;
 struct text_backend;
 
-struct text_model {
+struct text_input {
 	struct wl_resource resource;
 
 	struct weston_compositor *ec;
@@ -44,8 +44,8 @@ struct text_model {
 	uint32_t input_panel_visible;
 };
 
-struct text_model_factory {
-	struct wl_global *text_model_factory_global;
+struct text_input_manager {
+	struct wl_global *text_input_manager_global;
 	struct wl_listener destroy_listener;
 
 	struct weston_compositor *ec;
@@ -57,7 +57,7 @@ struct input_method {
 	struct wl_listener destroy_listener;
 
 	struct weston_seat *seat;
-	struct text_model *model;
+	struct text_input *model;
 
 	struct wl_list link;
 
@@ -73,7 +73,7 @@ struct input_method {
 struct input_method_context {
 	struct wl_resource resource;
 
-	struct text_model *model;
+	struct text_input *model;
 	struct input_method *input_method;
 
 	struct wl_list link;
@@ -95,7 +95,7 @@ struct text_backend {
 	struct wl_listener destroy_listener;
 };
 
-static void input_method_context_create(struct text_model *model,
+static void input_method_context_create(struct text_input *model,
 					struct input_method *input_method,
 					uint32_t serial);
 static void input_method_context_end_keyboard_grab(struct input_method_context *context);
@@ -103,12 +103,12 @@ static void input_method_context_end_keyboard_grab(struct input_method_context *
 static void input_method_init_seat(struct weston_seat *seat);
 
 static void
-deactivate_text_model(struct text_model *text_model,
+deactivate_text_input(struct text_input *text_input,
 		      struct input_method *input_method)
 {
-	struct weston_compositor *ec = text_model->ec;
+	struct weston_compositor *ec = text_input->ec;
 
-	if (input_method->model == text_model) {
+	if (input_method->model == text_input) {
 		if (input_method->context && input_method->input_method_binding) {
 			input_method_context_end_keyboard_grab(input_method->context);
 			input_method_send_deactivate(input_method->input_method_binding,
@@ -119,34 +119,34 @@ deactivate_text_model(struct text_model *text_model,
 		input_method->model = NULL;
 		input_method->context = NULL;
 		wl_signal_emit(&ec->hide_input_panel_signal, ec);
-		text_model_send_leave(&text_model->resource);
+		text_input_send_leave(&text_input->resource);
 	}
 }
 
 static void
-destroy_text_model(struct wl_resource *resource)
+destroy_text_input(struct wl_resource *resource)
 {
-	struct text_model *text_model =
-		container_of(resource, struct text_model, resource);
+	struct text_input *text_input =
+		container_of(resource, struct text_input, resource);
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link)
-		deactivate_text_model(text_model, input_method);
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link)
+		deactivate_text_input(text_input, input_method);
 
-	free(text_model);
+	free(text_input);
 }
 
 static void
-text_model_set_surrounding_text(struct wl_client *client,
+text_input_set_surrounding_text(struct wl_client *client,
 				struct wl_resource *resource,
 				const char *text,
 				uint32_t cursor,
 				uint32_t anchor)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_surrounding_text(&input_method->context->resource,
@@ -157,61 +157,61 @@ text_model_set_surrounding_text(struct wl_client *client,
 }
 
 static void
-text_model_activate(struct wl_client *client,
+text_input_activate(struct wl_client *client,
 	            struct wl_resource *resource,
 		    uint32_t serial,
 		    struct wl_resource *seat,
 		    struct wl_resource *surface)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct weston_seat *weston_seat = seat->data;
 	struct input_method *input_method = weston_seat->input_method;
-	struct text_model *old = weston_seat->input_method->model;
-	struct weston_compositor *ec = text_model->ec;
+	struct text_input *old = weston_seat->input_method->model;
+	struct weston_compositor *ec = text_input->ec;
 
-	if (old == text_model)
+	if (old == text_input)
 		return;
 
 	if (old) {
-		deactivate_text_model(old,
+		deactivate_text_input(old,
 				      weston_seat->input_method);
 	}
 
-	input_method->model = text_model;
-	wl_list_insert(&text_model->input_methods, &input_method->link);
+	input_method->model = text_input;
+	wl_list_insert(&text_input->input_methods, &input_method->link);
 	input_method_init_seat(weston_seat);
 
-	text_model->surface = surface->data;
+	text_input->surface = surface->data;
 
-	input_method_context_create(text_model, input_method, serial);
+	input_method_context_create(text_input, input_method, serial);
 
-	if (text_model->input_panel_visible)
+	if (text_input->input_panel_visible)
 		wl_signal_emit(&ec->show_input_panel_signal, ec);
 
-	text_model_send_enter(&text_model->resource, &text_model->surface->resource);
+	text_input_send_enter(&text_input->resource, &text_input->surface->resource);
 }
 
 static void
-text_model_deactivate(struct wl_client *client,
+text_input_deactivate(struct wl_client *client,
 		      struct wl_resource *resource,
 		      struct wl_resource *seat)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct weston_seat *weston_seat = seat->data;
 
-	deactivate_text_model(text_model,
+	deactivate_text_input(text_input,
 			      weston_seat->input_method);
 }
 
 static void
-text_model_reset(struct wl_client *client,
+text_input_reset(struct wl_client *client,
 		 struct wl_resource *resource,
 		 uint32_t serial)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_reset(&input_method->context->resource, serial);
@@ -219,7 +219,7 @@ text_model_reset(struct wl_client *client,
 }
 
 static void
-text_model_set_cursor_rectangle(struct wl_client *client,
+text_input_set_cursor_rectangle(struct wl_client *client,
 				struct wl_resource *resource,
 				int32_t x,
 				int32_t y,
@@ -229,15 +229,15 @@ text_model_set_cursor_rectangle(struct wl_client *client,
 }
 
 static void
-text_model_set_content_type(struct wl_client *client,
+text_input_set_content_type(struct wl_client *client,
 			    struct wl_resource *resource,
 			    uint32_t hint,
 			    uint32_t purpose)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_content_type(&input_method->context->resource, hint, purpose);
@@ -245,15 +245,15 @@ text_model_set_content_type(struct wl_client *client,
 }
 
 static void
-text_model_invoke_action(struct wl_client *client,
+text_input_invoke_action(struct wl_client *client,
 			 struct wl_resource *resource,
 			 uint32_t button,
 			 uint32_t index)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_invoke_action(&input_method->context->resource, button, index);
@@ -261,13 +261,13 @@ text_model_invoke_action(struct wl_client *client,
 }
 
 static void
-text_model_commit_state(struct wl_client *client,
+text_input_commit_state(struct wl_client *client,
 			struct wl_resource *resource)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_commit(&input_method->context->resource);
@@ -275,40 +275,40 @@ text_model_commit_state(struct wl_client *client,
 }
 
 static void
-text_model_show_input_panel(struct wl_client *client,
+text_input_show_input_panel(struct wl_client *client,
 			    struct wl_resource *resource)
 {
-	struct text_model *text_model = resource->data;
-	struct weston_compositor *ec = text_model->ec;
+	struct text_input *text_input = resource->data;
+	struct weston_compositor *ec = text_input->ec;
 
-	text_model->input_panel_visible = 1;
+	text_input->input_panel_visible = 1;
 
-	if (!wl_list_empty(&text_model->input_methods))
+	if (!wl_list_empty(&text_input->input_methods))
 		wl_signal_emit(&ec->show_input_panel_signal, ec);
 }
 
 static void
-text_model_hide_input_panel(struct wl_client *client,
+text_input_hide_input_panel(struct wl_client *client,
 			    struct wl_resource *resource)
 {
-	struct text_model *text_model = resource->data;
-	struct weston_compositor *ec = text_model->ec;
+	struct text_input *text_input = resource->data;
+	struct weston_compositor *ec = text_input->ec;
 
-	text_model->input_panel_visible = 0;
+	text_input->input_panel_visible = 0;
 
-	if (!wl_list_empty(&text_model->input_methods))
+	if (!wl_list_empty(&text_input->input_methods))
 		wl_signal_emit(&ec->hide_input_panel_signal, ec);
 }
 
 static void
-text_model_set_preferred_language(struct wl_client *client,
+text_input_set_preferred_language(struct wl_client *client,
 				  struct wl_resource *resource,
 				  const char *language)
 {
-	struct text_model *text_model = resource->data;
+	struct text_input *text_input = resource->data;
 	struct input_method *input_method, *next;
 
-	wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
+	wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
 		if (!input_method->context)
 			continue;
 		input_method_context_send_preferred_language(&input_method->context->resource,
@@ -316,91 +316,91 @@ text_model_set_preferred_language(struct wl_client *client,
 	}
 }
 
-static const struct text_model_interface text_model_implementation = {
-	text_model_activate,
-	text_model_deactivate,
-	text_model_show_input_panel,
-	text_model_hide_input_panel,
-	text_model_reset,
-	text_model_set_surrounding_text,
-	text_model_set_content_type,
-	text_model_set_cursor_rectangle,
-	text_model_set_preferred_language,
-	text_model_commit_state,
-	text_model_invoke_action
+static const struct text_input_interface text_input_implementation = {
+	text_input_activate,
+	text_input_deactivate,
+	text_input_show_input_panel,
+	text_input_hide_input_panel,
+	text_input_reset,
+	text_input_set_surrounding_text,
+	text_input_set_content_type,
+	text_input_set_cursor_rectangle,
+	text_input_set_preferred_language,
+	text_input_commit_state,
+	text_input_invoke_action
 };
 
-static void text_model_factory_create_text_model(struct wl_client *client,
+static void text_input_manager_create_text_input(struct wl_client *client,
 						 struct wl_resource *resource,
 						 uint32_t id)
 {
-	struct text_model_factory *text_model_factory = resource->data;
-	struct text_model *text_model;
+	struct text_input_manager *text_input_manager = resource->data;
+	struct text_input *text_input;
 
-	text_model = calloc(1, sizeof *text_model);
+	text_input = calloc(1, sizeof *text_input);
 
-	text_model->resource.object.id = id;
-	text_model->resource.object.interface = &text_model_interface;
-	text_model->resource.object.implementation =
-		(void (**)(void)) &text_model_implementation;
+	text_input->resource.object.id = id;
+	text_input->resource.object.interface = &text_input_interface;
+	text_input->resource.object.implementation =
+		(void (**)(void)) &text_input_implementation;
 
-	text_model->resource.data = text_model;
-	text_model->resource.destroy = destroy_text_model;
+	text_input->resource.data = text_input;
+	text_input->resource.destroy = destroy_text_input;
 
-	text_model->ec = text_model_factory->ec;
+	text_input->ec = text_input_manager->ec;
 
-	wl_list_init(&text_model->input_methods);
+	wl_list_init(&text_input->input_methods);
 
-	wl_client_add_resource(client, &text_model->resource);
+	wl_client_add_resource(client, &text_input->resource);
 };
 
-static const struct text_model_factory_interface text_model_factory_implementation = {
-	text_model_factory_create_text_model
+static const struct text_input_manager_interface text_input_manager_implementation = {
+	text_input_manager_create_text_input
 };
 
 static void
-bind_text_model_factory(struct wl_client *client,
+bind_text_input_manager(struct wl_client *client,
 			void *data,
 			uint32_t version,
 			uint32_t id)
 {
-	struct text_model_factory *text_model_factory = data;
+	struct text_input_manager *text_input_manager = data;
 
 	/* No checking for duplicate binding necessary.
 	 * No events have to be sent, so we don't need the return value. */
-	wl_client_add_object(client, &text_model_factory_interface,
-			     &text_model_factory_implementation,
-			     id, text_model_factory);
+	wl_client_add_object(client, &text_input_manager_interface,
+			     &text_input_manager_implementation,
+			     id, text_input_manager);
 }
 
 static void
-text_model_factory_notifier_destroy(struct wl_listener *listener, void *data)
+text_input_manager_notifier_destroy(struct wl_listener *listener, void *data)
 {
-	struct text_model_factory *text_model_factory =
-		container_of(listener, struct text_model_factory, destroy_listener);
+	struct text_input_manager *text_input_manager =
+		container_of(listener, struct text_input_manager, destroy_listener);
 
-	wl_display_remove_global(text_model_factory->ec->wl_display,
-				 text_model_factory->text_model_factory_global);
+	wl_display_remove_global(text_input_manager->ec->wl_display,
+				 text_input_manager->text_input_manager_global);
 
-	free(text_model_factory);
+	free(text_input_manager);
 }
 
 static void
-text_model_factory_create(struct weston_compositor *ec)
+text_input_manager_create(struct weston_compositor *ec)
 {
-	struct text_model_factory *text_model_factory;
+	struct text_input_manager *text_input_manager;
 
-	text_model_factory = calloc(1, sizeof *text_model_factory);
+	text_input_manager = calloc(1, sizeof *text_input_manager);
 
-	text_model_factory->ec = ec;
+	text_input_manager->ec = ec;
 
-	text_model_factory->text_model_factory_global =
+	text_input_manager->text_input_manager_global =
 		wl_display_add_global(ec->wl_display,
-				      &text_model_factory_interface,
-				      text_model_factory, bind_text_model_factory);
+				      &text_input_manager_interface,
+				      text_input_manager, bind_text_input_manager);
 
-	text_model_factory->destroy_listener.notify = text_model_factory_notifier_destroy;
-	wl_signal_add(&ec->destroy_signal, &text_model_factory->destroy_listener);
+	text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy;
+	wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener);
 }
 
 static void
@@ -418,7 +418,7 @@ input_method_context_commit_string(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_commit_string(&context->model->resource, serial, text);
+	text_input_send_commit_string(&context->model->resource, serial, text);
 }
 
 static void
@@ -430,7 +430,7 @@ input_method_context_preedit_string(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_preedit_string(&context->model->resource, serial, text, commit);
+	text_input_send_preedit_string(&context->model->resource, serial, text, commit);
 }
 
 static void
@@ -443,7 +443,7 @@ input_method_context_preedit_styling(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_preedit_styling(&context->model->resource, serial, index, length, style);
+	text_input_send_preedit_styling(&context->model->resource, serial, index, length, style);
 }
 
 static void
@@ -454,7 +454,7 @@ input_method_context_preedit_cursor(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_preedit_cursor(&context->model->resource, serial, cursor);
+	text_input_send_preedit_cursor(&context->model->resource, serial, cursor);
 }
 
 static void
@@ -466,7 +466,7 @@ input_method_context_delete_surrounding_text(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_delete_surrounding_text(&context->model->resource, serial, index, length);
+	text_input_send_delete_surrounding_text(&context->model->resource, serial, index, length);
 }
 
 static void
@@ -478,7 +478,7 @@ input_method_context_cursor_position(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_cursor_position(&context->model->resource, serial, index, anchor);
+	text_input_send_cursor_position(&context->model->resource, serial, index, anchor);
 }
 
 static void
@@ -488,7 +488,7 @@ input_method_context_modifiers_map(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_modifiers_map(&context->model->resource, map);
+	text_input_send_modifiers_map(&context->model->resource, map);
 }
 
 static void
@@ -502,7 +502,7 @@ input_method_context_keysym(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_keysym(&context->model->resource, serial, time,
+	text_input_send_keysym(&context->model->resource, serial, time,
 			       sym, state, modifiers);
 }
 
@@ -626,7 +626,7 @@ input_method_context_language(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_language(&context->model->resource, serial, language);
+	text_input_send_language(&context->model->resource, serial, language);
 }
 
 static void
@@ -637,7 +637,7 @@ input_method_context_text_direction(struct wl_client *client,
 {
 	struct input_method_context *context = resource->data;
 
-	text_model_send_text_direction(&context->model->resource, serial, direction);
+	text_input_send_text_direction(&context->model->resource, serial, direction);
 }
 
 
@@ -671,7 +671,7 @@ destroy_input_method_context(struct wl_resource *resource)
 }
 
 static void
-input_method_context_create(struct text_model *model,
+input_method_context_create(struct text_input *model,
 			    struct input_method *input_method,
 			    uint32_t serial)
 {
@@ -764,7 +764,7 @@ input_method_notifier_destroy(struct wl_listener *listener, void *data)
 		container_of(listener, struct input_method, destroy_listener);
 
 	if (input_method->model)
-		deactivate_text_model(input_method->model, input_method);
+		deactivate_text_input(input_method->model, input_method);
 
 	wl_display_remove_global(input_method->seat->compositor->wl_display,
 				 input_method->input_method_global);
@@ -784,7 +784,7 @@ handle_keyboard_focus(struct wl_listener *listener, void *data)
 		return;
 
 	if (!surface || input_method->model->surface != surface)
-		deactivate_text_model(input_method->model,
+		deactivate_text_input(input_method->model,
 				      input_method);
 }
 
@@ -923,7 +923,7 @@ text_backend_init(struct weston_compositor *ec)
 
 	text_backend_configuration(text_backend);
 
-	text_model_factory_create(ec);
+	text_input_manager_create(ec);
 
 	return 0;
 }
diff --git a/tests/text-test.c b/tests/text-test.c
index 8983ac4..1feae66 100644
--- a/tests/text-test.c
+++ b/tests/text-test.c
@@ -26,22 +26,22 @@
 #include "weston-test-client-helper.h"
 #include "../clients/text-client-protocol.h"
 
-struct text_model_state {
+struct text_input_state {
 	int activated;
 	int deactivated;
 };
 
 static void
-text_model_commit_string(void *data,
-			 struct text_model *text_model,
+text_input_commit_string(void *data,
+			 struct text_input *text_input,
 			 uint32_t serial,
 			 const char *text)
 {
 }
 
 static void
-text_model_preedit_string(void *data,
-			  struct text_model *text_model,
+text_input_preedit_string(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  const char *text,
 			  const char *commit)
@@ -49,8 +49,8 @@ text_model_preedit_string(void *data,
 }
 
 static void
-text_model_delete_surrounding_text(void *data,
-				   struct text_model *text_model,
+text_input_delete_surrounding_text(void *data,
+				   struct text_input *text_input,
 				   uint32_t serial,
 				   int32_t index,
 				   uint32_t length)
@@ -58,8 +58,8 @@ text_model_delete_surrounding_text(void *data,
 }
 
 static void
-text_model_cursor_position(void *data,
-			   struct text_model *text_model,
+text_input_cursor_position(void *data,
+			   struct text_input *text_input,
 			   uint32_t serial,
 			   int32_t index,
 			   int32_t anchor)
@@ -67,8 +67,8 @@ text_model_cursor_position(void *data,
 }
 
 static void
-text_model_preedit_styling(void *data,
-			   struct text_model *text_model,
+text_input_preedit_styling(void *data,
+			   struct text_input *text_input,
 			   uint32_t serial,
 			   uint32_t index,
 			   uint32_t length,
@@ -77,23 +77,23 @@ text_model_preedit_styling(void *data,
 }
 
 static void
-text_model_preedit_cursor(void *data,
-			  struct text_model *text_model,
+text_input_preedit_cursor(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  int32_t index)
 {
 }
 
 static void
-text_model_modifiers_map(void *data,
-			 struct text_model *text_model,
+text_input_modifiers_map(void *data,
+			 struct text_input *text_input,
 			 struct wl_array *map)
 {
 }
 
 static void
-text_model_keysym(void *data,
-		  struct text_model *text_model,
+text_input_keysym(void *data,
+		  struct text_input *text_input,
 		  uint32_t serial,
 		  uint32_t time,
 		  uint32_t sym,
@@ -103,12 +103,12 @@ text_model_keysym(void *data,
 }
 
 static void
-text_model_enter(void *data,
-		 struct text_model *text_model,
+text_input_enter(void *data,
+		 struct text_input *text_input,
 		 struct wl_surface *surface)
 
 {
-	struct text_model_state *state = data;
+	struct text_input_state *state = data;
 
 	fprintf(stderr, "%s\n", __FUNCTION__);
 
@@ -116,77 +116,77 @@ text_model_enter(void *data,
 }
 
 static void
-text_model_leave(void *data,
-		 struct text_model *text_model)
+text_input_leave(void *data,
+		 struct text_input *text_input)
 {
-	struct text_model_state *state = data;
+	struct text_input_state *state = data;
 
 	state->deactivated += 1;
 }
 
 static void
-text_model_input_panel_state(void *data,
-			     struct text_model *text_model,
+text_input_input_panel_state(void *data,
+			     struct text_input *text_input,
 			     uint32_t state)
 {
 }
 
 static void
-text_model_language(void *data,
-		    struct text_model *text_model,
+text_input_language(void *data,
+		    struct text_input *text_input,
 		    uint32_t serial,
 		    const char *language)
 {
 }
 
 static void
-text_model_text_direction(void *data,
-			  struct text_model *text_model,
+text_input_text_direction(void *data,
+			  struct text_input *text_input,
 			  uint32_t serial,
 			  uint32_t direction)
 {
 }
 
-static const struct text_model_listener text_model_listener = {
-	text_model_enter,
-	text_model_leave,
-	text_model_modifiers_map,
-	text_model_input_panel_state,
-	text_model_preedit_string,
-	text_model_preedit_styling,
-	text_model_preedit_cursor,
-	text_model_commit_string,
-	text_model_cursor_position,
-	text_model_delete_surrounding_text,
-	text_model_keysym,
-	text_model_language,
-	text_model_text_direction
+static const struct text_input_listener text_input_listener = {
+	text_input_enter,
+	text_input_leave,
+	text_input_modifiers_map,
+	text_input_input_panel_state,
+	text_input_preedit_string,
+	text_input_preedit_styling,
+	text_input_preedit_cursor,
+	text_input_commit_string,
+	text_input_cursor_position,
+	text_input_delete_surrounding_text,
+	text_input_keysym,
+	text_input_language,
+	text_input_text_direction
 };
 
 TEST(text_test)
 {
 	struct client *client;
 	struct global *global;
-	struct text_model_factory *factory;
-	struct text_model *text_model;
-	struct text_model_state state;
+	struct text_input_manager *factory;
+	struct text_input *text_input;
+	struct text_input_state state;
 
 	client = client_create(100, 100, 100, 100);
 	assert(client);
 
 	factory = NULL;
 	wl_list_for_each(global, &client->global_list, link) {
-		if (strcmp(global->interface, "text_model_factory") == 0)
+		if (strcmp(global->interface, "text_input_manager") == 0)
 			factory = wl_registry_bind(client->wl_registry,
 						   global->name,
-						   &text_model_factory_interface, 1);
+						   &text_input_manager_interface, 1);
 	}
 
 	assert(factory);
 
 	memset(&state, 0, sizeof state);
-	text_model = text_model_factory_create_text_model(factory);
-	text_model_add_listener(text_model, &text_model_listener, &state);
+	text_input = text_input_manager_create_text_input(factory);
+	text_input_add_listener(text_input, &text_input_listener, &state);
 
 	/* Make sure our test surface has keyboard focus. */
 	wl_test_activate_surface(client->test->wl_test,
@@ -195,18 +195,18 @@ TEST(text_test)
 	assert(client->input->keyboard->focus == client->surface);
 
 	/* Activate test model and make sure we get enter event. */
-	text_model_activate(text_model, 0, client->input->wl_seat,
+	text_input_activate(text_input, 0, client->input->wl_seat,
 			    client->surface->wl_surface);
 	client_roundtrip(client);
 	assert(state.activated == 1 && state.deactivated == 0);
 
 	/* Deactivate test model and make sure we get leave event. */
-	text_model_deactivate(text_model, client->input->wl_seat);
+	text_input_deactivate(text_input, client->input->wl_seat);
 	client_roundtrip(client);
 	assert(state.activated == 1 && state.deactivated == 1);
 
 	/* Activate test model again. */
-	text_model_activate(text_model, 0, client->input->wl_seat,
+	text_input_activate(text_input, 0, client->input->wl_seat,
 			    client->surface->wl_surface);
 	client_roundtrip(client);
 	assert(state.activated == 2 && state.deactivated == 1);
-- 
1.8.1.4



More information about the wayland-devel mailing list