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)
52 if (text_model->input_method->active_model == text_model) {
53 text_model->input_method->active_model = NULL;
54 wl_signal_emit(&text_model->input_method->ec->hide_input_panel_signal, text_model->input_method->ec);
59 destroy_text_model(struct wl_resource *resource)
61 struct text_model *text_model = container_of(resource,
62 struct text_model, resource);
64 deactivate_text_model(text_model);
66 wl_list_remove(&text_model->link);
71 text_model_set_surrounding_text(struct wl_client *client,
72 struct wl_resource *resource,
78 text_model_set_cursor_index(struct wl_client *client,
79 struct wl_resource *resource,
85 text_model_activate(struct wl_client *client,
86 struct wl_resource *resource)
88 struct text_model *text_model = resource->data;
90 text_model->input_method->active_model = text_model;
92 wl_signal_emit(&text_model->input_method->ec->show_input_panel_signal, text_model->input_method->ec);
96 text_model_deactivate(struct wl_client *client,
97 struct wl_resource *resource)
99 struct text_model *text_model = resource->data;
101 deactivate_text_model(text_model);
105 text_model_set_selected_text(struct wl_client *client,
106 struct wl_resource *resource,
113 text_model_set_micro_focus(struct wl_client *client,
114 struct wl_resource *resource,
123 text_model_set_preedit(struct wl_client *client,
124 struct wl_resource *resource)
129 text_model_set_content_type(struct wl_client *client,
130 struct wl_resource *resource)
134 struct text_model_interface text_model_implementation = {
135 text_model_set_surrounding_text,
136 text_model_set_cursor_index,
138 text_model_deactivate,
139 text_model_set_selected_text,
140 text_model_set_micro_focus,
141 text_model_set_preedit,
142 text_model_set_content_type
145 static void input_method_create_text_model(struct wl_client *client,
146 struct wl_resource *resource,
148 struct wl_resource *surface)
150 struct input_method *input_method = resource->data;
151 struct text_model *text_model;
153 text_model = calloc(1, sizeof *text_model);
155 text_model->resource.destroy = destroy_text_model;
157 text_model->resource.object.id = id;
158 text_model->resource.object.interface = &text_model_interface;
159 text_model->resource.object.implementation =
160 (void (**)(void)) &text_model_implementation;
161 text_model->resource.data = text_model;
163 text_model->input_method = input_method;
165 wl_client_add_resource(client, &text_model->resource);
167 wl_list_insert(&input_method->models, &text_model->link);
171 input_method_commit_string(struct wl_client *client,
172 struct wl_resource *resource,
176 struct input_method *input_method = resource->data;
178 if (input_method->active_model) {
179 text_model_send_commit_string(&input_method->active_model->resource, text, index);
183 struct input_method_interface input_method_implementation = {
184 input_method_create_text_model,
185 input_method_commit_string
189 bind_input_method(struct wl_client *client,
194 wl_client_add_object(client, &input_method_interface,
195 &input_method_implementation, id, data);
199 input_method_notifier_destroy(struct wl_listener *listener, void *data)
201 struct input_method *input_method = container_of(listener, struct input_method, destroy_listener);
203 wl_display_remove_global(input_method->ec->wl_display, input_method->global);
208 input_method_create(struct weston_compositor *ec)
210 struct input_method *input_method;
212 input_method = calloc(1, sizeof *input_method);
214 input_method->base.interface = &input_method_interface;
215 input_method->base.implementation = (void(**)(void)) &input_method_implementation;
216 input_method->ec = ec;
217 input_method->active_model = NULL;
219 wl_list_init(&input_method->models);
221 input_method->global = wl_display_add_global(ec->wl_display,
222 &input_method_interface,
223 input_method, bind_input_method);
225 input_method->destroy_listener.notify = input_method_notifier_destroy;
226 wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);