Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Openismus GmbH |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 3 | * Copyright © 2012 Intel Corporation |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
| 14 | * |
| 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 25 | #include <string.h> |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 26 | |
| 27 | #include "compositor.h" |
| 28 | #include "text-server-protocol.h" |
Jan Arne Petersen | 30b66ef | 2012-09-09 23:08:41 +0200 | [diff] [blame] | 29 | #include "input-method-server-protocol.h" |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 30 | |
| 31 | struct input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 32 | struct input_method_context; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 33 | struct text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 34 | |
| 35 | struct text_model { |
| 36 | struct wl_resource resource; |
| 37 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 38 | struct weston_compositor *ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 39 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 40 | struct wl_list input_methods; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 41 | |
| 42 | struct wl_surface *surface; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 45 | struct text_model_factory { |
Jan Arne Petersen | 5196374 | 2012-08-10 16:47:20 +0200 | [diff] [blame] | 46 | struct wl_global *text_model_factory_global; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 47 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 48 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 49 | struct weston_compositor *ec; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct input_method { |
| 53 | struct wl_resource *input_method_binding; |
| 54 | struct wl_global *input_method_global; |
| 55 | struct wl_listener destroy_listener; |
| 56 | |
| 57 | struct weston_seat *seat; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 58 | struct text_model *model; |
| 59 | |
| 60 | struct wl_list link; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 61 | |
| 62 | struct wl_listener keyboard_focus_listener; |
| 63 | |
| 64 | int focus_listener_initialized; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 65 | |
| 66 | struct input_method_context *context; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 67 | |
| 68 | struct text_backend *text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 71 | struct input_method_context { |
| 72 | struct wl_resource resource; |
| 73 | |
| 74 | struct text_model *model; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 75 | struct input_method *input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 76 | |
| 77 | struct wl_list link; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 78 | |
| 79 | struct wl_resource *keyboard; |
| 80 | struct wl_keyboard_grab grab; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 83 | struct text_backend { |
| 84 | struct weston_compositor *compositor; |
| 85 | |
| 86 | struct { |
| 87 | char *path; |
| 88 | struct wl_resource *binding; |
| 89 | struct weston_process process; |
| 90 | struct wl_client *client; |
| 91 | } input_method; |
| 92 | |
| 93 | struct wl_listener seat_created_listener; |
| 94 | struct wl_listener destroy_listener; |
| 95 | }; |
| 96 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 97 | static void input_method_context_create(struct text_model *model, |
| 98 | struct input_method *input_method); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 99 | static void input_method_context_end_keyboard_grab(struct input_method_context *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 100 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 101 | static void input_method_init_seat(struct weston_seat *seat); |
| 102 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 103 | static void |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 104 | deactivate_text_model(struct text_model *text_model, |
| 105 | struct input_method *input_method) |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 106 | { |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 107 | struct weston_compositor *ec = text_model->ec; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 108 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 109 | if (input_method->model == text_model) { |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 110 | if (input_method->context && input_method->input_method_binding) { |
| 111 | input_method_context_end_keyboard_grab(input_method->context); |
| 112 | input_method_send_deactivate(input_method->input_method_binding, |
| 113 | &input_method->context->resource); |
| 114 | } |
| 115 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 116 | wl_list_remove(&input_method->link); |
| 117 | input_method->model = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 118 | input_method->context = NULL; |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 119 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
Jan Arne Petersen | 680275f | 2012-09-24 14:51:14 +0200 | [diff] [blame] | 120 | text_model_send_leave(&text_model->resource); |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 125 | destroy_text_model(struct wl_resource *resource) |
| 126 | { |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 127 | struct text_model *text_model = |
| 128 | container_of(resource, struct text_model, resource); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 129 | struct input_method *input_method, *next; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 130 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 131 | wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) |
| 132 | deactivate_text_model(text_model, input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 133 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 134 | free(text_model); |
| 135 | } |
| 136 | |
| 137 | static void |
| 138 | text_model_set_surrounding_text(struct wl_client *client, |
| 139 | struct wl_resource *resource, |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 140 | const char *text, |
| 141 | uint32_t cursor, |
| 142 | uint32_t anchor) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 143 | { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 144 | struct text_model *text_model = resource->data; |
| 145 | struct input_method *input_method, *next; |
| 146 | |
| 147 | wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { |
| 148 | if (!input_method->context) |
| 149 | continue; |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 150 | input_method_context_send_surrounding_text(&input_method->context->resource, |
| 151 | text, |
| 152 | cursor, |
| 153 | anchor); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 154 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 158 | text_model_activate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 159 | struct wl_resource *resource, |
| 160 | struct wl_resource *seat, |
| 161 | struct wl_resource *surface) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 162 | { |
| 163 | struct text_model *text_model = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 164 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 165 | struct input_method *input_method = weston_seat->input_method; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 166 | struct text_model *old = weston_seat->input_method->model; |
| 167 | struct weston_compositor *ec = text_model->ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 168 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 169 | if (old == text_model) |
| 170 | return; |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 171 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 172 | if (old) { |
| 173 | deactivate_text_model(old, |
| 174 | weston_seat->input_method); |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 177 | input_method->model = text_model; |
| 178 | wl_list_insert(&text_model->input_methods, &input_method->link); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 179 | input_method_init_seat(weston_seat); |
| 180 | |
| 181 | text_model->surface = surface->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 182 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 183 | input_method_context_create(text_model, input_method); |
| 184 | |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 185 | wl_signal_emit(&ec->show_input_panel_signal, ec); |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 186 | |
Jan Arne Petersen | 680275f | 2012-09-24 14:51:14 +0200 | [diff] [blame] | 187 | text_model_send_enter(&text_model->resource, &text_model->surface->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void |
| 191 | text_model_deactivate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 192 | struct wl_resource *resource, |
| 193 | struct wl_resource *seat) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 194 | { |
| 195 | struct text_model *text_model = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 196 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 197 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 198 | deactivate_text_model(text_model, |
| 199 | weston_seat->input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 203 | text_model_reset(struct wl_client *client, |
| 204 | struct wl_resource *resource) |
| 205 | { |
| 206 | struct text_model *text_model = resource->data; |
| 207 | struct input_method *input_method, *next; |
| 208 | |
| 209 | wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { |
| 210 | if (!input_method->context) |
| 211 | continue; |
| 212 | input_method_context_send_reset(&input_method->context->resource); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 217 | text_model_set_micro_focus(struct wl_client *client, |
| 218 | struct wl_resource *resource, |
| 219 | int32_t x, |
| 220 | int32_t y, |
| 221 | int32_t width, |
| 222 | int32_t height) |
| 223 | { |
| 224 | } |
| 225 | |
| 226 | static void |
| 227 | text_model_set_preedit(struct wl_client *client, |
| 228 | struct wl_resource *resource) |
| 229 | { |
| 230 | } |
| 231 | |
| 232 | static void |
| 233 | text_model_set_content_type(struct wl_client *client, |
| 234 | struct wl_resource *resource) |
| 235 | { |
| 236 | } |
| 237 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 238 | static const struct text_model_interface text_model_implementation = { |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 239 | text_model_set_surrounding_text, |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 240 | text_model_activate, |
| 241 | text_model_deactivate, |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 242 | text_model_reset, |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 243 | text_model_set_micro_focus, |
| 244 | text_model_set_preedit, |
| 245 | text_model_set_content_type |
| 246 | }; |
| 247 | |
Jan Arne Petersen | 5196374 | 2012-08-10 16:47:20 +0200 | [diff] [blame] | 248 | static void text_model_factory_create_text_model(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 249 | struct wl_resource *resource, |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 250 | uint32_t id) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 251 | { |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 252 | struct text_model_factory *text_model_factory = resource->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 253 | struct text_model *text_model; |
| 254 | |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 255 | text_model = calloc(1, sizeof *text_model); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 256 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 257 | text_model->resource.object.id = id; |
| 258 | text_model->resource.object.interface = &text_model_interface; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 259 | text_model->resource.object.implementation = |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 260 | (void (**)(void)) &text_model_implementation; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 261 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 262 | text_model->resource.data = text_model; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 263 | text_model->resource.destroy = destroy_text_model; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 264 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 265 | text_model->ec = text_model_factory->ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 266 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 267 | wl_list_init(&text_model->input_methods); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 268 | |
| 269 | wl_client_add_resource(client, &text_model->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 270 | }; |
| 271 | |
Jan Arne Petersen | 5196374 | 2012-08-10 16:47:20 +0200 | [diff] [blame] | 272 | static const struct text_model_factory_interface text_model_factory_implementation = { |
| 273 | text_model_factory_create_text_model |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | static void |
Jan Arne Petersen | 5196374 | 2012-08-10 16:47:20 +0200 | [diff] [blame] | 277 | bind_text_model_factory(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 278 | void *data, |
| 279 | uint32_t version, |
| 280 | uint32_t id) |
| 281 | { |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 282 | struct text_model_factory *text_model_factory = data; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 283 | |
| 284 | /* No checking for duplicate binding necessary. |
| 285 | * No events have to be sent, so we don't need the return value. */ |
Jan Arne Petersen | 5196374 | 2012-08-10 16:47:20 +0200 | [diff] [blame] | 286 | wl_client_add_object(client, &text_model_factory_interface, |
| 287 | &text_model_factory_implementation, |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 288 | id, text_model_factory); |
| 289 | } |
| 290 | |
| 291 | static void |
| 292 | text_model_factory_notifier_destroy(struct wl_listener *listener, void *data) |
| 293 | { |
| 294 | struct text_model_factory *text_model_factory = |
| 295 | container_of(listener, struct text_model_factory, destroy_listener); |
| 296 | |
| 297 | wl_display_remove_global(text_model_factory->ec->wl_display, |
| 298 | text_model_factory->text_model_factory_global); |
| 299 | |
| 300 | free(text_model_factory); |
| 301 | } |
| 302 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 303 | static void |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 304 | text_model_factory_create(struct weston_compositor *ec) |
| 305 | { |
| 306 | struct text_model_factory *text_model_factory; |
| 307 | |
| 308 | text_model_factory = calloc(1, sizeof *text_model_factory); |
| 309 | |
| 310 | text_model_factory->ec = ec; |
| 311 | |
| 312 | text_model_factory->text_model_factory_global = |
| 313 | wl_display_add_global(ec->wl_display, |
| 314 | &text_model_factory_interface, |
| 315 | text_model_factory, bind_text_model_factory); |
| 316 | |
| 317 | text_model_factory->destroy_listener.notify = text_model_factory_notifier_destroy; |
| 318 | wl_signal_add(&ec->destroy_signal, &text_model_factory->destroy_listener); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 321 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 322 | input_method_context_destroy(struct wl_client *client, |
| 323 | struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 324 | { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 325 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 328 | static void |
| 329 | input_method_context_commit_string(struct wl_client *client, |
| 330 | struct wl_resource *resource, |
| 331 | const char *text, |
| 332 | uint32_t index) |
| 333 | { |
| 334 | struct input_method_context *context = resource->data; |
| 335 | |
| 336 | text_model_send_commit_string(&context->model->resource, text, index); |
| 337 | } |
| 338 | |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 339 | static void |
| 340 | input_method_context_preedit_string(struct wl_client *client, |
| 341 | struct wl_resource *resource, |
| 342 | const char *text, |
| 343 | uint32_t index) |
| 344 | { |
| 345 | struct input_method_context *context = resource->data; |
| 346 | |
| 347 | text_model_send_preedit_string(&context->model->resource, text, index); |
| 348 | } |
| 349 | |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 350 | static void |
| 351 | input_method_context_delete_surrounding_text(struct wl_client *client, |
| 352 | struct wl_resource *resource, |
| 353 | int32_t index, |
| 354 | uint32_t length) |
| 355 | { |
| 356 | struct input_method_context *context = resource->data; |
| 357 | |
| 358 | text_model_send_delete_surrounding_text(&context->model->resource, index, length); |
| 359 | } |
| 360 | |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 361 | static void |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 362 | input_method_context_modifiers_map(struct wl_client *client, |
| 363 | struct wl_resource *resource, |
| 364 | struct wl_array *map) |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 365 | { |
| 366 | struct input_method_context *context = resource->data; |
| 367 | |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 368 | text_model_send_modifiers_map(&context->model->resource, map); |
| 369 | } |
| 370 | |
| 371 | static void |
| 372 | input_method_context_keysym(struct wl_client *client, |
| 373 | struct wl_resource *resource, |
| 374 | uint32_t serial, |
| 375 | uint32_t time, |
| 376 | uint32_t sym, |
| 377 | uint32_t state, |
| 378 | uint32_t modifiers) |
| 379 | { |
| 380 | struct input_method_context *context = resource->data; |
| 381 | |
| 382 | text_model_send_keysym(&context->model->resource, serial, time, |
| 383 | sym, state, modifiers); |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 384 | } |
| 385 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 386 | static void |
| 387 | unbind_keyboard(struct wl_resource *resource) |
| 388 | { |
| 389 | struct input_method_context *context = resource->data; |
| 390 | |
| 391 | input_method_context_end_keyboard_grab(context); |
| 392 | context->keyboard = NULL; |
| 393 | |
| 394 | free(resource); |
| 395 | } |
| 396 | |
| 397 | static void |
| 398 | input_method_context_grab_key(struct wl_keyboard_grab *grab, |
| 399 | uint32_t time, uint32_t key, uint32_t state_w) |
| 400 | { |
| 401 | struct input_method_context *input_method_context = container_of(grab, struct input_method_context, grab); |
| 402 | uint32_t serial; |
| 403 | |
| 404 | if (input_method_context->keyboard) { |
| 405 | serial = wl_display_next_serial(input_method_context->model->ec->wl_display); |
| 406 | wl_keyboard_send_key(input_method_context->keyboard, |
| 407 | serial, time, key, state_w); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | static void |
| 412 | input_method_context_grab_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 413 | uint32_t mods_depressed, uint32_t mods_latched, |
| 414 | uint32_t mods_locked, uint32_t group) |
| 415 | { |
| 416 | struct input_method_context *input_method_context = container_of(grab, struct input_method_context, grab); |
| 417 | |
| 418 | if (!input_method_context->keyboard) |
| 419 | return; |
| 420 | |
| 421 | wl_keyboard_send_modifiers(input_method_context->keyboard, |
| 422 | serial, mods_depressed, mods_latched, |
| 423 | mods_locked, group); |
| 424 | } |
| 425 | |
| 426 | static const struct wl_keyboard_grab_interface input_method_context_grab = { |
| 427 | input_method_context_grab_key, |
| 428 | input_method_context_grab_modifier, |
| 429 | }; |
| 430 | |
| 431 | static void |
| 432 | input_method_context_grab_keyboard(struct wl_client *client, |
| 433 | struct wl_resource *resource, |
| 434 | uint32_t id) |
| 435 | { |
| 436 | struct input_method_context *context = resource->data; |
| 437 | struct wl_resource *cr; |
| 438 | struct weston_seat *seat = context->input_method->seat; |
| 439 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 440 | |
| 441 | cr = wl_client_add_object(client, &wl_keyboard_interface, |
| 442 | NULL, id, context); |
| 443 | cr->destroy = unbind_keyboard; |
| 444 | |
| 445 | context->keyboard = cr; |
| 446 | |
| 447 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 448 | seat->xkb_info.keymap_fd, |
| 449 | seat->xkb_info.keymap_size); |
| 450 | |
| 451 | if (keyboard->grab != &keyboard->default_grab) { |
| 452 | wl_keyboard_end_grab(keyboard); |
| 453 | } |
| 454 | wl_keyboard_start_grab(keyboard, &context->grab); |
| 455 | } |
| 456 | |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame^] | 457 | static void |
| 458 | input_method_context_key(struct wl_client *client, |
| 459 | struct wl_resource *resource, |
| 460 | uint32_t serial, |
| 461 | uint32_t time, |
| 462 | uint32_t key, |
| 463 | uint32_t state_w) |
| 464 | { |
| 465 | struct input_method_context *context = resource->data; |
| 466 | struct weston_seat *seat = context->input_method->seat; |
| 467 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 468 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 469 | |
| 470 | default_grab->interface->key(default_grab, time, key, state_w); |
| 471 | } |
| 472 | |
| 473 | static void |
| 474 | input_method_context_modifiers(struct wl_client *client, |
| 475 | struct wl_resource *resource, |
| 476 | uint32_t serial, |
| 477 | uint32_t mods_depressed, |
| 478 | uint32_t mods_latched, |
| 479 | uint32_t mods_locked, |
| 480 | uint32_t group) |
| 481 | { |
| 482 | struct input_method_context *context = resource->data; |
| 483 | |
| 484 | struct weston_seat *seat = context->input_method->seat; |
| 485 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 486 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 487 | |
| 488 | default_grab->interface->modifiers(default_grab, |
| 489 | serial, mods_depressed, |
| 490 | mods_latched, mods_locked, |
| 491 | group); |
| 492 | } |
| 493 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 494 | static const struct input_method_context_interface input_method_context_implementation = { |
| 495 | input_method_context_destroy, |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 496 | input_method_context_commit_string, |
| 497 | input_method_context_preedit_string, |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 498 | input_method_context_delete_surrounding_text, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 499 | input_method_context_modifiers_map, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 500 | input_method_context_keysym, |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame^] | 501 | input_method_context_grab_keyboard, |
| 502 | input_method_context_key, |
| 503 | input_method_context_modifiers |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 507 | destroy_input_method_context(struct wl_resource *resource) |
| 508 | { |
| 509 | struct input_method_context *context = resource->data; |
| 510 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 511 | if (context->keyboard) { |
| 512 | wl_resource_destroy(context->keyboard); |
| 513 | } |
| 514 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 515 | free(context); |
| 516 | } |
| 517 | |
| 518 | static void |
| 519 | input_method_context_create(struct text_model *model, |
| 520 | struct input_method *input_method) |
| 521 | { |
| 522 | struct input_method_context *context; |
| 523 | |
| 524 | if (!input_method->input_method_binding) |
| 525 | return; |
| 526 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 527 | context = calloc(1, sizeof *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 528 | if (context == NULL) |
| 529 | return; |
| 530 | |
| 531 | context->resource.destroy = destroy_input_method_context; |
| 532 | context->resource.object.id = 0; |
| 533 | context->resource.object.interface = &input_method_context_interface; |
| 534 | context->resource.object.implementation = |
| 535 | (void (**)(void)) &input_method_context_implementation; |
| 536 | context->resource.data = context; |
| 537 | wl_signal_init(&context->resource.destroy_signal); |
| 538 | |
| 539 | context->model = model; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 540 | context->input_method = input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 541 | input_method->context = context; |
| 542 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 543 | context->grab.interface = &input_method_context_grab; |
| 544 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 545 | wl_client_add_resource(input_method->input_method_binding->client, &context->resource); |
| 546 | |
| 547 | input_method_send_activate(input_method->input_method_binding, &context->resource); |
| 548 | } |
| 549 | |
| 550 | static void |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 551 | input_method_context_end_keyboard_grab(struct input_method_context *context) |
| 552 | { |
| 553 | struct wl_keyboard_grab *grab = &context->grab; |
| 554 | |
| 555 | if (grab->keyboard && (grab->keyboard->grab == grab)) { |
| 556 | wl_keyboard_end_grab(grab->keyboard); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | |
| 561 | static void |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 562 | unbind_input_method(struct wl_resource *resource) |
| 563 | { |
| 564 | struct input_method *input_method = resource->data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 565 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 566 | |
| 567 | input_method->input_method_binding = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 568 | input_method->context = NULL; |
| 569 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 570 | text_backend->input_method.binding = NULL; |
| 571 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 572 | free(resource); |
| 573 | } |
| 574 | |
| 575 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 576 | bind_input_method(struct wl_client *client, |
| 577 | void *data, |
| 578 | uint32_t version, |
| 579 | uint32_t id) |
| 580 | { |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 581 | struct input_method *input_method = data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 582 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 583 | struct wl_resource *resource; |
| 584 | |
| 585 | resource = wl_client_add_object(client, &input_method_interface, |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 586 | NULL, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 587 | id, input_method); |
| 588 | |
| 589 | if (input_method->input_method_binding == NULL) { |
| 590 | resource->destroy = unbind_input_method; |
| 591 | input_method->input_method_binding = resource; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 592 | |
| 593 | text_backend->input_method.binding = resource; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | |
| 597 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 598 | "interface object already bound"); |
| 599 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static void |
| 603 | input_method_notifier_destroy(struct wl_listener *listener, void *data) |
| 604 | { |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 605 | struct input_method *input_method = |
| 606 | container_of(listener, struct input_method, destroy_listener); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 607 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 608 | if (input_method->model) |
| 609 | deactivate_text_model(input_method->model, input_method); |
| 610 | |
| 611 | wl_display_remove_global(input_method->seat->compositor->wl_display, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 612 | input_method->input_method_global); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 613 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 614 | free(input_method); |
| 615 | } |
| 616 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 617 | static void |
| 618 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 619 | { |
| 620 | struct wl_keyboard *keyboard = data; |
| 621 | struct input_method *input_method = |
| 622 | container_of(listener, struct input_method, keyboard_focus_listener); |
| 623 | struct wl_surface *surface = keyboard->focus; |
| 624 | |
| 625 | if (!input_method->model) |
| 626 | return; |
| 627 | |
| 628 | if (!surface || input_method->model->surface != surface) |
| 629 | deactivate_text_model(input_method->model, |
| 630 | input_method); |
| 631 | } |
| 632 | |
| 633 | static void |
| 634 | input_method_init_seat(struct weston_seat *seat) |
| 635 | { |
| 636 | if (seat->input_method->focus_listener_initialized) |
| 637 | return; |
| 638 | |
| 639 | if (seat->has_keyboard) { |
| 640 | seat->input_method->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 641 | wl_signal_add(&seat->seat.keyboard->focus_signal, &seat->input_method->keyboard_focus_listener); |
| 642 | } |
| 643 | |
| 644 | seat->input_method->focus_listener_initialized = 1; |
| 645 | } |
| 646 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 647 | static void |
| 648 | handle_input_method_sigchld(struct weston_process *process, int status) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 649 | { |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 650 | struct text_backend *text_backend = |
| 651 | container_of(process, struct text_backend, input_method.process); |
| 652 | |
| 653 | text_backend->input_method.process.pid = 0; |
| 654 | text_backend->input_method.client = NULL; |
| 655 | } |
| 656 | |
| 657 | static void |
| 658 | launch_input_method(struct text_backend *text_backend) |
| 659 | { |
| 660 | if (text_backend->input_method.binding) |
| 661 | return; |
| 662 | |
| 663 | if (!text_backend->input_method.path) |
| 664 | return; |
| 665 | |
| 666 | if (text_backend->input_method.process.pid != 0) |
| 667 | return; |
| 668 | |
| 669 | text_backend->input_method.client = weston_client_launch(text_backend->compositor, |
| 670 | &text_backend->input_method.process, |
| 671 | text_backend->input_method.path, |
| 672 | handle_input_method_sigchld); |
| 673 | |
| 674 | if (!text_backend->input_method.client) |
| 675 | weston_log("not able to start %s\n", text_backend->input_method.path); |
| 676 | } |
| 677 | |
| 678 | static void |
| 679 | handle_seat_created(struct wl_listener *listener, |
| 680 | void *data) |
| 681 | { |
| 682 | struct weston_seat *seat = data; |
| 683 | struct text_backend *text_backend = |
| 684 | container_of(listener, struct text_backend, |
| 685 | seat_created_listener); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 686 | struct input_method *input_method; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 687 | struct weston_compositor *ec = seat->compositor; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 688 | |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 689 | input_method = calloc(1, sizeof *input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 690 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 691 | input_method->seat = seat; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 692 | input_method->model = NULL; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 693 | input_method->focus_listener_initialized = 0; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 694 | input_method->context = NULL; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 695 | input_method->text_backend = text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 696 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 697 | input_method->input_method_global = |
| 698 | wl_display_add_global(ec->wl_display, |
| 699 | &input_method_interface, |
| 700 | input_method, bind_input_method); |
| 701 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 702 | input_method->destroy_listener.notify = input_method_notifier_destroy; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 703 | wl_signal_add(&seat->seat.destroy_signal, &input_method->destroy_listener); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 704 | |
| 705 | seat->input_method = input_method; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 706 | |
| 707 | launch_input_method(text_backend); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 708 | } |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 709 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 710 | static void |
| 711 | text_backend_configuration(struct text_backend *text_backend) |
| 712 | { |
| 713 | char *config_file; |
| 714 | char *path = NULL; |
| 715 | |
| 716 | struct config_key input_method_keys[] = { |
| 717 | { "path", CONFIG_KEY_STRING, &path } |
| 718 | }; |
| 719 | |
| 720 | struct config_section cs[] = { |
| 721 | { "input-method", input_method_keys, ARRAY_LENGTH(input_method_keys), NULL } |
| 722 | }; |
| 723 | |
| 724 | config_file = config_file_path("weston.ini"); |
| 725 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), text_backend); |
| 726 | free(config_file); |
| 727 | |
| 728 | if (path) |
| 729 | text_backend->input_method.path = path; |
| 730 | else |
| 731 | text_backend->input_method.path = strdup(LIBEXECDIR "/weston-keyboard"); |
| 732 | } |
| 733 | |
| 734 | static void |
| 735 | text_backend_notifier_destroy(struct wl_listener *listener, void *data) |
| 736 | { |
| 737 | struct text_backend *text_backend = |
| 738 | container_of(listener, struct text_backend, destroy_listener); |
| 739 | |
| 740 | if (text_backend->input_method.client) |
| 741 | wl_client_destroy(text_backend->input_method.client); |
| 742 | |
| 743 | free(text_backend->input_method.path); |
| 744 | |
| 745 | free(text_backend); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | WL_EXPORT int |
| 750 | text_backend_init(struct weston_compositor *ec) |
| 751 | { |
| 752 | struct text_backend *text_backend; |
| 753 | |
| 754 | text_backend = calloc(1, sizeof(*text_backend)); |
| 755 | |
| 756 | text_backend->compositor = ec; |
| 757 | |
| 758 | text_backend->seat_created_listener.notify = handle_seat_created; |
| 759 | wl_signal_add(&ec->seat_created_signal, |
| 760 | &text_backend->seat_created_listener); |
| 761 | |
| 762 | text_backend->destroy_listener.notify = text_backend_notifier_destroy; |
| 763 | wl_signal_add(&ec->destroy_signal, &text_backend->destroy_listener); |
| 764 | |
| 765 | text_backend_configuration(text_backend); |
| 766 | |
| 767 | text_model_factory_create(ec); |
| 768 | |
| 769 | return 0; |
| 770 | } |