[PATCH 09/15] text: Add get_keyboard to text_model

Jan Arne Petersen jpetersen at openismus.com
Sun Nov 4 18:26:47 PST 2012


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

Allows a client to listen to unfiltered key events when an input method
grabs the keyboard.

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 protocol/text.xml  |  4 ++++
 src/text-backend.c | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/protocol/text.xml b/protocol/text.xml
index 539fef9..918b1fb 100644
--- a/protocol/text.xml
+++ b/protocol/text.xml
@@ -82,6 +82,10 @@
     </request>
     <request name="set_preedit"/>
     <request name="set_content_type"/>
+    <request name="get_keyboard">
+      <arg name="seat" type="object" interface="wl_seat"/>
+      <arg name="id" type="new_id" interface="wl_keyboard"/>
+    </request>
 
     <event name="commit_string">
       <description summary="commit">
diff --git a/src/text-backend.c b/src/text-backend.c
index 5a002d6..81ab417 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -38,6 +38,8 @@ struct text_model {
 	struct wl_list input_methods;
 
 	struct wl_surface *surface;
+
+	struct wl_resource *keyboard;
 };
 
 struct text_model_factory {
@@ -229,6 +231,37 @@ text_model_set_content_type(struct wl_client *client,
 {
 }
 
+static void
+text_model_unbind_keyboard(struct wl_resource *resource)
+{
+	struct text_model *model = resource->data;
+
+	model->keyboard = NULL;
+
+	free(resource);
+}
+
+static void
+text_model_get_keyboard(struct wl_client *client,
+			struct wl_resource *resource,
+			struct wl_resource *seat,
+			uint32_t id)
+{
+	struct text_model *model = resource->data;
+	struct weston_seat *weston_seat = seat->data;
+	struct wl_resource *cr;
+
+	cr = wl_client_add_object(client, &wl_keyboard_interface,
+				  NULL, id, model);
+	cr->destroy = text_model_unbind_keyboard;
+
+	model->keyboard = cr;
+
+	wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
+				weston_seat->xkb_info.keymap_fd,
+				weston_seat->xkb_info.keymap_size);
+}
+
 static const struct text_model_interface text_model_implementation = {
 	text_model_set_surrounding_text,
 	text_model_activate,
@@ -236,7 +269,8 @@ static const struct text_model_interface text_model_implementation = {
 	text_model_reset,
 	text_model_set_micro_focus,
 	text_model_set_preedit,
-	text_model_set_content_type
+	text_model_set_content_type,
+	text_model_get_keyboard
 };
 
 static void text_model_factory_create_text_model(struct wl_client *client,
-- 
1.7.11.7



More information about the wayland-devel mailing list