2 * Copyright © 2012 Openismus GmbH
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "compositor.h"
26 #include "text-server-protocol.h"
31 struct wl_resource resource;
35 struct input_method *input_method;
39 struct wl_object base;
40 struct weston_compositor *ec;
41 struct wl_global *global;
42 struct wl_listener destroy_listener;
43 struct wl_list models;
45 struct text_model *active_model;
49 destroy_text_model(struct wl_resource *resource)
51 struct text_model *text_model = container_of(resource,
52 struct text_model, resource);
54 if (text_model->input_method->active_model == text_model) {
55 text_model->input_method->active_model = 0;
58 wl_list_remove(&text_model->link);
63 text_model_set_surrounding_text(struct wl_client *client,
64 struct wl_resource *resource,
70 text_model_set_cursor_index(struct wl_client *client,
71 struct wl_resource *resource,
77 text_model_activate(struct wl_client *client,
78 struct wl_resource *resource)
80 struct text_model *text_model = resource->data;
82 text_model->input_method->active_model = text_model;
84 wl_signal_emit(&text_model->input_method->ec->show_input_panel_signal, text_model->input_method->ec);
88 text_model_deactivate(struct wl_client *client,
89 struct wl_resource *resource)
91 struct text_model *text_model = resource->data;
93 if (text_model->input_method->active_model == text_model) {
94 text_model->input_method->active_model = NULL;
95 wl_signal_emit(&text_model->input_method->ec->hide_input_panel_signal, text_model->input_method->ec);
100 text_model_set_selected_text(struct wl_client *client,
101 struct wl_resource *resource,
108 text_model_set_micro_focus(struct wl_client *client,
109 struct wl_resource *resource,
118 text_model_set_preedit(struct wl_client *client,
119 struct wl_resource *resource)
124 text_model_set_content_type(struct wl_client *client,
125 struct wl_resource *resource)
129 struct text_model_interface text_model_implementation = {
130 text_model_set_surrounding_text,
131 text_model_set_cursor_index,
133 text_model_deactivate,
134 text_model_set_selected_text,
135 text_model_set_micro_focus,
136 text_model_set_preedit,
137 text_model_set_content_type
140 static void input_method_create_text_model(struct wl_client *client,
141 struct wl_resource *resource,
143 struct wl_resource *surface)
145 struct input_method *input_method = resource->data;
146 struct text_model *text_model;
148 text_model = malloc(sizeof *text_model);
150 text_model->resource.destroy = destroy_text_model;
152 text_model->resource.object.id = id;
153 text_model->resource.object.interface = &text_model_interface;
154 text_model->resource.object.implementation =
155 (void (**)(void)) &text_model_implementation;
156 text_model->resource.data = text_model;
158 text_model->input_method = input_method;
160 wl_client_add_resource(client, &text_model->resource);
162 wl_list_insert(&input_method->models, &text_model->link);
166 input_method_commit_string(struct wl_client *client,
167 struct wl_resource *resource,
171 struct input_method *input_method = resource->data;
173 if (input_method->active_model) {
174 text_model_send_commit_string(&input_method->active_model->resource, text, index);
178 struct input_method_interface input_method_implementation = {
179 input_method_create_text_model,
180 input_method_commit_string
184 bind_input_method(struct wl_client *client,
189 wl_client_add_object(client, &input_method_interface,
190 &input_method_implementation, id, data);
194 input_method_notifier_destroy(struct wl_listener *listener, void *data)
196 struct input_method *input_method = container_of(listener, struct input_method, destroy_listener);
198 wl_display_remove_global(input_method->ec->wl_display, input_method->global);
203 input_method_create(struct weston_compositor *ec)
205 struct input_method *input_method;
207 input_method = malloc(sizeof *input_method);
209 input_method->base.interface = &input_method_interface;
210 input_method->base.implementation = (void(**)(void)) &input_method_implementation;
211 input_method->ec = ec;
212 input_method->active_model = NULL;
214 wl_list_init(&input_method->models);
216 input_method->global = wl_display_add_global(ec->wl_display,
217 &input_method_interface,
218 input_method, bind_input_method);
220 input_method->destroy_listener.notify = input_method_notifier_destroy;
221 wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);