[PATCH 06/15] text: Start input method from configuration

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


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

Start the input method specified in the weston.ini configuration file.

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 src/compositor.c   |  2 +-
 src/compositor.h   |  4 +--
 src/text-backend.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 weston.ini         |  3 ++
 4 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 2d5b263..3c37d44 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2829,7 +2829,7 @@ weston_compositor_init(struct weston_compositor *ec,
 
 	screenshooter_create(ec);
 	text_cursor_position_notifier_create(ec);
-	text_model_factory_create(ec);
+	text_backend_init(ec);
 
 	wl_data_device_manager_init(ec->wl_display);
 
diff --git a/src/compositor.h b/src/compositor.h
index 121f6bf..538f7ee 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -773,8 +773,8 @@ clipboard_create(struct weston_seat *seat);
 void
 text_cursor_position_notifier_create(struct weston_compositor *ec);
 
-void
-text_model_factory_create(struct weston_compositor *ec);
+int
+text_backend_init(struct weston_compositor *ec);
 
 void
 input_method_create(struct weston_compositor *ec,
diff --git a/src/text-backend.c b/src/text-backend.c
index c480e4e..a3d796e 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -72,6 +72,18 @@ struct input_method_context {
 	struct wl_list link;
 };
 
+struct text_backend {
+	struct weston_compositor *compositor;
+
+	struct {
+		char *path;
+		struct wl_resource *binding;
+		struct weston_process process;
+	} input_method;
+};
+
+static struct text_backend *text_backend = 0;
+
 static void input_method_context_create(struct text_model *model,
 					struct input_method *input_method);
 
@@ -273,7 +285,7 @@ text_model_factory_notifier_destroy(struct wl_listener *listener, void *data)
 	free(text_model_factory);
 }
 
-WL_EXPORT void
+static void
 text_model_factory_create(struct weston_compositor *ec)
 {
 	struct text_model_factory *text_model_factory;
@@ -395,6 +407,8 @@ unbind_input_method(struct wl_resource *resource)
 	input_method->input_method_binding = NULL;
 	input_method->context = NULL;
 
+	text_backend->input_method.binding = NULL;
+
 	free(resource);
 }
 
@@ -414,6 +428,8 @@ bind_input_method(struct wl_client *client,
 	if (input_method->input_method_binding == NULL) {
 		resource->destroy = unbind_input_method;
 		input_method->input_method_binding = resource;
+
+		text_backend->input_method.binding = resource;
 		return;
 	}
 
@@ -467,6 +483,30 @@ input_method_init_seat(struct weston_seat *seat)
 	seat->input_method->focus_listener_initialized = 1;
 }
 
+static void
+handle_input_method_sigchld(struct weston_process *process, int status)
+{
+	process->pid = 0;
+}
+
+static void
+launch_input_method(struct text_backend *text_backend)
+{
+	if (text_backend->input_method.binding)
+		return;
+
+	if (!text_backend->input_method.path)
+		return;
+
+	if (text_backend->input_method.process.pid != 0)
+		return;
+
+	weston_client_launch(text_backend->compositor,
+			     &text_backend->input_method.process,
+			     text_backend->input_method.path,
+			     handle_input_method_sigchld);
+}
+
 WL_EXPORT void
 input_method_create(struct weston_compositor *ec,
 		    struct weston_seat *seat)
@@ -489,5 +529,43 @@ input_method_create(struct weston_compositor *ec,
 	wl_signal_add(&seat->seat.destroy_signal, &input_method->destroy_listener);
 
 	seat->input_method = input_method;
+
+	launch_input_method(text_backend);
+}
+
+static void
+text_backend_configuration(struct text_backend *text_backend)
+{
+	char *config_file;
+	char *path;
+
+	struct config_key input_method_keys[] = {
+		{ "path", CONFIG_KEY_STRING, &path }
+	};
+
+	struct config_section cs[] = {
+		{ "input-method", input_method_keys, ARRAY_LENGTH(input_method_keys), NULL }
+	};
+
+	config_file = config_file_path("weston.ini");
+	parse_config_file(config_file, cs, ARRAY_LENGTH(cs), text_backend);
+	free(config_file);
+
+	text_backend->input_method.path = path;
 }
 
+WL_EXPORT int
+text_backend_init(struct weston_compositor *ec)
+{
+/*	struct text_backend *text_backend; */
+
+	text_backend = calloc(1, sizeof(*text_backend));
+
+	text_backend->compositor = ec;
+
+	text_backend_configuration(text_backend);
+
+	text_model_factory_create(ec);
+
+	return 0;
+}
diff --git a/weston.ini b/weston.ini
index cb88eba..4cad83b 100644
--- a/weston.ini
+++ b/weston.ini
@@ -35,6 +35,9 @@ path=./clients/flower
 path=/usr/libexec/weston-screensaver
 duration=600
 
+[input-method]
+path=/usr/libexec/weston-keyboard
+
 #[output]
 #name=LVDS1
 #mode=1680x1050
-- 
1.7.11.7



More information about the wayland-devel mailing list