2012-06-21 23:52:18 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Openismus GmbH
|
2012-09-10 01:08:30 +04:00
|
|
|
* Copyright © 2012 Intel Corporation
|
2012-06-21 23:52:18 +04:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-11-18 22:06:42 +04:00
|
|
|
#include <string.h>
|
2012-06-21 23:52:18 +04:00
|
|
|
|
|
|
|
#include "compositor.h"
|
|
|
|
#include "text-server-protocol.h"
|
2012-09-10 01:08:41 +04:00
|
|
|
#include "input-method-server-protocol.h"
|
2012-06-21 23:52:18 +04:00
|
|
|
|
|
|
|
struct input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
struct input_method_context;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input {
|
2012-06-21 23:52:18 +04:00
|
|
|
struct wl_resource resource;
|
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
struct weston_compositor *ec;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_list input_methods;
|
2012-08-10 18:47:23 +04:00
|
|
|
|
|
|
|
struct wl_surface *surface;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:28 +04:00
|
|
|
pixman_box32_t cursor_rectangle;
|
|
|
|
|
2013-01-31 18:52:21 +04:00
|
|
|
uint32_t input_panel_visible;
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager {
|
|
|
|
struct wl_global *text_input_manager_global;
|
2012-09-10 01:08:31 +04:00
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
|
|
|
|
struct weston_compositor *ec;
|
|
|
|
};
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
struct input_method {
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *input_method_binding;
|
|
|
|
struct wl_global *input_method_global;
|
2012-06-21 23:52:18 +04:00
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
struct weston_seat *seat;
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *model;
|
2012-08-10 18:47:22 +04:00
|
|
|
|
|
|
|
struct wl_list link;
|
2012-08-10 18:47:23 +04:00
|
|
|
|
|
|
|
struct wl_listener keyboard_focus_listener;
|
|
|
|
|
|
|
|
int focus_listener_initialized;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
|
|
struct input_method_context *context;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
struct text_backend *text_backend;
|
2012-09-10 01:08:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct input_method_context {
|
|
|
|
struct wl_resource resource;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *model;
|
2012-11-18 22:06:45 +04:00
|
|
|
struct input_method *input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
|
|
struct wl_list link;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
|
|
|
struct wl_resource *keyboard;
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend {
|
|
|
|
struct weston_compositor *compositor;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *path;
|
|
|
|
struct wl_resource *binding;
|
|
|
|
struct weston_process process;
|
|
|
|
struct wl_client *client;
|
|
|
|
} input_method;
|
|
|
|
|
|
|
|
struct wl_listener seat_created_listener;
|
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
static void input_method_context_create(struct text_input *model,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct input_method *input_method);
|
2012-11-18 22:06:45 +04:00
|
|
|
static void input_method_context_end_keyboard_grab(struct input_method_context *context);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2012-08-10 18:47:23 +04:00
|
|
|
static void input_method_init_seat(struct weston_seat *seat);
|
|
|
|
|
2012-07-12 00:25:30 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
deactivate_text_input(struct text_input *text_input,
|
2012-08-10 18:47:22 +04:00
|
|
|
struct input_method *input_method)
|
2012-07-12 00:25:30 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2012-07-12 00:25:30 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
if (input_method->model == text_input) {
|
2012-11-18 22:06:45 +04:00
|
|
|
if (input_method->context && input_method->input_method_binding) {
|
|
|
|
input_method_context_end_keyboard_grab(input_method->context);
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_send_deactivate(input_method->input_method_binding,
|
|
|
|
&input_method->context->resource);
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
wl_list_remove(&input_method->link);
|
|
|
|
input_method->model = NULL;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = NULL;
|
2012-07-22 19:51:42 +04:00
|
|
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_leave(&text_input->resource);
|
2012-07-12 00:25:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
destroy_text_input(struct wl_resource *resource)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input =
|
|
|
|
container_of(resource, struct text_input, resource);
|
2012-08-10 18:47:22 +04:00
|
|
|
struct input_method *input_method, *next;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link)
|
|
|
|
deactivate_text_input(text_input, input_method);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
free(text_input);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_surrounding_text(struct wl_client *client,
|
2012-06-21 23:52:18 +04:00
|
|
|
struct wl_resource *resource,
|
2012-09-10 01:08:40 +04:00
|
|
|
const char *text,
|
|
|
|
uint32_t cursor,
|
|
|
|
uint32_t anchor)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2012-09-10 01:08:32 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2012-09-10 01:08:32 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_surrounding_text(&input_method->context->resource,
|
|
|
|
text,
|
|
|
|
cursor,
|
|
|
|
anchor);
|
2012-09-10 01:08:32 +04:00
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_activate(struct wl_client *client,
|
2013-04-18 18:47:39 +04:00
|
|
|
struct wl_resource *resource,
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_resource *seat,
|
|
|
|
struct wl_resource *surface)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2012-08-10 18:47:22 +04:00
|
|
|
struct weston_seat *weston_seat = seat->data;
|
2012-09-10 01:08:32 +04:00
|
|
|
struct input_method *input_method = weston_seat->input_method;
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *old = weston_seat->input_method->model;
|
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
if (old == text_input)
|
2012-08-10 18:47:22 +04:00
|
|
|
return;
|
2012-08-10 18:47:21 +04:00
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
if (old) {
|
2013-04-18 18:47:24 +04:00
|
|
|
deactivate_text_input(old,
|
2012-08-10 18:47:22 +04:00
|
|
|
weston_seat->input_method);
|
2012-08-10 18:47:21 +04:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
input_method->model = text_input;
|
|
|
|
wl_list_insert(&text_input->input_methods, &input_method->link);
|
2012-08-10 18:47:23 +04:00
|
|
|
input_method_init_seat(weston_seat);
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->surface = surface->data;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:33 +04:00
|
|
|
input_method_context_create(text_input, input_method);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2013-04-18 18:47:28 +04:00
|
|
|
if (text_input->input_panel_visible) {
|
|
|
|
wl_signal_emit(&ec->show_input_panel_signal, text_input->surface);
|
|
|
|
wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle);
|
|
|
|
}
|
2012-08-10 18:47:21 +04:00
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_enter(&text_input->resource, &text_input->surface->resource);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_deactivate(struct wl_client *client,
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *seat)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2012-08-10 18:47:22 +04:00
|
|
|
struct weston_seat *weston_seat = seat->data;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
deactivate_text_input(text_input,
|
2012-08-10 18:47:22 +04:00
|
|
|
weston_seat->input_method);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:46 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_reset(struct wl_client *client,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct wl_resource *resource)
|
2012-09-10 01:08:46 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2012-09-10 01:08:46 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2012-09-10 01:08:46 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_reset(&input_method->context->resource);
|
2012-09-10 01:08:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_cursor_rectangle(struct wl_client *client,
|
2013-04-18 18:47:23 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:28 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
|
|
|
struct weston_compositor *ec = text_input->ec;
|
|
|
|
|
|
|
|
text_input->cursor_rectangle.x1 = x;
|
|
|
|
text_input->cursor_rectangle.y1 = y;
|
|
|
|
text_input->cursor_rectangle.x2 = x + width;
|
|
|
|
text_input->cursor_rectangle.y2 = y + height;
|
|
|
|
|
|
|
|
wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_content_type(struct wl_client *client,
|
2013-01-17 00:26:43 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t hint,
|
|
|
|
uint32_t purpose)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2013-01-17 00:26:43 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2013-01-17 00:26:43 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_content_type(&input_method->context->resource, hint, purpose);
|
2013-01-17 00:26:43 +04:00
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2013-01-17 00:26:46 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_invoke_action(struct wl_client *client,
|
2013-01-17 00:26:46 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t button,
|
|
|
|
uint32_t index)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2013-01-17 00:26:46 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2013-01-17 00:26:46 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_invoke_action(&input_method->context->resource, button, index);
|
2013-01-17 00:26:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:20 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_commit_state(struct wl_client *client,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial)
|
2013-01-31 18:52:20 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2013-01-31 18:52:20 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2013-01-31 18:52:20 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_commit_state(&input_method->context->resource, serial);
|
2013-01-31 18:52:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:21 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_show_input_panel(struct wl_client *client,
|
2013-01-31 18:52:21 +04:00
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->input_panel_visible = 1;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:28 +04:00
|
|
|
if (!wl_list_empty(&text_input->input_methods)) {
|
|
|
|
wl_signal_emit(&ec->show_input_panel_signal, text_input->surface);
|
|
|
|
wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle);
|
|
|
|
}
|
2013-01-31 18:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_hide_input_panel(struct wl_client *client,
|
2013-01-31 18:52:21 +04:00
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->input_panel_visible = 0;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
if (!wl_list_empty(&text_input->input_methods))
|
2013-01-31 18:52:21 +04:00
|
|
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_preferred_language(struct wl_client *client,
|
2013-04-18 18:47:15 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *language)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input = resource->data;
|
2013-04-18 18:47:15 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
|
2013-04-18 18:47:15 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_context_send_preferred_language(&input_method->context->resource,
|
|
|
|
language);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
static const struct wl_text_input_interface text_input_implementation = {
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_activate,
|
|
|
|
text_input_deactivate,
|
|
|
|
text_input_show_input_panel,
|
|
|
|
text_input_hide_input_panel,
|
|
|
|
text_input_reset,
|
|
|
|
text_input_set_surrounding_text,
|
|
|
|
text_input_set_content_type,
|
|
|
|
text_input_set_cursor_rectangle,
|
|
|
|
text_input_set_preferred_language,
|
|
|
|
text_input_commit_state,
|
|
|
|
text_input_invoke_action
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
static void text_input_manager_create_text_input(struct wl_client *client,
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *resource,
|
2012-09-10 01:08:30 +04:00
|
|
|
uint32_t id)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager = resource->data;
|
|
|
|
struct text_input *text_input;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input = calloc(1, sizeof *text_input);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->resource.object.id = id;
|
2013-04-18 18:47:36 +04:00
|
|
|
text_input->resource.object.interface = &wl_text_input_interface;
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->resource.object.implementation =
|
|
|
|
(void (**)(void)) &text_input_implementation;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->resource.data = text_input;
|
|
|
|
text_input->resource.destroy = destroy_text_input;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->ec = text_input_manager->ec;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_init(&text_input->input_methods);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_client_add_resource(client, &text_input->resource);
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
static const struct wl_text_input_manager_interface text_input_manager_implementation = {
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create_text_input
|
2012-07-12 00:25:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
bind_text_input_manager(struct wl_client *client,
|
2012-07-12 00:25:31 +04:00
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager = data;
|
2012-07-12 00:25:31 +04:00
|
|
|
|
|
|
|
/* No checking for duplicate binding necessary.
|
|
|
|
* No events have to be sent, so we don't need the return value. */
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_client_add_object(client, &wl_text_input_manager_interface,
|
2013-04-18 18:47:24 +04:00
|
|
|
&text_input_manager_implementation,
|
|
|
|
id, text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_notifier_destroy(struct wl_listener *listener, void *data)
|
2012-09-10 01:08:31 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager =
|
|
|
|
container_of(listener, struct text_input_manager, destroy_listener);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_display_remove_global(text_input_manager->ec->wl_display,
|
|
|
|
text_input_manager->text_input_manager_global);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
free(text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create(struct weston_compositor *ec)
|
2012-09-10 01:08:31 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager = calloc(1, sizeof *text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager->ec = ec;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager->text_input_manager_global =
|
2012-09-10 01:08:31 +04:00
|
|
|
wl_display_add_global(ec->wl_display,
|
2013-04-18 18:47:36 +04:00
|
|
|
&wl_text_input_manager_interface,
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager, bind_text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy;
|
|
|
|
wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener);
|
2012-07-12 00:25:31 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method_context_destroy(struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2012-09-10 01:08:32 +04:00
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
static void
|
|
|
|
input_method_context_commit_string(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
2013-01-17 00:26:39 +04:00
|
|
|
uint32_t serial,
|
2013-01-31 18:52:23 +04:00
|
|
|
const char *text)
|
2012-09-10 01:08:32 +04:00
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_commit_string(&context->model->resource, serial, text);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:43 +04:00
|
|
|
static void
|
|
|
|
input_method_context_preedit_string(struct wl_client *client,
|
2013-01-17 00:26:38 +04:00
|
|
|
struct wl_resource *resource,
|
2013-01-17 00:26:39 +04:00
|
|
|
uint32_t serial,
|
2013-01-17 00:26:38 +04:00
|
|
|
const char *text,
|
|
|
|
const char *commit)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_preedit_string(&context->model->resource, serial, text, commit);
|
2013-01-17 00:26:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_preedit_styling(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t index,
|
|
|
|
uint32_t length,
|
|
|
|
uint32_t style)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_preedit_styling(&context->model->resource, index, length, style);
|
2013-01-17 00:26:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_preedit_cursor(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t cursor)
|
2012-09-10 01:08:43 +04:00
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_preedit_cursor(&context->model->resource, cursor);
|
2012-09-10 01:08:43 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:44 +04:00
|
|
|
static void
|
|
|
|
input_method_context_delete_surrounding_text(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t index,
|
|
|
|
uint32_t length)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_delete_surrounding_text(&context->model->resource, index, length);
|
2012-09-10 01:08:44 +04:00
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:23 +04:00
|
|
|
static void
|
|
|
|
input_method_context_cursor_position(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t index,
|
|
|
|
int32_t anchor)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_cursor_position(&context->model->resource, index, anchor);
|
2013-01-31 18:52:23 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:45 +04:00
|
|
|
static void
|
2012-11-18 22:06:43 +04:00
|
|
|
input_method_context_modifiers_map(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_array *map)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_modifiers_map(&context->model->resource, map);
|
2012-11-18 22:06:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_keysym(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t sym,
|
|
|
|
uint32_t state,
|
|
|
|
uint32_t modifiers)
|
2012-09-10 01:08:45 +04:00
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_keysym(&context->model->resource, serial, time,
|
2013-04-18 18:47:39 +04:00
|
|
|
sym, state, modifiers);
|
2012-09-10 01:08:45 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
static void
|
|
|
|
unbind_keyboard(struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
|
|
|
input_method_context_end_keyboard_grab(context);
|
|
|
|
context->keyboard = NULL;
|
|
|
|
|
|
|
|
free(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 23:25:39 +04:00
|
|
|
input_method_context_grab_key(struct weston_keyboard_grab *grab,
|
2012-11-18 22:06:45 +04:00
|
|
|
uint32_t time, uint32_t key, uint32_t state_w)
|
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
2013-01-17 00:26:50 +04:00
|
|
|
struct wl_display *display;
|
2012-11-18 22:06:45 +04:00
|
|
|
uint32_t serial;
|
2013-01-17 00:26:50 +04:00
|
|
|
|
|
|
|
if (!keyboard->input_method_resource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
display = wl_client_get_display(keyboard->input_method_resource->client);
|
|
|
|
serial = wl_display_next_serial(display);
|
|
|
|
wl_keyboard_send_key(keyboard->input_method_resource,
|
|
|
|
serial, time, key, state_w);
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 23:25:39 +04:00
|
|
|
input_method_context_grab_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
|
2012-11-18 22:06:45 +04:00
|
|
|
uint32_t mods_depressed, uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked, uint32_t group)
|
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
if (!keyboard->input_method_resource)
|
2012-11-18 22:06:45 +04:00
|
|
|
return;
|
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
wl_keyboard_send_modifiers(keyboard->input_method_resource,
|
2012-11-18 22:06:45 +04:00
|
|
|
serial, mods_depressed, mods_latched,
|
|
|
|
mods_locked, group);
|
|
|
|
}
|
|
|
|
|
2013-04-18 23:25:39 +04:00
|
|
|
static const struct weston_keyboard_grab_interface input_method_context_grab = {
|
2012-11-18 22:06:45 +04:00
|
|
|
input_method_context_grab_key,
|
|
|
|
input_method_context_grab_modifier,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_grab_keyboard(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
struct wl_resource *cr;
|
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2013-01-17 00:26:50 +04:00
|
|
|
struct weston_keyboard *keyboard = &seat->keyboard;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
|
|
|
cr = wl_client_add_object(client, &wl_keyboard_interface,
|
|
|
|
NULL, id, context);
|
|
|
|
cr->destroy = unbind_keyboard;
|
|
|
|
|
|
|
|
context->keyboard = cr;
|
|
|
|
|
|
|
|
wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
|
|
|
|
seat->xkb_info.keymap_fd,
|
|
|
|
seat->xkb_info.keymap_size);
|
|
|
|
|
2013-04-18 23:25:39 +04:00
|
|
|
if (keyboard->grab != &keyboard->default_grab) {
|
|
|
|
weston_keyboard_end_grab(keyboard);
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
2013-04-18 23:25:39 +04:00
|
|
|
weston_keyboard_start_grab(keyboard, &keyboard->input_method_grab);
|
2013-01-17 00:26:50 +04:00
|
|
|
keyboard->input_method_resource = cr;
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:46 +04:00
|
|
|
static void
|
|
|
|
input_method_context_key(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t key,
|
|
|
|
uint32_t state_w)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = seat->seat.keyboard;
|
|
|
|
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
|
2012-11-18 22:06:46 +04:00
|
|
|
|
|
|
|
default_grab->interface->key(default_grab, time, key, state_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_modifiers(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = seat->seat.keyboard;
|
|
|
|
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
|
2012-11-18 22:06:46 +04:00
|
|
|
|
|
|
|
default_grab->interface->modifiers(default_grab,
|
|
|
|
serial, mods_depressed,
|
|
|
|
mods_latched, mods_locked,
|
|
|
|
group);
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
static void
|
|
|
|
input_method_context_language(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
const char *language)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_language(&context->model->resource, serial, language);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_text_direction(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t direction)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2013-04-18 18:47:36 +04:00
|
|
|
wl_text_input_send_text_direction(&context->model->resource, serial, direction);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-18 18:47:39 +04:00
|
|
|
static const struct wl_input_method_context_interface input_method_context_implementation = {
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method_context_destroy,
|
2012-09-10 01:08:43 +04:00
|
|
|
input_method_context_commit_string,
|
|
|
|
input_method_context_preedit_string,
|
2013-01-17 00:26:38 +04:00
|
|
|
input_method_context_preedit_styling,
|
|
|
|
input_method_context_preedit_cursor,
|
2012-09-10 01:08:45 +04:00
|
|
|
input_method_context_delete_surrounding_text,
|
2013-01-31 18:52:23 +04:00
|
|
|
input_method_context_cursor_position,
|
2012-11-18 22:06:43 +04:00
|
|
|
input_method_context_modifiers_map,
|
2012-11-18 22:06:45 +04:00
|
|
|
input_method_context_keysym,
|
2012-11-18 22:06:46 +04:00
|
|
|
input_method_context_grab_keyboard,
|
|
|
|
input_method_context_key,
|
2013-04-18 18:47:15 +04:00
|
|
|
input_method_context_modifiers,
|
|
|
|
input_method_context_language,
|
|
|
|
input_method_context_text_direction
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
static void
|
|
|
|
destroy_input_method_context(struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct input_method_context *context = resource->data;
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
if (context->keyboard) {
|
|
|
|
wl_resource_destroy(context->keyboard);
|
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
input_method_context_create(struct text_input *model,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct input_method *input_method)
|
2012-09-10 01:08:32 +04:00
|
|
|
{
|
|
|
|
struct input_method_context *context;
|
|
|
|
|
|
|
|
if (!input_method->input_method_binding)
|
|
|
|
return;
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
context = calloc(1, sizeof *context);
|
2012-09-10 01:08:32 +04:00
|
|
|
if (context == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context->resource.destroy = destroy_input_method_context;
|
|
|
|
context->resource.object.id = 0;
|
2013-04-18 18:47:39 +04:00
|
|
|
context->resource.object.interface = &wl_input_method_context_interface;
|
2012-09-10 01:08:32 +04:00
|
|
|
context->resource.object.implementation =
|
|
|
|
(void (**)(void)) &input_method_context_implementation;
|
|
|
|
context->resource.data = context;
|
|
|
|
wl_signal_init(&context->resource.destroy_signal);
|
|
|
|
|
|
|
|
context->model = model;
|
2012-11-18 22:06:45 +04:00
|
|
|
context->input_method = input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = context;
|
|
|
|
|
|
|
|
wl_client_add_resource(input_method->input_method_binding->client, &context->resource);
|
|
|
|
|
2013-04-18 18:47:39 +04:00
|
|
|
wl_input_method_send_activate(input_method->input_method_binding, &context->resource);
|
2012-09-10 01:08:32 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
static void
|
|
|
|
input_method_context_end_keyboard_grab(struct input_method_context *context)
|
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard_grab *grab = &context->input_method->seat->keyboard.input_method_grab;
|
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
if (!grab->keyboard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (grab->keyboard->grab == grab)
|
2013-04-18 23:25:39 +04:00
|
|
|
weston_keyboard_end_grab(grab->keyboard);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
keyboard->input_method_resource = NULL;
|
|
|
|
}
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
static void
|
|
|
|
unbind_input_method(struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct input_method *input_method = resource->data;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend *text_backend = input_method->text_backend;
|
2012-07-12 00:25:31 +04:00
|
|
|
|
|
|
|
input_method->input_method_binding = NULL;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = NULL;
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
text_backend->input_method.binding = NULL;
|
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
free(resource);
|
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
|
|
|
bind_input_method(struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2012-07-12 00:25:31 +04:00
|
|
|
struct input_method *input_method = data;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend *text_backend = input_method->text_backend;
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-04-18 18:47:39 +04:00
|
|
|
resource = wl_client_add_object(client, &wl_input_method_interface,
|
2012-09-10 01:08:32 +04:00
|
|
|
NULL,
|
2012-07-12 00:25:31 +04:00
|
|
|
id, input_method);
|
|
|
|
|
2013-04-18 18:47:31 +04:00
|
|
|
if (input_method->input_method_binding != NULL) {
|
|
|
|
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"interface object already bound");
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2013-04-18 18:47:31 +04:00
|
|
|
if (text_backend->input_method.client != client) {
|
|
|
|
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"permission to bind desktop_shell denied");
|
|
|
|
wl_resource_destroy(resource);
|
2012-07-12 00:25:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:31 +04:00
|
|
|
resource->destroy = unbind_input_method;
|
|
|
|
input_method->input_method_binding = resource;
|
|
|
|
|
|
|
|
text_backend->input_method.binding = resource;
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_notifier_destroy(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2012-07-22 19:51:42 +04:00
|
|
|
struct input_method *input_method =
|
|
|
|
container_of(listener, struct input_method, destroy_listener);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
if (input_method->model)
|
2013-04-18 18:47:24 +04:00
|
|
|
deactivate_text_input(input_method->model, input_method);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
|
|
|
wl_display_remove_global(input_method->seat->compositor->wl_display,
|
2012-07-12 00:25:31 +04:00
|
|
|
input_method->input_method_global);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
free(input_method);
|
|
|
|
}
|
|
|
|
|
2012-08-10 18:47:23 +04:00
|
|
|
static void
|
|
|
|
handle_keyboard_focus(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = data;
|
2012-08-10 18:47:23 +04:00
|
|
|
struct input_method *input_method =
|
|
|
|
container_of(listener, struct input_method, keyboard_focus_listener);
|
|
|
|
struct wl_surface *surface = keyboard->focus;
|
|
|
|
|
|
|
|
if (!input_method->model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!surface || input_method->model->surface != surface)
|
2013-04-18 18:47:24 +04:00
|
|
|
deactivate_text_input(input_method->model,
|
2012-08-10 18:47:23 +04:00
|
|
|
input_method);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_init_seat(struct weston_seat *seat)
|
|
|
|
{
|
|
|
|
if (seat->input_method->focus_listener_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (seat->has_keyboard) {
|
|
|
|
seat->input_method->keyboard_focus_listener.notify = handle_keyboard_focus;
|
|
|
|
wl_signal_add(&seat->seat.keyboard->focus_signal, &seat->input_method->keyboard_focus_listener);
|
2013-01-17 00:26:50 +04:00
|
|
|
seat->keyboard.input_method_grab.interface = &input_method_context_grab;
|
2012-08-10 18:47:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
seat->input_method->focus_listener_initialized = 1;
|
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
|
|
|
handle_input_method_sigchld(struct weston_process *process, int status)
|
|
|
|
{
|
|
|
|
struct text_backend *text_backend =
|
|
|
|
container_of(process, struct text_backend, input_method.process);
|
|
|
|
|
|
|
|
text_backend->input_method.process.pid = 0;
|
|
|
|
text_backend->input_method.client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
text_backend->input_method.client = weston_client_launch(text_backend->compositor,
|
2013-04-18 18:47:39 +04:00
|
|
|
&text_backend->input_method.process,
|
|
|
|
text_backend->input_method.path,
|
|
|
|
handle_input_method_sigchld);
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
if (!text_backend->input_method.client)
|
|
|
|
weston_log("not able to start %s\n", text_backend->input_method.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_seat_created(struct wl_listener *listener,
|
|
|
|
void *data)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2012-11-18 22:06:42 +04:00
|
|
|
struct weston_seat *seat = data;
|
|
|
|
struct text_backend *text_backend =
|
|
|
|
container_of(listener, struct text_backend,
|
|
|
|
seat_created_listener);
|
2012-06-21 23:52:18 +04:00
|
|
|
struct input_method *input_method;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct weston_compositor *ec = seat->compositor;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-07-12 00:25:30 +04:00
|
|
|
input_method = calloc(1, sizeof *input_method);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
input_method->seat = seat;
|
2012-08-10 18:47:22 +04:00
|
|
|
input_method->model = NULL;
|
2012-08-10 18:47:23 +04:00
|
|
|
input_method->focus_listener_initialized = 0;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = NULL;
|
2012-11-18 22:06:42 +04:00
|
|
|
input_method->text_backend = text_backend;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
input_method->input_method_global =
|
|
|
|
wl_display_add_global(ec->wl_display,
|
2013-04-18 18:47:39 +04:00
|
|
|
&wl_input_method_interface,
|
2012-07-12 00:25:31 +04:00
|
|
|
input_method, bind_input_method);
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
input_method->destroy_listener.notify = input_method_notifier_destroy;
|
2012-09-10 01:08:31 +04:00
|
|
|
wl_signal_add(&seat->seat.destroy_signal, &input_method->destroy_listener);
|
2012-08-10 18:47:22 +04:00
|
|
|
|
|
|
|
seat->input_method = input_method;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
launch_input_method(text_backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_backend_configuration(struct text_backend *text_backend)
|
|
|
|
{
|
|
|
|
char *config_file;
|
|
|
|
char *path = NULL;
|
|
|
|
|
|
|
|
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 (path)
|
|
|
|
text_backend->input_method.path = path;
|
|
|
|
else
|
|
|
|
text_backend->input_method.path = strdup(LIBEXECDIR "/weston-keyboard");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_backend_notifier_destroy(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct text_backend *text_backend =
|
|
|
|
container_of(listener, struct text_backend, destroy_listener);
|
|
|
|
|
|
|
|
if (text_backend->input_method.client)
|
|
|
|
wl_client_destroy(text_backend->input_method.client);
|
|
|
|
|
|
|
|
free(text_backend->input_method.path);
|
|
|
|
|
|
|
|
free(text_backend);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
2012-08-10 18:47:23 +04:00
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
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->seat_created_listener.notify = handle_seat_created;
|
|
|
|
wl_signal_add(&ec->seat_created_signal,
|
|
|
|
&text_backend->seat_created_listener);
|
|
|
|
|
|
|
|
text_backend->destroy_listener.notify = text_backend_notifier_destroy;
|
|
|
|
wl_signal_add(&ec->destroy_signal, &text_backend->destroy_listener);
|
|
|
|
|
|
|
|
text_backend_configuration(text_backend);
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create(ec);
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|