[PATCH v2 01/28] text: Add language and text-direction to protocol

Jan Arne Petersen jpetersen at openismus.com
Thu Apr 18 07:47:15 PDT 2013


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

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 clients/editor.c           | 20 ++++++++++++++++-
 clients/keyboard.c         | 54 ++++++++++++++++++++++++++--------------------
 clients/weston-simple-im.c | 54 ++++++++++++++++++++++++++--------------------
 protocol/input-method.xml  | 11 ++++++++++
 protocol/text.xml          | 36 +++++++++++++++++++++++++++++++
 src/text-backend.c         | 46 +++++++++++++++++++++++++++++++++++++--
 tests/text-test.c          | 20 ++++++++++++++++-
 7 files changed, 191 insertions(+), 50 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 0de2500..e037c2f 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -391,6 +391,22 @@ text_model_input_panel_state(void *data,
 {
 }
 
+static void
+text_model_language(void *data,
+		    struct text_model *text_model,
+		    uint32_t serial,
+		    const char *language)
+{
+}
+
+static void
+text_model_text_direction(void *data,
+			  struct text_model *text_model,
+			  uint32_t serial,
+			  uint32_t direction)
+{
+}
+
 static const struct text_model_listener text_model_listener = {
 	text_model_commit_string,
 	text_model_preedit_string,
@@ -402,7 +418,9 @@ static const struct text_model_listener text_model_listener = {
 	text_model_keysym,
 	text_model_enter,
 	text_model_leave,
-	text_model_input_panel_state
+	text_model_input_panel_state,
+	text_model_language,
+	text_model_text_direction
 };
 
 static struct text_entry*
diff --git a/clients/keyboard.c b/clients/keyboard.c
index ad34b85..b23de42 100644
--- a/clients/keyboard.c
+++ b/clients/keyboard.c
@@ -492,11 +492,11 @@ button_handler(struct widget *widget,
 }
 
 static void
-input_method_context_surrounding_text(void *data,
-				      struct input_method_context *context,
-				      const char *text,
-				      uint32_t cursor,
-				      uint32_t anchor)
+handle_surrounding_text(void *data,
+			struct input_method_context *context,
+			const char *text,
+			uint32_t cursor,
+			uint32_t anchor)
 {
 	struct virtual_keyboard *keyboard = data;
 
@@ -505,9 +505,9 @@ input_method_context_surrounding_text(void *data,
 }
 
 static void
-input_method_context_reset(void *data,
-			   struct input_method_context *context,
-			   uint32_t serial)
+handle_reset(void *data,
+	     struct input_method_context *context,
+	     uint32_t serial)
 {
 	struct virtual_keyboard *keyboard = data;
 
@@ -529,10 +529,10 @@ input_method_context_reset(void *data,
 }
 
 static void
-input_method_context_content_type(void *data,
-				  struct input_method_context *context,
-				  uint32_t hint,
-				  uint32_t purpose)
+handle_content_type(void *data,
+		    struct input_method_context *context,
+		    uint32_t hint,
+		    uint32_t purpose)
 {
 	struct virtual_keyboard *keyboard = data;
 
@@ -541,10 +541,10 @@ input_method_context_content_type(void *data,
 }
 
 static void
-input_method_context_invoke_action(void *data,
-				   struct input_method_context *context,
-				   uint32_t button,
-				   uint32_t index)
+handle_invoke_action(void *data,
+		     struct input_method_context *context,
+		     uint32_t button,
+		     uint32_t index)
 {
 	struct virtual_keyboard *keyboard = data;
 
@@ -555,8 +555,8 @@ input_method_context_invoke_action(void *data,
 }
 
 static void
-input_method_context_commit(void *data,
-			    struct input_method_context *context)
+handle_commit(void *data,
+	      struct input_method_context *context)
 {
 	struct virtual_keyboard *keyboard = data;
 	const struct layout *layout;
@@ -573,12 +573,20 @@ input_method_context_commit(void *data,
 	widget_schedule_redraw(keyboard->widget);
 }
 
+static void
+handle_preferred_language(void *data,
+			  struct input_method_context *context,
+			  const char *language)
+{
+}
+
 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_commit
+	handle_surrounding_text,
+	handle_reset,
+	handle_content_type,
+	handle_invoke_action,
+	handle_commit,
+	handle_preferred_language
 };
 
 static void
diff --git a/clients/weston-simple-im.c b/clients/weston-simple-im.c
index e955d3c..9d31e3b 100644
--- a/clients/weston-simple-im.c
+++ b/clients/weston-simple-im.c
@@ -101,19 +101,19 @@ static const uint32_t ignore_keys_on_compose[] = {
 };
 
 static void
-input_method_context_surrounding_text(void *data,
-				      struct input_method_context *context,
-				      const char *text,
-				      uint32_t cursor,
-				      uint32_t anchor)
+handle_surrounding_text(void *data,
+			struct input_method_context *context,
+			const char *text,
+			uint32_t cursor,
+			uint32_t anchor)
 {
 	fprintf(stderr, "Surrounding text updated: %s\n", text);
 }
 
 static void
-input_method_context_reset(void *data,
-			   struct input_method_context *context,
-			   uint32_t serial)
+handle_reset(void *data,
+	     struct input_method_context *context,
+	     uint32_t serial)
 {
 	struct simple_im *keyboard = data;
 
@@ -125,33 +125,41 @@ input_method_context_reset(void *data,
 }
 
 static void
-input_method_context_content_type(void *data,
-				  struct input_method_context *context,
-				  uint32_t hint,
-				  uint32_t purpose)
+handle_content_type(void *data,
+		    struct input_method_context *context,
+		    uint32_t hint,
+		    uint32_t purpose)
 {
 }
 
 static void
-input_method_context_invoke_action(void *data,
-				   struct input_method_context *context,
-				   uint32_t button,
-				   uint32_t index)
+handle_invoke_action(void *data,
+		     struct input_method_context *context,
+		     uint32_t button,
+		     uint32_t index)
 {
 }
 
 static void
-input_method_context_commit(void *data,
-			    struct input_method_context *context)
+handle_commit(void *data,
+	      struct input_method_context *context)
+{
+}
+
+static void
+handle_preferred_language(void *data,
+			  struct input_method_context *context,
+			  const char *language)
 {
 }
 
 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_commit
+	handle_surrounding_text,
+	handle_reset,
+	handle_content_type,
+	handle_invoke_action,
+	handle_commit,
+	handle_preferred_language
 };
 
 static void
diff --git a/protocol/input-method.xml b/protocol/input-method.xml
index a59201b..59ac244 100644
--- a/protocol/input-method.xml
+++ b/protocol/input-method.xml
@@ -113,6 +113,14 @@
       <arg name="mods_locked" type="uint"/>
       <arg name="group" type="uint"/>
     </request>
+    <request name="language">
+      <arg name="serial" type="uint"/>
+      <arg name="language" type="string"/>
+    </request>
+    <request name="text_direction">
+      <arg name="serial" type="uint"/>
+      <arg name="direction" type="uint"/>
+    </request>
     <event name="surrounding_text">
       <description summary="surrounding text event">
         The plain surrounding text around the input position. Cursor is the
@@ -136,6 +144,9 @@
       <arg name="index" type="uint"/>
     </event>
     <event name="commit"/>
+    <event name="preferred_language">
+      <arg name="language" type="string"/>
+    </event>
   </interface>
 
   <interface name="input_method" version="1">
diff --git a/protocol/text.xml b/protocol/text.xml
index 28d12ed..3334769 100644
--- a/protocol/text.xml
+++ b/protocol/text.xml
@@ -150,6 +150,18 @@
         Requests input panels (virtual keyboard) to hide.
       </description>
     </request>
+    <request name="set_preferred_language">
+      <description summary="sets preferred language">
+        Sets a specific language. This allows for example a virtual keyboard to
+        show a language specific layout. The "language" argument is a RFC-3066 
+	format language tag.
+
+	It could be used for example in a word processor to indicate language of
+	currently edited document or in an instant message application which tracks
+	languages of contacts.
+      </description>
+      <arg name="language" type="string"/>
+    </request>
     <event name="commit_string">
       <description summary="commit">
         Notify when text should be inserted into the editor widget. The text
@@ -272,6 +284,30 @@
       </description>
       <arg name="state" type="uint"/>
     </event>
+    <event name="language">
+      <description summary="language">
+        Sets the language of the input text. The "language" argument is a RFC-3066 
+        format language tag.
+      </description>
+      <arg name="serial" type="uint"/>
+      <arg name="language" type="string"/>
+    </event>
+    <enum name="text_direction">
+      <entry name="auto" value="0" summary="automatic text direction based on text and language"/>
+      <entry name="ltr" value="1" summary="left-to-right"/>
+      <entry name="rtl" value="2" summary="right-to-left"/>
+    </enum>
+    <event name="text_direction">
+      <description summary="text direction">
+        Sets the text direction of input text.
+
+        It is mainly needed for showing input cursor on correct side of the
+        editor when there is no input yet done and making sure neutral
+        direction text is laid out properly.
+      </description>
+      <arg name="serial" type="uint"/>
+      <arg name="direction" type="uint"/>
+    </event>
   </interface>
 
   <interface name="text_model_factory" version="1">
diff --git a/src/text-backend.c b/src/text-backend.c
index a92aebe..7741123 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -300,6 +300,22 @@ text_model_hide_input_panel(struct wl_client *client,
 		wl_signal_emit(&ec->hide_input_panel_signal, ec);
 }
 
+static void
+text_model_set_preferred_language(struct wl_client *client,
+				  struct wl_resource *resource,
+				  const char *language)
+{
+	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_preferred_language(&input_method->context->resource,
+							     language);
+	}
+}
+
 static const struct text_model_interface text_model_implementation = {
 	text_model_set_surrounding_text,
 	text_model_activate,
@@ -310,7 +326,8 @@ static const struct text_model_interface text_model_implementation = {
 	text_model_invoke_action,
 	text_model_commit,
 	text_model_show_input_panel,
-	text_model_hide_input_panel
+	text_model_hide_input_panel,
+	text_model_set_preferred_language
 };
 
 static void text_model_factory_create_text_model(struct wl_client *client,
@@ -601,6 +618,29 @@ input_method_context_modifiers(struct wl_client *client,
 					   group);
 }
 
+static void
+input_method_context_language(struct wl_client *client,
+			      struct wl_resource *resource,
+			      uint32_t serial,
+			      const char *language)
+{
+	struct input_method_context *context = resource->data;
+
+	text_model_send_language(&context->model->resource, serial, language);
+}
+
+static void
+input_method_context_text_direction(struct wl_client *client,
+				    struct wl_resource *resource,
+				    uint32_t serial,
+				    uint32_t direction)
+{
+	struct input_method_context *context = resource->data;
+
+	text_model_send_text_direction(&context->model->resource, serial, direction);
+}
+
+
 static const struct input_method_context_interface input_method_context_implementation = {
 	input_method_context_destroy,
 	input_method_context_commit_string,
@@ -613,7 +653,9 @@ static const struct input_method_context_interface input_method_context_implemen
 	input_method_context_keysym,
 	input_method_context_grab_keyboard,
 	input_method_context_key,
-	input_method_context_modifiers
+	input_method_context_modifiers,
+	input_method_context_language,
+	input_method_context_text_direction
 };
 
 static void
diff --git a/tests/text-test.c b/tests/text-test.c
index f5c02ff..41bf750 100644
--- a/tests/text-test.c
+++ b/tests/text-test.c
@@ -131,6 +131,22 @@ text_model_input_panel_state(void *data,
 {
 }
 
+static void
+text_model_language(void *data,
+		    struct text_model *text_model,
+		    uint32_t serial,
+		    const char *language)
+{
+}
+
+static void
+text_model_text_direction(void *data,
+			  struct text_model *text_model,
+			  uint32_t serial,
+			  uint32_t direction)
+{
+}
+
 static const struct text_model_listener text_model_listener = {
 	text_model_commit_string,
 	text_model_preedit_string,
@@ -142,7 +158,9 @@ static const struct text_model_listener text_model_listener = {
 	text_model_keysym,
 	text_model_enter,
 	text_model_leave,
-	text_model_input_panel_state
+	text_model_input_panel_state,
+	text_model_language,
+	text_model_text_direction
 };
 
 TEST(text_test)
-- 
1.8.1.4



More information about the wayland-devel mailing list