[PATCH 3/5] text: Add show/hide_input_panel requests

Jan Arne Petersen jpetersen at openismus.com
Thu Jan 31 06:52:21 PST 2013


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

Allows to show/hide the input panel (virtual keyboard) more independent
of focus (some applications might to require additionaly click on a
focused entry to show the input panel).

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 clients/editor.c   | 30 +++++++++++++++++++++++++++++-
 protocol/text.xml  | 16 ++++++++++++++++
 src/shell.c        |  3 +++
 src/text-backend.c | 35 +++++++++++++++++++++++++++++++++--
 4 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 5c072f2..a830ead 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -60,6 +60,7 @@ struct text_entry {
 	} keysym;
 	uint32_t serial;
 	uint32_t content_purpose;
+	uint32_t click_to_show;
 };
 
 struct editor {
@@ -360,9 +361,18 @@ text_model_leave(void *data,
 
 	entry->active = 0;
 
+	text_model_hide_input_panel(text_model);
+
 	widget_schedule_redraw(entry->widget);
 }
 
+static void
+text_model_input_panel_state(void *data,
+			     struct text_model *text_model,
+			     uint32_t state)
+{
+}
+
 static const struct text_model_listener text_model_listener = {
 	text_model_commit_string,
 	text_model_preedit_string,
@@ -372,7 +382,8 @@ static const struct text_model_listener text_model_listener = {
 	text_model_modifiers_map,
 	text_model_keysym,
 	text_model_enter,
-	text_model_leave
+	text_model_leave,
+	text_model_input_panel_state
 };
 
 static struct text_entry*
@@ -468,6 +479,15 @@ 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);
+
+		return;
+	}
+
+	if (!entry->click_to_show)
+		text_model_show_input_panel(entry->model);
+
 	entry->serial++;
 
 	text_model_activate(entry->model,
@@ -997,6 +1017,12 @@ int
 main(int argc, char *argv[])
 {
 	struct editor editor;
+	int i;
+	uint32_t click_to_show = 0;
+
+	for (i = 1; i < argc; i++)
+		if (strcmp("--click-to-show", argv[i]) == 0)
+			click_to_show = 1;
 
 	memset(&editor, 0, sizeof editor);
 
@@ -1017,8 +1043,10 @@ main(int argc, char *argv[])
 	editor.widget = frame_create(editor.window, &editor);
 
 	editor.entry = text_entry_create(&editor, "Entry");
+	editor.entry->click_to_show = click_to_show;
 	editor.editor = text_entry_create(&editor, "Numeric");
 	editor.editor->content_purpose = TEXT_MODEL_CONTENT_PURPOSE_NUMBER;
+	editor.editor->click_to_show = click_to_show;
 
 	window_set_title(editor.window, "Text Editor");
 	window_set_key_handler(editor.window, key_handler);
diff --git a/protocol/text.xml b/protocol/text.xml
index 7fdbcf1..b20f00e 100644
--- a/protocol/text.xml
+++ b/protocol/text.xml
@@ -140,6 +140,16 @@
     </request>
     <request name="commit">
     </request>
+    <request name="show_input_panel">
+      <description summary="show input panels">
+        Requests input panels (virtual keyboard) to show.
+      </description>
+    </request>
+    <request name="hide_input_panel">
+      <description summary="hide input panels">
+        Requests input panels (virtual keyboard) to hide.
+      </description>
+    </request>
     <event name="commit_string">
       <description summary="commit">
         Notify when text should be inserted into the editor widget. The text
@@ -248,6 +258,12 @@
         destroyed.
       </description>
     </event>
+    <event name="input_panel_state">
+      <description summary="state of the input panel">
+        Notify when the visibility state of the input panel changed.
+      </description>
+      <arg name="state" type="uint"/>
+    </event>
   </interface>
 
   <interface name="text_model_factory" version="1">
diff --git a/src/shell.c b/src/shell.c
index a3363ab..6e0db35 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2798,6 +2798,9 @@ hide_input_panels(struct wl_listener *listener, void *data)
 			     hide_input_panel_listener);
 	struct weston_surface *surface, *next;
 
+	if (!shell->showing_input_panels)
+		return;
+
 	shell->showing_input_panels = false;
 
 	if (!shell->locked)
diff --git a/src/text-backend.c b/src/text-backend.c
index f096a9b..00ca46e 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -40,6 +40,8 @@ struct text_model {
 	struct wl_list input_methods;
 
 	struct wl_surface *surface;
+
+	uint32_t input_panel_visible;
 };
 
 struct text_model_factory {
@@ -183,7 +185,8 @@ text_model_activate(struct wl_client *client,
 
 	input_method_context_create(text_model, input_method, serial);
 
-	wl_signal_emit(&ec->show_input_panel_signal, ec);
+	if (text_model->input_panel_visible)
+		wl_signal_emit(&ec->show_input_panel_signal, ec);
 
 	text_model_send_enter(&text_model->resource, &text_model->surface->resource);
 }
@@ -271,6 +274,32 @@ text_model_commit(struct wl_client *client,
 	}
 }
 
+static void
+text_model_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;
+
+	text_model->input_panel_visible = 1;
+
+	if (!wl_list_empty(&text_model->input_methods))
+		wl_signal_emit(&ec->show_input_panel_signal, ec);
+}
+
+static void
+text_model_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;
+
+	text_model->input_panel_visible = 0;
+
+	if (!wl_list_empty(&text_model->input_methods))
+		wl_signal_emit(&ec->hide_input_panel_signal, ec);
+}
+
 static const struct text_model_interface text_model_implementation = {
 	text_model_set_surrounding_text,
 	text_model_activate,
@@ -279,7 +308,9 @@ static const struct text_model_interface text_model_implementation = {
 	text_model_set_micro_focus,
 	text_model_set_content_type,
 	text_model_invoke_action,
-	text_model_commit
+	text_model_commit,
+	text_model_show_input_panel,
+	text_model_hide_input_panel
 };
 
 static void text_model_factory_create_text_model(struct wl_client *client,
-- 
1.8.1



More information about the wayland-devel mailing list