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 | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 101 | struct input_method *input_method); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 102 | 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] | 103 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 104 | static void input_method_init_seat(struct weston_seat *seat); |
| 105 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 106 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 107 | deactivate_text_input(struct text_input *text_input, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 108 | struct input_method *input_method) |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 109 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 110 | struct weston_compositor *ec = text_input->ec; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 111 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 112 | if (input_method->model == text_input) { |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 113 | if (input_method->context && input_method->input_method_binding) { |
| 114 | input_method_context_end_keyboard_grab(input_method->context); |
| 115 | input_method_send_deactivate(input_method->input_method_binding, |
| 116 | &input_method->context->resource); |
| 117 | } |
| 118 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 119 | wl_list_remove(&input_method->link); |
| 120 | input_method->model = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 121 | input_method->context = NULL; |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 122 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 123 | text_input_send_leave(&text_input->resource); |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 128 | destroy_text_input(struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 129 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 130 | struct text_input *text_input = |
| 131 | container_of(resource, struct text_input, resource); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 132 | struct input_method *input_method, *next; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 133 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 134 | wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) |
| 135 | deactivate_text_input(text_input, input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 136 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 137 | free(text_input); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 141 | text_input_set_surrounding_text(struct wl_client *client, |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 142 | struct wl_resource *resource, |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 143 | const char *text, |
| 144 | uint32_t cursor, |
| 145 | uint32_t anchor) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 146 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 147 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 148 | struct input_method *input_method, *next; |
| 149 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 150 | 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] | 151 | if (!input_method->context) |
| 152 | continue; |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 153 | input_method_context_send_surrounding_text(&input_method->context->resource, |
| 154 | text, |
| 155 | cursor, |
| 156 | anchor); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 157 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 161 | text_input_activate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 162 | struct wl_resource *resource, |
| 163 | struct wl_resource *seat, |
| 164 | struct wl_resource *surface) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 165 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 166 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 167 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 168 | struct input_method *input_method = weston_seat->input_method; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 169 | struct text_input *old = weston_seat->input_method->model; |
| 170 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 171 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 172 | if (old == text_input) |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 173 | return; |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 174 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 175 | if (old) { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 176 | deactivate_text_input(old, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 177 | weston_seat->input_method); |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 180 | input_method->model = text_input; |
| 181 | wl_list_insert(&text_input->input_methods, &input_method->link); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 182 | input_method_init_seat(weston_seat); |
| 183 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 184 | text_input->surface = surface->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 185 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 186 | input_method_context_create(text_input, input_method); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 187 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 188 | if (text_input->input_panel_visible) { |
| 189 | wl_signal_emit(&ec->show_input_panel_signal, text_input->surface); |
| 190 | wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle); |
| 191 | } |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 192 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 193 | text_input_send_enter(&text_input->resource, &text_input->surface->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 197 | text_input_deactivate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 198 | struct wl_resource *resource, |
| 199 | struct wl_resource *seat) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 200 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 201 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 202 | struct weston_seat *weston_seat = seat->data; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 203 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 204 | deactivate_text_input(text_input, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 205 | weston_seat->input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 209 | text_input_reset(struct wl_client *client, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 210 | struct wl_resource *resource) |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 211 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 212 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 213 | struct input_method *input_method, *next; |
| 214 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 215 | 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] | 216 | if (!input_method->context) |
| 217 | continue; |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 218 | input_method_context_send_reset(&input_method->context->resource); |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 223 | text_input_set_cursor_rectangle(struct wl_client *client, |
Jan Arne Petersen | 7ef8eff | 2013-04-18 16:47:23 +0200 | [diff] [blame] | 224 | struct wl_resource *resource, |
| 225 | int32_t x, |
| 226 | int32_t y, |
| 227 | int32_t width, |
| 228 | int32_t height) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 229 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 230 | struct text_input *text_input = resource->data; |
| 231 | struct weston_compositor *ec = text_input->ec; |
| 232 | |
| 233 | text_input->cursor_rectangle.x1 = x; |
| 234 | text_input->cursor_rectangle.y1 = y; |
| 235 | text_input->cursor_rectangle.x2 = x + width; |
| 236 | text_input->cursor_rectangle.y2 = y + height; |
| 237 | |
| 238 | 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] | 239 | } |
| 240 | |
| 241 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 242 | text_input_set_content_type(struct wl_client *client, |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 243 | struct wl_resource *resource, |
| 244 | uint32_t hint, |
| 245 | uint32_t purpose) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 246 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 247 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 248 | struct input_method *input_method, *next; |
| 249 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 250 | 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] | 251 | if (!input_method->context) |
| 252 | continue; |
| 253 | input_method_context_send_content_type(&input_method->context->resource, hint, purpose); |
| 254 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 257 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 258 | text_input_invoke_action(struct wl_client *client, |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 259 | struct wl_resource *resource, |
| 260 | uint32_t button, |
| 261 | uint32_t index) |
| 262 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 263 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 264 | struct input_method *input_method, *next; |
| 265 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 266 | 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] | 267 | if (!input_method->context) |
| 268 | continue; |
| 269 | input_method_context_send_invoke_action(&input_method->context->resource, button, index); |
| 270 | } |
| 271 | } |
| 272 | |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 273 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 274 | text_input_commit_state(struct wl_client *client, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 275 | struct wl_resource *resource, |
| 276 | uint32_t serial) |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 277 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 278 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 279 | struct input_method *input_method, *next; |
| 280 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 281 | 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] | 282 | if (!input_method->context) |
| 283 | continue; |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 284 | input_method_context_send_commit_state(&input_method->context->resource, serial); |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 288 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 289 | text_input_show_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 290 | struct wl_resource *resource) |
| 291 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 292 | struct text_input *text_input = resource->data; |
| 293 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 294 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 295 | text_input->input_panel_visible = 1; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 296 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 297 | if (!wl_list_empty(&text_input->input_methods)) { |
| 298 | wl_signal_emit(&ec->show_input_panel_signal, text_input->surface); |
| 299 | wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle); |
| 300 | } |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 304 | text_input_hide_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 305 | struct wl_resource *resource) |
| 306 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 307 | struct text_input *text_input = resource->data; |
| 308 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 309 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 310 | text_input->input_panel_visible = 0; |
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 | if (!wl_list_empty(&text_input->input_methods)) |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 313 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
| 314 | } |
| 315 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 316 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 317 | text_input_set_preferred_language(struct wl_client *client, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 318 | struct wl_resource *resource, |
| 319 | const char *language) |
| 320 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 321 | struct text_input *text_input = resource->data; |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 322 | struct input_method *input_method, *next; |
| 323 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 324 | 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] | 325 | if (!input_method->context) |
| 326 | continue; |
| 327 | input_method_context_send_preferred_language(&input_method->context->resource, |
| 328 | language); |
| 329 | } |
| 330 | } |
| 331 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 332 | static const struct text_input_interface text_input_implementation = { |
| 333 | text_input_activate, |
| 334 | text_input_deactivate, |
| 335 | text_input_show_input_panel, |
| 336 | text_input_hide_input_panel, |
| 337 | text_input_reset, |
| 338 | text_input_set_surrounding_text, |
| 339 | text_input_set_content_type, |
| 340 | text_input_set_cursor_rectangle, |
| 341 | text_input_set_preferred_language, |
| 342 | text_input_commit_state, |
| 343 | text_input_invoke_action |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 344 | }; |
| 345 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 346 | 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] | 347 | struct wl_resource *resource, |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 348 | uint32_t id) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 349 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 350 | struct text_input_manager *text_input_manager = resource->data; |
| 351 | struct text_input *text_input; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 352 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 353 | text_input = calloc(1, sizeof *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->resource.object.id = id; |
| 356 | text_input->resource.object.interface = &text_input_interface; |
| 357 | text_input->resource.object.implementation = |
| 358 | (void (**)(void)) &text_input_implementation; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 359 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 360 | text_input->resource.data = text_input; |
| 361 | text_input->resource.destroy = destroy_text_input; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 362 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 363 | text_input->ec = text_input_manager->ec; |
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 | wl_list_init(&text_input->input_methods); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 366 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 367 | wl_client_add_resource(client, &text_input->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 368 | }; |
| 369 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 370 | static const struct text_input_manager_interface text_input_manager_implementation = { |
| 371 | text_input_manager_create_text_input |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 375 | bind_text_input_manager(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 376 | void *data, |
| 377 | uint32_t version, |
| 378 | uint32_t id) |
| 379 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 380 | struct text_input_manager *text_input_manager = data; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 381 | |
| 382 | /* No checking for duplicate binding necessary. |
| 383 | * 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] | 384 | wl_client_add_object(client, &text_input_manager_interface, |
| 385 | &text_input_manager_implementation, |
| 386 | id, text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 390 | text_input_manager_notifier_destroy(struct wl_listener *listener, void *data) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 391 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 392 | struct text_input_manager *text_input_manager = |
| 393 | container_of(listener, struct text_input_manager, destroy_listener); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 394 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 395 | wl_display_remove_global(text_input_manager->ec->wl_display, |
| 396 | text_input_manager->text_input_manager_global); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 397 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 398 | free(text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 401 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 402 | text_input_manager_create(struct weston_compositor *ec) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 403 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 404 | struct text_input_manager *text_input_manager; |
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 | text_input_manager = calloc(1, sizeof *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->ec = ec; |
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->text_input_manager_global = |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 411 | wl_display_add_global(ec->wl_display, |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 412 | &text_input_manager_interface, |
| 413 | text_input_manager, bind_text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 414 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 415 | text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy; |
| 416 | wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 419 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 420 | input_method_context_destroy(struct wl_client *client, |
| 421 | struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 422 | { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 423 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 424 | } |
| 425 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 426 | static void |
| 427 | input_method_context_commit_string(struct wl_client *client, |
| 428 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 429 | uint32_t serial, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 430 | const char *text) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 431 | { |
| 432 | struct input_method_context *context = resource->data; |
| 433 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 434 | text_input_send_commit_string(&context->model->resource, serial, text); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 435 | } |
| 436 | |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 437 | static void |
| 438 | input_method_context_preedit_string(struct wl_client *client, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 439 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 440 | uint32_t serial, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 441 | const char *text, |
| 442 | const char *commit) |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 443 | { |
| 444 | struct input_method_context *context = resource->data; |
| 445 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 446 | text_input_send_preedit_string(&context->model->resource, serial, text, commit); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void |
| 450 | input_method_context_preedit_styling(struct wl_client *client, |
| 451 | struct wl_resource *resource, |
| 452 | uint32_t index, |
| 453 | uint32_t length, |
| 454 | uint32_t style) |
| 455 | { |
| 456 | struct input_method_context *context = resource->data; |
| 457 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 458 | text_input_send_preedit_styling(&context->model->resource, index, length, style); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void |
| 462 | input_method_context_preedit_cursor(struct wl_client *client, |
| 463 | struct wl_resource *resource, |
| 464 | int32_t cursor) |
| 465 | { |
| 466 | struct input_method_context *context = resource->data; |
| 467 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 468 | text_input_send_preedit_cursor(&context->model->resource, cursor); |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 471 | static void |
| 472 | input_method_context_delete_surrounding_text(struct wl_client *client, |
| 473 | struct wl_resource *resource, |
| 474 | int32_t index, |
| 475 | uint32_t length) |
| 476 | { |
| 477 | struct input_method_context *context = resource->data; |
| 478 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 479 | text_input_send_delete_surrounding_text(&context->model->resource, index, length); |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 482 | static void |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 483 | input_method_context_cursor_position(struct wl_client *client, |
| 484 | struct wl_resource *resource, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 485 | int32_t index, |
| 486 | int32_t anchor) |
| 487 | { |
| 488 | struct input_method_context *context = resource->data; |
| 489 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 490 | text_input_send_cursor_position(&context->model->resource, index, anchor); |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 494 | input_method_context_modifiers_map(struct wl_client *client, |
| 495 | struct wl_resource *resource, |
| 496 | struct wl_array *map) |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 497 | { |
| 498 | struct input_method_context *context = resource->data; |
| 499 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 500 | text_input_send_modifiers_map(&context->model->resource, map); |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static void |
| 504 | input_method_context_keysym(struct wl_client *client, |
| 505 | struct wl_resource *resource, |
| 506 | uint32_t serial, |
| 507 | uint32_t time, |
| 508 | uint32_t sym, |
| 509 | uint32_t state, |
| 510 | uint32_t modifiers) |
| 511 | { |
| 512 | struct input_method_context *context = resource->data; |
| 513 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 514 | text_input_send_keysym(&context->model->resource, serial, time, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 515 | sym, state, modifiers); |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 518 | static void |
| 519 | unbind_keyboard(struct wl_resource *resource) |
| 520 | { |
| 521 | struct input_method_context *context = resource->data; |
| 522 | |
| 523 | input_method_context_end_keyboard_grab(context); |
| 524 | context->keyboard = NULL; |
| 525 | |
| 526 | free(resource); |
| 527 | } |
| 528 | |
| 529 | static void |
| 530 | input_method_context_grab_key(struct wl_keyboard_grab *grab, |
| 531 | uint32_t time, uint32_t key, uint32_t state_w) |
| 532 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 533 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
| 534 | struct wl_display *display; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 535 | uint32_t serial; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 536 | |
| 537 | if (!keyboard->input_method_resource) |
| 538 | return; |
| 539 | |
| 540 | display = wl_client_get_display(keyboard->input_method_resource->client); |
| 541 | serial = wl_display_next_serial(display); |
| 542 | wl_keyboard_send_key(keyboard->input_method_resource, |
| 543 | serial, time, key, state_w); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static void |
| 547 | input_method_context_grab_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 548 | uint32_t mods_depressed, uint32_t mods_latched, |
| 549 | uint32_t mods_locked, uint32_t group) |
| 550 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 551 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 552 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 553 | if (!keyboard->input_method_resource) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 554 | return; |
| 555 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 556 | wl_keyboard_send_modifiers(keyboard->input_method_resource, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 557 | serial, mods_depressed, mods_latched, |
| 558 | mods_locked, group); |
| 559 | } |
| 560 | |
| 561 | static const struct wl_keyboard_grab_interface input_method_context_grab = { |
| 562 | input_method_context_grab_key, |
| 563 | input_method_context_grab_modifier, |
| 564 | }; |
| 565 | |
| 566 | static void |
| 567 | input_method_context_grab_keyboard(struct wl_client *client, |
| 568 | struct wl_resource *resource, |
| 569 | uint32_t id) |
| 570 | { |
| 571 | struct input_method_context *context = resource->data; |
| 572 | struct wl_resource *cr; |
| 573 | struct weston_seat *seat = context->input_method->seat; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 574 | struct weston_keyboard *keyboard = &seat->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 575 | |
| 576 | cr = wl_client_add_object(client, &wl_keyboard_interface, |
| 577 | NULL, id, context); |
| 578 | cr->destroy = unbind_keyboard; |
| 579 | |
| 580 | context->keyboard = cr; |
| 581 | |
| 582 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 583 | seat->xkb_info.keymap_fd, |
| 584 | seat->xkb_info.keymap_size); |
| 585 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 586 | if (keyboard->keyboard.grab != &keyboard->keyboard.default_grab) { |
| 587 | wl_keyboard_end_grab(&keyboard->keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 588 | } |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 589 | wl_keyboard_start_grab(&keyboard->keyboard, &keyboard->input_method_grab); |
| 590 | keyboard->input_method_resource = cr; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 593 | static void |
| 594 | input_method_context_key(struct wl_client *client, |
| 595 | struct wl_resource *resource, |
| 596 | uint32_t serial, |
| 597 | uint32_t time, |
| 598 | uint32_t key, |
| 599 | uint32_t state_w) |
| 600 | { |
| 601 | struct input_method_context *context = resource->data; |
| 602 | struct weston_seat *seat = context->input_method->seat; |
| 603 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 604 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 605 | |
| 606 | default_grab->interface->key(default_grab, time, key, state_w); |
| 607 | } |
| 608 | |
| 609 | static void |
| 610 | input_method_context_modifiers(struct wl_client *client, |
| 611 | struct wl_resource *resource, |
| 612 | uint32_t serial, |
| 613 | uint32_t mods_depressed, |
| 614 | uint32_t mods_latched, |
| 615 | uint32_t mods_locked, |
| 616 | uint32_t group) |
| 617 | { |
| 618 | struct input_method_context *context = resource->data; |
| 619 | |
| 620 | struct weston_seat *seat = context->input_method->seat; |
| 621 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 622 | struct wl_keyboard_grab *default_grab = &keyboard->default_grab; |
| 623 | |
| 624 | default_grab->interface->modifiers(default_grab, |
| 625 | serial, mods_depressed, |
| 626 | mods_latched, mods_locked, |
| 627 | group); |
| 628 | } |
| 629 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 630 | static void |
| 631 | input_method_context_language(struct wl_client *client, |
| 632 | struct wl_resource *resource, |
| 633 | uint32_t serial, |
| 634 | const char *language) |
| 635 | { |
| 636 | struct input_method_context *context = resource->data; |
| 637 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 638 | text_input_send_language(&context->model->resource, serial, language); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static void |
| 642 | input_method_context_text_direction(struct wl_client *client, |
| 643 | struct wl_resource *resource, |
| 644 | uint32_t serial, |
| 645 | uint32_t direction) |
| 646 | { |
| 647 | struct input_method_context *context = resource->data; |
| 648 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 649 | text_input_send_text_direction(&context->model->resource, serial, direction); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 653 | static const struct input_method_context_interface input_method_context_implementation = { |
| 654 | input_method_context_destroy, |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 655 | input_method_context_commit_string, |
| 656 | input_method_context_preedit_string, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 657 | input_method_context_preedit_styling, |
| 658 | input_method_context_preedit_cursor, |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 659 | input_method_context_delete_surrounding_text, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 660 | input_method_context_cursor_position, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 661 | input_method_context_modifiers_map, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 662 | input_method_context_keysym, |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 663 | input_method_context_grab_keyboard, |
| 664 | input_method_context_key, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 665 | input_method_context_modifiers, |
| 666 | input_method_context_language, |
| 667 | input_method_context_text_direction |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 671 | destroy_input_method_context(struct wl_resource *resource) |
| 672 | { |
| 673 | struct input_method_context *context = resource->data; |
| 674 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 675 | if (context->keyboard) { |
| 676 | wl_resource_destroy(context->keyboard); |
| 677 | } |
| 678 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 679 | free(context); |
| 680 | } |
| 681 | |
| 682 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 683 | input_method_context_create(struct text_input *model, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 684 | struct input_method *input_method) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 685 | { |
| 686 | struct input_method_context *context; |
| 687 | |
| 688 | if (!input_method->input_method_binding) |
| 689 | return; |
| 690 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 691 | context = calloc(1, sizeof *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 692 | if (context == NULL) |
| 693 | return; |
| 694 | |
| 695 | context->resource.destroy = destroy_input_method_context; |
| 696 | context->resource.object.id = 0; |
| 697 | context->resource.object.interface = &input_method_context_interface; |
| 698 | context->resource.object.implementation = |
| 699 | (void (**)(void)) &input_method_context_implementation; |
| 700 | context->resource.data = context; |
| 701 | wl_signal_init(&context->resource.destroy_signal); |
| 702 | |
| 703 | context->model = model; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 704 | context->input_method = input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 705 | input_method->context = context; |
| 706 | |
| 707 | wl_client_add_resource(input_method->input_method_binding->client, &context->resource); |
| 708 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 709 | input_method_send_activate(input_method->input_method_binding, &context->resource); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 713 | input_method_context_end_keyboard_grab(struct input_method_context *context) |
| 714 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 715 | struct wl_keyboard_grab *grab = &context->input_method->seat->keyboard.input_method_grab; |
| 716 | struct weston_keyboard *keyboard = (struct weston_keyboard *)grab->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 717 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 718 | if (!grab->keyboard) |
| 719 | return; |
| 720 | |
| 721 | if (grab->keyboard->grab == grab) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 722 | wl_keyboard_end_grab(grab->keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 723 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 724 | keyboard->input_method_resource = NULL; |
| 725 | } |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 726 | |
| 727 | static void |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 728 | unbind_input_method(struct wl_resource *resource) |
| 729 | { |
| 730 | struct input_method *input_method = resource->data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 731 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 732 | |
| 733 | input_method->input_method_binding = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 734 | input_method->context = NULL; |
| 735 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 736 | text_backend->input_method.binding = NULL; |
| 737 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 738 | free(resource); |
| 739 | } |
| 740 | |
| 741 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 742 | bind_input_method(struct wl_client *client, |
| 743 | void *data, |
| 744 | uint32_t version, |
| 745 | uint32_t id) |
| 746 | { |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 747 | struct input_method *input_method = data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 748 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 749 | struct wl_resource *resource; |
| 750 | |
| 751 | resource = wl_client_add_object(client, &input_method_interface, |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 752 | NULL, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 753 | id, input_method); |
| 754 | |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 755 | if (input_method->input_method_binding != NULL) { |
| 756 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 757 | "interface object already bound"); |
| 758 | wl_resource_destroy(resource); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 762 | if (text_backend->input_method.client != client) { |
| 763 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 764 | "permission to bind desktop_shell denied"); |
| 765 | wl_resource_destroy(resource); |
| 766 | return; |
| 767 | } |
| 768 | |
| 769 | resource->destroy = unbind_input_method; |
| 770 | input_method->input_method_binding = resource; |
| 771 | |
| 772 | text_backend->input_method.binding = 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 | } |