[PATCH 3/5] text: Add activate/deactivate events

Jan Arne Petersen jpetersen at openismus.com
Fri Aug 10 07:47:21 PDT 2012


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

Let the client know when a text model gets activated or deactiavted.
---
 clients/editor.c   | 45 +++++++++++++++++++++++++++++----------------
 protocol/text.xml  |  4 +++-
 src/text-backend.c | 10 ++++++++++
 3 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 8f0e9d8..9cb7326 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -107,6 +107,28 @@ text_model_locale(void *data,
 {
 }
 
+static void
+text_model_activated(void *data,
+		     struct text_model *text_model)
+{
+	struct text_entry *entry = data;
+
+	entry->active = 1;
+
+	widget_schedule_redraw(entry->widget);
+}
+
+static void
+text_model_deactivated(void *data,
+		       struct text_model *text_model)
+{
+	struct text_entry *entry = data;
+
+	entry->active = 0;
+
+	widget_schedule_redraw(entry->widget);
+}
+
 static const struct text_model_listener text_model_listener = {
 	text_model_commit_string,
 	text_model_preedit_string,
@@ -114,7 +136,9 @@ static const struct text_model_listener text_model_listener = {
 	text_model_key,
 	text_model_selection_replacement,
 	text_model_direction,
-	text_model_locale
+	text_model_locale,
+	text_model_activated,
+	text_model_deactivated
 };
 
 static struct text_entry*
@@ -283,24 +307,13 @@ button_handler(struct widget *widget,
 	assert(!(activate_entry && activate_editor));
 
 	if (activate_entry) {
-		if (editor->editor->active)
-			text_entry_deactivate(editor->editor);
-		if (!editor->entry->active)
-			text_entry_activate(editor->entry);
+		text_entry_activate(editor->entry);
 	} else if (activate_editor) {
-		if (editor->entry->active)
-			text_entry_deactivate(editor->entry);
-		if (!editor->editor->active)
-			text_entry_activate(editor->editor);
+		text_entry_activate(editor->editor);
 	} else {
-		if (editor->entry->active)
-			text_entry_deactivate(editor->entry);
-		if (editor->editor->active)
-			text_entry_deactivate(editor->editor);
+		text_entry_deactivate(editor->entry);
+		text_entry_deactivate(editor->editor);
 	}
-	editor->entry->active = activate_entry;
-	editor->editor->active = activate_editor;
-	assert(!(editor->entry->active && editor->editor->active));
 
 	widget_schedule_redraw(widget);
 }
diff --git a/protocol/text.xml b/protocol/text.xml
index 54866e1..ac12a1a 100644
--- a/protocol/text.xml
+++ b/protocol/text.xml
@@ -33,7 +33,9 @@
     <event name="key"/>
     <event name="selection_replacement"/>
     <event name="direction"/>
-    <event name="locale"/>      
+    <event name="locale"/>
+    <event name="activated"/>
+    <event name="deactivated"/>
   </interface>
 
   <interface name="text_model_factory" version="1">
diff --git a/src/text-backend.c b/src/text-backend.c
index bed3f77..9113c9b 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -54,6 +54,7 @@ deactivate_text_model(struct text_model *text_model)
 	if (text_model->input_method->active_model == text_model) {
 		text_model->input_method->active_model = NULL;
 		wl_signal_emit(&ec->hide_input_panel_signal, ec);
+		text_model_send_deactivated(&text_model->resource);
 	}
 }
 
@@ -90,9 +91,18 @@ text_model_activate(struct wl_client *client,
 	struct text_model *text_model = resource->data;
 	struct weston_compositor *ec = text_model->input_method->ec;
 
+	if (text_model->input_method->active_model) {
+		if (text_model->input_method->active_model == text_model)
+			return;
+
+		deactivate_text_model(text_model->input_method->active_model);
+	}
+
 	text_model->input_method->active_model = text_model;
 
 	wl_signal_emit(&ec->show_input_panel_signal, ec);
+
+	text_model_send_activated(&text_model->resource);
 }
 
 static void
-- 
1.7.11.2



More information about the wayland-devel mailing list