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 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 35 | struct text_input { |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 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 | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 43 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 44 | pixman_box32_t cursor_rectangle; |
| 45 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 46 | uint32_t input_panel_visible; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 49 | struct text_input_manager { |
| 50 | struct wl_global *text_input_manager_global; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 51 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 52 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 53 | struct weston_compositor *ec; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct input_method { |
| 57 | struct wl_resource *input_method_binding; |
| 58 | struct wl_global *input_method_global; |
| 59 | struct wl_listener destroy_listener; |
| 60 | |
| 61 | struct weston_seat *seat; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 62 | struct text_input *model; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 63 | |
| 64 | struct wl_list link; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 65 | |
| 66 | struct wl_listener keyboard_focus_listener; |
| 67 | |
| 68 | int focus_listener_initialized; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 69 | |
| 70 | struct input_method_context *context; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 71 | |
| 72 | struct text_backend *text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 75 | struct input_method_context { |
| 76 | struct wl_resource resource; |
| 77 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 78 | struct text_input *model; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 79 | struct input_method *input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 80 | |
| 81 | struct wl_list link; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 82 | |
| 83 | struct wl_resource *keyboard; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 86 | struct text_backend { |
| 87 | struct weston_compositor *compositor; |
| 88 | |
| 89 | struct { |
| 90 | char *path; |
| 91 | struct wl_resource *binding; |
| 92 | struct weston_process process; |
| 93 | struct wl_client *client; |
| 94 | } input_method; |
| 95 | |
| 96 | struct wl_listener seat_created_listener; |
| 97 | struct wl_listener destroy_listener; |
| 98 | }; |
| 99 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 100 | static void input_method_context_create(struct text_input *model, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 101 | struct input_method *input_method, |
| 102 | uint32_t serial); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 103 | 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] | 104 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 105 | static void input_method_init_seat(struct weston_seat *seat); |
| 106 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 107 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 108 | deactivate_text_input(struct text_input *text_input, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 109 | struct input_method *input_method) |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 110 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 111 | struct weston_compositor *ec = text_input->ec; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 112 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 113 | if (input_method->model == text_input) { |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 114 | if (input_method->context && input_method->input_method_binding) { |
| 115 | input_method_context_end_keyboard_grab(input_method->context); |
| 116 | input_method_send_deactivate(input_method->input_method_binding, |
| 117 | &input_method->context->resource); |
| 118 | } |
| 119 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 120 | wl_list_remove(&input_method->link); |
| 121 | input_method->model = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 122 | input_method->context = NULL; |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 123 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 124 | text_input_send_leave(&text_input->resource); |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 129 | destroy_text_input(struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 130 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 131 | struct text_input *text_input = |
| 132 | container_of(resource, struct text_input, resource); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 133 | struct input_method *input_method, *next; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 134 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 135 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) |
| 136 | deactivate_text_input(text_input, input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 137 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 138 | free(text_input); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 142 | text_input_set_surrounding_text(struct wl_client *client, |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 143 | struct wl_resource *resource, |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 144 | const char *text, |
| 145 | uint32_t cursor, |
| 146 | uint32_t anchor) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 147 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 148 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 149 | struct input_method *input_method, *next; |
| 150 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 151 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 152 | if (!input_method->context) |
| 153 | continue; |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 154 | input_method_context_send_surrounding_text(&input_method->context->resource, |
| 155 | text, |
| 156 | cursor, |
| 157 | anchor); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 158 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 162 | text_input_activate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 163 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 164 | uint32_t serial, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 165 | struct wl_resource *seat, |
| 166 | struct wl_resource *surface) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 167 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 168 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 169 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 170 | struct input_method *input_method = weston_seat->input_method; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 171 | struct text_input *old = weston_seat->input_method->model; |
| 172 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 173 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 174 | if (old == text_input) |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 175 | return; |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 176 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 177 | if (old) { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 178 | deactivate_text_input(old, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 179 | weston_seat->input_method); |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 182 | input_method->model = text_input; |
| 183 | wl_list_insert(&text_input->input_methods, &input_method->link); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 184 | input_method_init_seat(weston_seat); |
| 185 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 186 | text_input->surface = surface->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 187 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 188 | input_method_context_create(text_input, input_method, serial); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 189 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 190 | if (text_input->input_panel_visible) { |
| 191 | wl_signal_emit(&ec->show_input_panel_signal, text_input->surface); |
| 192 | wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle); |
| 193 | } |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 194 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 195 | text_input_send_enter(&text_input->resource, &text_input->surface->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 199 | text_input_deactivate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 200 | struct wl_resource *resource, |
| 201 | struct wl_resource *seat) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 202 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 203 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 204 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 205 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 206 | deactivate_text_input(text_input, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 207 | weston_seat->input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 211 | text_input_reset(struct wl_client *client, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 212 | struct wl_resource *resource, |
| 213 | uint32_t serial) |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 214 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 215 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 216 | struct input_method *input_method, *next; |
| 217 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 218 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 219 | if (!input_method->context) |
| 220 | continue; |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 221 | input_method_context_send_reset(&input_method->context->resource, serial); |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 226 | text_input_set_cursor_rectangle(struct wl_client *client, |
Jan Arne Petersen | 7ef8eff | 2013-04-18 16:47:23 +0200 | [diff] [blame] | 227 | struct wl_resource *resource, |
| 228 | int32_t x, |
| 229 | int32_t y, |
| 230 | int32_t width, |
| 231 | int32_t height) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 232 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 233 | struct text_input *text_input = resource->data; |
| 234 | struct weston_compositor *ec = text_input->ec; |
| 235 | |
| 236 | text_input->cursor_rectangle.x1 = x; |
| 237 | text_input->cursor_rectangle.y1 = y; |
| 238 | text_input->cursor_rectangle.x2 = x + width; |
| 239 | text_input->cursor_rectangle.y2 = y + height; |
| 240 | |
| 241 | wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 245 | text_input_set_content_type(struct wl_client *client, |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 246 | struct wl_resource *resource, |
| 247 | uint32_t hint, |
| 248 | uint32_t purpose) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 249 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 250 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 251 | struct input_method *input_method, *next; |
| 252 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 253 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 254 | if (!input_method->context) |
| 255 | continue; |
| 256 | input_method_context_send_content_type(&input_method->context->resource, hint, purpose); |
| 257 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 260 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 261 | text_input_invoke_action(struct wl_client *client, |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 262 | struct wl_resource *resource, |
| 263 | uint32_t button, |
| 264 | uint32_t index) |
| 265 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 266 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 267 | struct input_method *input_method, *next; |
| 268 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 269 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 270 | if (!input_method->context) |
| 271 | continue; |
| 272 | input_method_context_send_invoke_action(&input_method->context->resource, button, index); |
| 273 | } |
| 274 | } |
| 275 | |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 276 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 277 | text_input_commit_state(struct wl_client *client, |
Jan Arne Petersen | fa35738 | 2013-04-18 16:47:22 +0200 | [diff] [blame] | 278 | struct wl_resource *resource) |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 279 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 280 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 281 | struct input_method *input_method, *next; |
| 282 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 283 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 284 | if (!input_method->context) |
| 285 | continue; |
| 286 | input_method_context_send_commit(&input_method->context->resource); |
| 287 | } |
| 288 | } |
| 289 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 290 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 291 | text_input_show_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 292 | struct wl_resource *resource) |
| 293 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 294 | struct text_input *text_input = resource->data; |
| 295 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 296 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 297 | text_input->input_panel_visible = 1; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 298 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 299 | if (!wl_list_empty(&text_input->input_methods)) { |
| 300 | wl_signal_emit(&ec->show_input_panel_signal, text_input->surface); |
| 301 | wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle); |
| 302 | } |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 306 | text_input_hide_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 307 | struct wl_resource *resource) |
| 308 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 309 | struct text_input *text_input = resource->data; |
| 310 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 311 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 312 | text_input->input_panel_visible = 0; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 313 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 314 | if (!wl_list_empty(&text_input->input_methods)) |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 315 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
| 316 | } |
| 317 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 318 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 319 | text_input_set_preferred_language(struct wl_client *client, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 320 | struct wl_resource *resource, |
| 321 | const char *language) |
| 322 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 323 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 324 | struct input_method *input_method, *next; |
| 325 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 326 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) { |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 327 | if (!input_method->context) |
| 328 | continue; |
| 329 | input_method_context_send_preferred_language(&input_method->context->resource, |
| 330 | language); |
| 331 | } |
| 332 | } |
| 333 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 334 | static const struct text_input_interface text_input_implementation = { |
| 335 | text_input_activate, |
| 336 | text_input_deactivate, |
| 337 | text_input_show_input_panel, |
| 338 | text_input_hide_input_panel, |
| 339 | text_input_reset, |
| 340 | text_input_set_surrounding_text, |
| 341 | text_input_set_content_type, |
| 342 | text_input_set_cursor_rectangle, |
| 343 | text_input_set_preferred_language, |
| 344 | text_input_commit_state, |
| 345 | text_input_invoke_action |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 346 | }; |
| 347 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 348 | static void text_input_manager_create_text_input(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 349 | struct wl_resource *resource, |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 350 | uint32_t id) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 351 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 352 | struct text_input_manager *text_input_manager = resource->data; |
| 353 | struct text_input *text_input; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 354 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 355 | text_input = calloc(1, sizeof *text_input); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 356 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 357 | text_input->resource.object.id = id; |
| 358 | text_input->resource.object.interface = &text_input_interface; |
| 359 | text_input->resource.object.implementation = |
| 360 | (void (**)(void)) &text_input_implementation; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 361 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 362 | text_input->resource.data = text_input; |
| 363 | text_input->resource.destroy = destroy_text_input; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 364 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 365 | text_input->ec = text_input_manager->ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 366 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 367 | wl_list_init(&text_input->input_methods); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 368 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 369 | wl_client_add_resource(client, &text_input->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 370 | }; |
| 371 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 372 | static const struct text_input_manager_interface text_input_manager_implementation = { |
| 373 | text_input_manager_create_text_input |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 377 | bind_text_input_manager(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 378 | void *data, |
| 379 | uint32_t version, |
| 380 | uint32_t id) |
| 381 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 382 | struct text_input_manager *text_input_manager = data; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 383 | |
| 384 | /* No checking for duplicate binding necessary. |
| 385 | * No events have to be sent, so we don't need the return value. */ |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 386 | wl_client_add_object(client, &text_input_manager_interface, |
| 387 | &text_input_manager_implementation, |
| 388 | id, text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 392 | text_input_manager_notifier_destroy(struct wl_listener *listener, void *data) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 393 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 394 | struct text_input_manager *text_input_manager = |
| 395 | container_of(listener, struct text_input_manager, destroy_listener); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 396 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 397 | wl_display_remove_global(text_input_manager->ec->wl_display, |
| 398 | text_input_manager->text_input_manager_global); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 399 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 400 | free(text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 403 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 404 | text_input_manager_create(struct weston_compositor *ec) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 405 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 406 | struct text_input_manager *text_input_manager; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 407 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 408 | text_input_manager = calloc(1, sizeof *text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 409 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 410 | text_input_manager->ec = ec; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 411 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 412 | text_input_manager->text_input_manager_global = |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 413 | wl_display_add_global(ec->wl_display, |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 414 | &text_input_manager_interface, |
| 415 | text_input_manager, bind_text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 416 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 417 | text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy; |
| 418 | wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 421 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 422 | input_method_context_destroy(struct wl_client *client, |
| 423 | struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 424 | { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 425 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 428 | static void |
| 429 | input_method_context_commit_string(struct wl_client *client, |
| 430 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 431 | uint32_t serial, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 432 | const char *text) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 433 | { |
| 434 | struct input_method_context *context = resource->data; |
| 435 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 436 | text_input_send_commit_string(&context->model->resource, serial, text); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 439 | static void |
| 440 | input_method_context_preedit_string(struct wl_client *client, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 441 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 442 | uint32_t serial, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 443 | const char *text, |
| 444 | const char *commit) |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 445 | { |
| 446 | struct input_method_context *context = resource->data; |
| 447 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 448 | text_input_send_preedit_string(&context->model->resource, serial, text, commit); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static void |
| 452 | input_method_context_preedit_styling(struct wl_client *client, |
| 453 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 454 | uint32_t serial, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 455 | uint32_t index, |
| 456 | uint32_t length, |
| 457 | uint32_t style) |
| 458 | { |
| 459 | struct input_method_context *context = resource->data; |
| 460 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 461 | text_input_send_preedit_styling(&context->model->resource, serial, index, length, style); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void |
| 465 | input_method_context_preedit_cursor(struct wl_client *client, |
| 466 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 467 | uint32_t serial, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 468 | int32_t cursor) |
| 469 | { |
| 470 | struct input_method_context *context = resource->data; |
| 471 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 472 | text_input_send_preedit_cursor(&context->model->resource, serial, cursor); |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 475 | static void |
| 476 | input_method_context_delete_surrounding_text(struct wl_client *client, |
| 477 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 478 | uint32_t serial, |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 479 | int32_t index, |
| 480 | uint32_t length) |
| 481 | { |
| 482 | struct input_method_context *context = resource->data; |
| 483 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 484 | text_input_send_delete_surrounding_text(&context->model->resource, serial, index, length); |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 487 | static void |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 488 | input_method_context_cursor_position(struct wl_client *client, |
| 489 | struct wl_resource *resource, |
| 490 | uint32_t serial, |
| 491 | int32_t index, |
| 492 | int32_t anchor) |
| 493 | { |
| 494 | struct input_method_context *context = resource->data; |
| 495 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 496 | text_input_send_cursor_position(&context->model->resource, serial, index, anchor); |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 500 | input_method_context_modifiers_map(struct wl_client *client, |
| 501 | struct wl_resource *resource, |
| 502 | struct wl_array *map) |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 503 | { |
| 504 | struct input_method_context *context = resource->data; |
| 505 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 506 | text_input_send_modifiers_map(&context->model->resource, map); |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static void |
| 510 | input_method_context_keysym(struct wl_client *client, |
| 511 | struct wl_resource *resource, |
| 512 | uint32_t serial, |
| 513 | uint32_t time, |
| 514 | uint32_t sym, |
| 515 | uint32_t state, |
| 516 | uint32_t modifiers) |
| 517 | { |
| 518 | struct input_method_context *context = resource->data; |
| 519 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 520 | text_input_send_keysym(&context->model->resource, serial, time, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 521 | sym, state, modifiers); |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 524 | static void |
| 525 | unbind_keyboard(struct wl_resource *resource) |
| 526 | { |
| 527 | struct input_method_context *context = resource->data; |
| 528 | |
| 529 | input_method_context_end_keyboard_grab(context); |
| 530 | context->keyboard = NULL; |
| 531 | |
| 532 | free(resource); |
| 533 | } |
| 534 | |
| 535 | static void |
| 536 | input_method_context_grab_key(struct wl_keyboard_grab *grab, |
| 537 | uint32_t time, uint32_t key, uint32_t state_w) |
| 538 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 539 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
| 540 | struct wl_display *display; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 541 | uint32_t serial; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 542 | |
| 543 | if (!keyboard->input_method_resource) |
| 544 | return; |
| 545 | |
| 546 | display = wl_client_get_display(keyboard->input_method_resource->client); |
| 547 | serial = wl_display_next_serial(display); |
| 548 | wl_keyboard_send_key(keyboard->input_method_resource, |
| 549 | serial, time, key, state_w); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static void |
| 553 | input_method_context_grab_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 554 | uint32_t mods_depressed, uint32_t mods_latched, |
| 555 | uint32_t mods_locked, uint32_t group) |
| 556 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 557 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 558 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 559 | if (!keyboard->input_method_resource) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 560 | return; |
| 561 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 562 | wl_keyboard_send_modifiers(keyboard->input_method_resource, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 563 | serial, mods_depressed, mods_latched, |
| 564 | mods_locked, group); |
| 565 | } |
| 566 | |
| 567 | static const struct wl_keyboard_grab_interface input_method_context_grab = { |
| 568 | input_method_context_grab_key, |
| 569 | input_method_context_grab_modifier, |
| 570 | }; |
| 571 | |
| 572 | static void |
| 573 | input_method_context_grab_keyboard(struct wl_client *client, |
| 574 | struct wl_resource *resource, |
| 575 | uint32_t id) |
| 576 | { |
| 577 | struct input_method_context *context = resource->data; |
| 578 | struct wl_resource *cr; |
| 579 | struct weston_seat *seat = context->input_method->seat; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 580 | struct weston_keyboard *keyboard = &seat->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 581 | |
| 582 | cr = wl_client_add_object(client, &wl_keyboard_interface, |
| 583 | NULL, id, context); |
| 584 | cr->destroy = unbind_keyboard; |
| 585 | |
| 586 | context->keyboard = cr; |
| 587 | |
| 588 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 589 | seat->xkb_info.keymap_fd, |
| 590 | seat->xkb_info.keymap_size); |
| 591 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 592 | if (keyboard->keyboard.grab != &keyboard->keyboard.default_grab) { |
| 593 | wl_keyboard_end_grab(&keyboard->keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 594 | } |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 595 | wl_keyboard_start_grab(&keyboard->keyboard, &keyboard->input_method_grab); |
| 596 | keyboard->input_method_resource = cr; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 599 | static void |
| 600 | input_method_context_key(struct wl_client *client, |
| 601 | struct wl_resource *resource, |
| 602 | uint32_t serial, |
| 603 | uint32_t time, |
| 604 | uint32_t key, |
| 605 | uint32_t state_w) |
| 606 | { |
| 607 | struct input_method_context *context = resource->data; |
| 608 | struct weston_seat *seat = context->input_method->seat; |
| 609 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 610 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 611 | |
| 612 | default_grab->interface->key(default_grab, time, key, state_w); |
| 613 | } |
| 614 | |
| 615 | static void |
| 616 | input_method_context_modifiers(struct wl_client *client, |
| 617 | struct wl_resource *resource, |
| 618 | uint32_t serial, |
| 619 | uint32_t mods_depressed, |
| 620 | uint32_t mods_latched, |
| 621 | uint32_t mods_locked, |
| 622 | uint32_t group) |
| 623 | { |
| 624 | struct input_method_context *context = resource->data; |
| 625 | |
| 626 | struct weston_seat *seat = context->input_method->seat; |
| 627 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 628 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 629 | |
| 630 | default_grab->interface->modifiers(default_grab, |
| 631 | serial, mods_depressed, |
| 632 | mods_latched, mods_locked, |
| 633 | group); |
| 634 | } |
| 635 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 636 | static void |
| 637 | input_method_context_language(struct wl_client *client, |
| 638 | struct wl_resource *resource, |
| 639 | uint32_t serial, |
| 640 | const char *language) |
| 641 | { |
| 642 | struct input_method_context *context = resource->data; |
| 643 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 644 | text_input_send_language(&context->model->resource, serial, language); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void |
| 648 | input_method_context_text_direction(struct wl_client *client, |
| 649 | struct wl_resource *resource, |
| 650 | uint32_t serial, |
| 651 | uint32_t direction) |
| 652 | { |
| 653 | struct input_method_context *context = resource->data; |
| 654 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 655 | text_input_send_text_direction(&context->model->resource, serial, direction); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 659 | static const struct input_method_context_interface input_method_context_implementation = { |
| 660 | input_method_context_destroy, |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 661 | input_method_context_commit_string, |
| 662 | input_method_context_preedit_string, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 663 | input_method_context_preedit_styling, |
| 664 | input_method_context_preedit_cursor, |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 665 | input_method_context_delete_surrounding_text, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 666 | input_method_context_cursor_position, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 667 | input_method_context_modifiers_map, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 668 | input_method_context_keysym, |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 669 | input_method_context_grab_keyboard, |
| 670 | input_method_context_key, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 671 | input_method_context_modifiers, |
| 672 | input_method_context_language, |
| 673 | input_method_context_text_direction |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 674 | }; |
| 675 | |
| 676 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 677 | destroy_input_method_context(struct wl_resource *resource) |
| 678 | { |
| 679 | struct input_method_context *context = resource->data; |
| 680 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 681 | if (context->keyboard) { |
| 682 | wl_resource_destroy(context->keyboard); |
| 683 | } |
| 684 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 685 | free(context); |
| 686 | } |
| 687 | |
| 688 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 689 | input_method_context_create(struct text_input *model, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 690 | struct input_method *input_method, |
| 691 | uint32_t serial) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 692 | { |
| 693 | struct input_method_context *context; |
| 694 | |
| 695 | if (!input_method->input_method_binding) |
| 696 | return; |
| 697 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 698 | context = calloc(1, sizeof *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 699 | if (context == NULL) |
| 700 | return; |
| 701 | |
| 702 | context->resource.destroy = destroy_input_method_context; |
| 703 | context->resource.object.id = 0; |
| 704 | context->resource.object.interface = &input_method_context_interface; |
| 705 | context->resource.object.implementation = |
| 706 | (void (**)(void)) &input_method_context_implementation; |
| 707 | context->resource.data = context; |
| 708 | wl_signal_init(&context->resource.destroy_signal); |
| 709 | |
| 710 | context->model = model; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 711 | context->input_method = input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 712 | input_method->context = context; |
| 713 | |
| 714 | wl_client_add_resource(input_method->input_method_binding->client, &context->resource); |
| 715 | |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 716 | input_method_send_activate(input_method->input_method_binding, &context->resource, serial); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | static void |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 720 | input_method_context_end_keyboard_grab(struct input_method_context *context) |
| 721 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 722 | struct wl_keyboard_grab *grab = &context->input_method->seat->keyboard.input_method_grab; |
| 723 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 724 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 725 | if (!grab->keyboard) |
| 726 | return; |
| 727 | |
| 728 | if (grab->keyboard->grab == grab) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 729 | wl_keyboard_end_grab(grab->keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 730 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 731 | keyboard->input_method_resource = NULL; |
| 732 | } |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 733 | |
| 734 | static void |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 735 | unbind_input_method(struct wl_resource *resource) |
| 736 | { |
| 737 | struct input_method *input_method = resource->data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 738 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 739 | |
| 740 | input_method->input_method_binding = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 741 | input_method->context = NULL; |
| 742 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 743 | text_backend->input_method.binding = NULL; |
| 744 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 745 | free(resource); |
| 746 | } |
| 747 | |
| 748 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 749 | bind_input_method(struct wl_client *client, |
| 750 | void *data, |
| 751 | uint32_t version, |
| 752 | uint32_t id) |
| 753 | { |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 754 | struct input_method *input_method = data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 755 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 756 | struct wl_resource *resource; |
| 757 | |
| 758 | resource = wl_client_add_object(client, &input_method_interface, |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 759 | NULL, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 760 | id, input_method); |
| 761 | |
| 762 | if (input_method->input_method_binding == NULL) { |
| 763 | resource->destroy = unbind_input_method; |
| 764 | input_method->input_method_binding = resource; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 765 | |
| 766 | text_backend->input_method.binding = resource; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
| 770 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 771 | "interface object already bound"); |
| 772 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static void |
| 776 | input_method_notifier_destroy(struct wl_listener *listener, void *data) |
| 777 | { |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 778 | struct input_method *input_method = |
| 779 | container_of(listener, struct input_method, destroy_listener); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 780 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 781 | if (input_method->model) |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 782 | deactivate_text_input(input_method->model, input_method); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 783 | |
| 784 | wl_display_remove_global(input_method->seat->compositor->wl_display, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 785 | input_method->input_method_global); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 786 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 787 | free(input_method); |
| 788 | } |
| 789 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 790 | static void |
| 791 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 792 | { |
| 793 | struct wl_keyboard *keyboard = data; |
| 794 | struct input_method *input_method = |
| 795 | container_of(listener, struct input_method, keyboard_focus_listener); |
| 796 | struct wl_surface *surface = keyboard->focus; |
| 797 | |
| 798 | if (!input_method->model) |
| 799 | return; |
| 800 | |
| 801 | if (!surface || input_method->model->surface != surface) |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 802 | deactivate_text_input(input_method->model, |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 803 | input_method); |
| 804 | } |
| 805 | |
| 806 | static void |
| 807 | input_method_init_seat(struct weston_seat *seat) |
| 808 | { |
| 809 | if (seat->input_method->focus_listener_initialized) |
| 810 | return; |
| 811 | |
| 812 | if (seat->has_keyboard) { |
| 813 | seat->input_method->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 814 | wl_signal_add(&seat->seat.keyboard->focus_signal, &seat->input_method->keyboard_focus_listener); |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 815 | seat->keyboard.input_method_grab.interface = &input_method_context_grab; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | seat->input_method->focus_listener_initialized = 1; |
| 819 | } |
| 820 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 821 | static void |
| 822 | handle_input_method_sigchld(struct weston_process *process, int status) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 823 | { |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 824 | struct text_backend *text_backend = |
| 825 | container_of(process, struct text_backend, input_method.process); |
| 826 | |
| 827 | text_backend->input_method.process.pid = 0; |
| 828 | text_backend->input_method.client = NULL; |
| 829 | } |
| 830 | |
| 831 | static void |
| 832 | launch_input_method(struct text_backend *text_backend) |
| 833 | { |
| 834 | if (text_backend->input_method.binding) |
| 835 | return; |
| 836 | |
| 837 | if (!text_backend->input_method.path) |
| 838 | return; |
| 839 | |
| 840 | if (text_backend->input_method.process.pid != 0) |
| 841 | return; |
| 842 | |
| 843 | text_backend->input_method.client = weston_client_launch(text_backend->compositor, |
| 844 | &text_backend->input_method.process, |
| 845 | text_backend->input_method.path, |
| 846 | handle_input_method_sigchld); |
| 847 | |
| 848 | if (!text_backend->input_method.client) |
| 849 | weston_log("not able to start %s\n", text_backend->input_method.path); |
| 850 | } |
| 851 | |
| 852 | static void |
| 853 | handle_seat_created(struct wl_listener *listener, |
| 854 | void *data) |
| 855 | { |
| 856 | struct weston_seat *seat = data; |
| 857 | struct text_backend *text_backend = |
| 858 | container_of(listener, struct text_backend, |
| 859 | seat_created_listener); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 860 | struct input_method *input_method; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 861 | struct weston_compositor *ec = seat->compositor; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 862 | |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 863 | input_method = calloc(1, sizeof *input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 864 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 865 | input_method->seat = seat; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 866 | input_method->model = NULL; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 867 | input_method->focus_listener_initialized = 0; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 868 | input_method->context = NULL; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 869 | input_method->text_backend = text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 870 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 871 | input_method->input_method_global = |
| 872 | wl_display_add_global(ec->wl_display, |
| 873 | &input_method_interface, |
| 874 | input_method, bind_input_method); |
| 875 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 876 | input_method->destroy_listener.notify = input_method_notifier_destroy; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 877 | wl_signal_add(&seat->seat.destroy_signal, &input_method->destroy_listener); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 878 | |
| 879 | seat->input_method = input_method; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 880 | |
| 881 | launch_input_method(text_backend); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 882 | } |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 883 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 884 | static void |
| 885 | text_backend_configuration(struct text_backend *text_backend) |
| 886 | { |
| 887 | char *config_file; |
| 888 | char *path = NULL; |
| 889 | |
| 890 | struct config_key input_method_keys[] = { |
| 891 | { "path", CONFIG_KEY_STRING, &path } |
| 892 | }; |
| 893 | |
| 894 | struct config_section cs[] = { |
| 895 | { "input-method", input_method_keys, ARRAY_LENGTH(input_method_keys), NULL } |
| 896 | }; |
| 897 | |
| 898 | config_file = config_file_path("weston.ini"); |
| 899 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), text_backend); |
| 900 | free(config_file); |
| 901 | |
| 902 | if (path) |
| 903 | text_backend->input_method.path = path; |
| 904 | else |
| 905 | text_backend->input_method.path = strdup(LIBEXECDIR "/weston-keyboard"); |
| 906 | } |
| 907 | |
| 908 | static void |
| 909 | text_backend_notifier_destroy(struct wl_listener *listener, void *data) |
| 910 | { |
| 911 | struct text_backend *text_backend = |
| 912 | container_of(listener, struct text_backend, destroy_listener); |
| 913 | |
| 914 | if (text_backend->input_method.client) |
| 915 | wl_client_destroy(text_backend->input_method.client); |
| 916 | |
| 917 | free(text_backend->input_method.path); |
| 918 | |
| 919 | free(text_backend); |
| 920 | } |
| 921 | |
| 922 | |
| 923 | WL_EXPORT int |
| 924 | text_backend_init(struct weston_compositor *ec) |
| 925 | { |
| 926 | struct text_backend *text_backend; |
| 927 | |
| 928 | text_backend = calloc(1, sizeof(*text_backend)); |
| 929 | |
| 930 | text_backend->compositor = ec; |
| 931 | |
| 932 | text_backend->seat_created_listener.notify = handle_seat_created; |
| 933 | wl_signal_add(&ec->seat_created_signal, |
| 934 | &text_backend->seat_created_listener); |
| 935 | |
| 936 | text_backend->destroy_listener.notify = text_backend_notifier_destroy; |
| 937 | wl_signal_add(&ec->destroy_signal, &text_backend->destroy_listener); |
| 938 | |
| 939 | text_backend_configuration(text_backend); |
| 940 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 941 | text_input_manager_create(ec); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 942 | |
| 943 | return 0; |
| 944 | } |