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 deactivate_text_model(struct text_model *text_model)
51 struct weston_compositor *ec = text_model->input_method->ec;
53 if (text_model->input_method->active_model == text_model) {
54 text_model->input_method->active_model = NULL;
55 wl_signal_emit(&ec->hide_input_panel_signal, ec);
60 destroy_text_model(struct wl_resource *resource)
62 struct text_model *text_model =
63 container_of(resource, struct text_model, resource);
65 deactivate_text_model(text_model);
67 wl_list_remove(&text_model->link);
72 text_model_set_surrounding_text(struct wl_client *client,
73 struct wl_resource *resource,
79 text_model_set_cursor_index(struct wl_client *client,
80 struct wl_resource *resource,
86 text_model_activate(struct wl_client *client,
87 struct wl_resource *resource)
89 struct text_model *text_model = resource->data;
90 struct weston_compositor *ec = text_model->input_method->ec;
92 text_model->input_method->active_model = text_model;
94 wl_signal_emit(&ec->show_input_panel_signal, ec);
98 text_model_deactivate(struct wl_client *client,
99 struct wl_resource *resource)
101 struct text_model *text_model = resource->data;
103 deactivate_text_model(text_model);
107 text_model_set_selected_text(struct wl_client *client,
108 struct wl_resource *resource,
115 text_model_set_micro_focus(struct wl_client *client,
116 struct wl_resource *resource,
125 text_model_set_preedit(struct wl_client *client,
126 struct wl_resource *resource)
131 text_model_set_content_type(struct wl_client *client,
132 struct wl_resource *resource)
136 struct text_model_interface text_model_implementation = {
137 text_model_set_surrounding_text,
138 text_model_set_cursor_index,
140 text_model_deactivate,
141 text_model_set_selected_text,
142 text_model_set_micro_focus,
143 text_model_set_preedit,
144 text_model_set_content_type
147 static void input_method_create_text_model(struct wl_client *client,
148 struct wl_resource *resource,
150 struct wl_resource *surface)
152 struct input_method *input_method = resource->data;
153 struct text_model *text_model;
155 text_model = calloc(1, sizeof *text_model);
157 text_model->resource.destroy = destroy_text_model;
159 text_model->resource.object.id = id;
160 text_model->resource.object.interface = &text_model_interface;
161 text_model->resource.object.implementation =
162 (void (**)(void)) &text_model_implementation;
163 text_model->resource.data = text_model;
165 text_model->input_method = input_method;
167 wl_client_add_resource(client, &text_model->resource);
169 wl_list_insert(&input_method->models, &text_model->link);
173 input_method_commit_string(struct wl_client *client,
174 struct wl_resource *resource,
178 struct input_method *input_method = resource->data;
180 if (input_method->active_model) {
181 text_model_send_commit_string(&input_method->active_model->resource, text, index);
185 struct input_method_interface input_method_implementation = {
186 input_method_create_text_model,
187 input_method_commit_string
191 bind_input_method(struct wl_client *client,
196 wl_client_add_object(client, &input_method_interface,
197 &input_method_implementation, id, data);
201 input_method_notifier_destroy(struct wl_listener *listener, void *data)
203 struct input_method *input_method =
204 container_of(listener, struct input_method, destroy_listener);
206 wl_display_remove_global(input_method->ec->wl_display,
207 input_method->global);
212 input_method_create(struct weston_compositor *ec)
214 struct input_method *input_method;
216 input_method = calloc(1, sizeof *input_method);
218 input_method->base.interface = &input_method_interface;
219 input_method->base.implementation =
220 (void(**)(void)) &input_method_implementation;
221 input_method->ec = ec;
222 input_method->active_model = NULL;
224 wl_list_init(&input_method->models);
226 input_method->global = wl_display_add_global(ec->wl_display,
227 &input_method_interface,
231 input_method->destroy_listener.notify = input_method_notifier_destroy;
232 wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);