[PATCH 06/15] text: Start input method from configuration
Kristian Høgsberg
hoegsberg at gmail.com
Thu Nov 8 12:58:38 PST 2012
On Mon, Nov 05, 2012 at 03:26:44AM +0100, Jan Arne Petersen wrote:
> 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;
Can we avoid this global variable here? All callbacks from the core
should give you a way to get back to your data and if not we should
fix that.
> +
> 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);
Let's handle errors here and at least use weston_log to log an error.
> +}
> +
> 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);
If the path key is not in the ini file, the path variable here is
uninitialized. Initialize path to NULL and if it's NULL after parsing
the config, set it to path = strdup(LIBEXECDIR "/weston-keyboard").
That way we have a default even without an ini 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;
You should install a compositor destroy listener here and clean up
when the compositor is destroyed. That will also give you a way to
get back to struct text_backend from the compositor struct
(wl_signal_get + container_of).
> +}
> 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
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list