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 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 25 | */ |
| 26 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Derek Foreman | d09dbb3 | 2014-12-05 15:38:39 -0600 | [diff] [blame] | 29 | #include <stdbool.h> |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 30 | #include <stdlib.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 31 | #include <stdint.h> |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 32 | #include <string.h> |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 33 | #include <unistd.h> |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 34 | #include <time.h> |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 35 | |
| 36 | #include "compositor.h" |
Giulio Camuffo | fba27fb | 2016-06-02 21:48:10 +0300 | [diff] [blame] | 37 | #include "weston.h" |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 38 | #include "text-input-unstable-v1-server-protocol.h" |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 39 | #include "input-method-unstable-v1-server-protocol.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 40 | #include "shared/helpers.h" |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 41 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 42 | struct text_input_manager; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 43 | struct input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 44 | struct input_method_context; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 45 | struct text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 46 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 47 | struct text_input { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 48 | struct wl_resource *resource; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 49 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 50 | struct weston_compositor *ec; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 51 | |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 52 | struct wl_list input_methods; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 53 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 54 | struct weston_surface *surface; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 55 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 56 | pixman_box32_t cursor_rectangle; |
| 57 | |
Derek Foreman | d09dbb3 | 2014-12-05 15:38:39 -0600 | [diff] [blame] | 58 | bool input_panel_visible; |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 59 | |
| 60 | struct text_input_manager *manager; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 63 | struct text_input_manager { |
| 64 | struct wl_global *text_input_manager_global; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 65 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 66 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 67 | struct text_input *current_panel; |
| 68 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 69 | struct weston_compositor *ec; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct input_method { |
| 73 | struct wl_resource *input_method_binding; |
| 74 | struct wl_global *input_method_global; |
| 75 | struct wl_listener destroy_listener; |
| 76 | |
| 77 | struct weston_seat *seat; |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 78 | struct text_input *input; |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 79 | |
| 80 | struct wl_list link; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 81 | |
| 82 | struct wl_listener keyboard_focus_listener; |
| 83 | |
Derek Foreman | ddc2c97 | 2015-07-15 13:00:32 -0500 | [diff] [blame] | 84 | bool focus_listener_initialized; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 85 | |
| 86 | struct input_method_context *context; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 87 | |
| 88 | struct text_backend *text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 91 | struct input_method_context { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 92 | struct wl_resource *resource; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 93 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 94 | struct text_input *input; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 95 | struct input_method *input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 96 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 97 | struct wl_resource *keyboard; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 100 | struct text_backend { |
| 101 | struct weston_compositor *compositor; |
| 102 | |
| 103 | struct { |
| 104 | char *path; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 105 | struct wl_client *client; |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 106 | |
| 107 | unsigned deathcount; |
| 108 | uint32_t deathstamp; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 109 | } input_method; |
| 110 | |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 111 | struct wl_listener client_listener; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 112 | struct wl_listener seat_created_listener; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
Derek Foreman | cb5fcea | 2014-12-05 15:38:37 -0600 | [diff] [blame] | 115 | static void |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 116 | input_method_context_create(struct text_input *input, |
Derek Foreman | cb5fcea | 2014-12-05 15:38:37 -0600 | [diff] [blame] | 117 | struct input_method *input_method); |
| 118 | static void |
| 119 | input_method_context_end_keyboard_grab(struct input_method_context *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 120 | |
Derek Foreman | cb5fcea | 2014-12-05 15:38:37 -0600 | [diff] [blame] | 121 | static void |
| 122 | input_method_init_seat(struct weston_seat *seat); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 123 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 124 | static void |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 125 | deactivate_input_method(struct input_method *input_method) |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 126 | { |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 127 | struct text_input *text_input = input_method->input; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 128 | struct weston_compositor *ec = text_input->ec; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 129 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 130 | if (input_method->context && input_method->input_method_binding) { |
| 131 | input_method_context_end_keyboard_grab(input_method->context); |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 132 | zwp_input_method_v1_send_deactivate( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 133 | input_method->input_method_binding, |
| 134 | input_method->context->resource); |
Daniel Stone | 97863d6 | 2016-11-10 15:47:56 +0000 | [diff] [blame] | 135 | input_method->context->input = NULL; |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 136 | } |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 137 | |
| 138 | wl_list_remove(&input_method->link); |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 139 | input_method->input = NULL; |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 140 | input_method->context = NULL; |
| 141 | |
| 142 | if (wl_list_empty(&text_input->input_methods) && |
| 143 | text_input->input_panel_visible) { |
| 144 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
| 145 | text_input->input_panel_visible = false; |
| 146 | text_input->manager->current_panel = NULL; |
| 147 | } |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 148 | zwp_text_input_v1_send_leave(text_input->resource); |
Philipp Brüschweiler | 1746781 | 2012-07-11 22:25:30 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 152 | destroy_text_input(struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 153 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 154 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 155 | struct input_method *input_method, *next; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 156 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 157 | wl_list_for_each_safe(input_method, next, |
| 158 | &text_input->input_methods, link) |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 159 | deactivate_input_method(input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 160 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 161 | free(text_input); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 165 | text_input_set_surrounding_text(struct wl_client *client, |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 166 | struct wl_resource *resource, |
Jan Arne Petersen | cb08f4d | 2012-09-09 23:08:40 +0200 | [diff] [blame] | 167 | const char *text, |
| 168 | uint32_t cursor, |
| 169 | uint32_t anchor) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 170 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 171 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 172 | struct input_method *input_method, *next; |
| 173 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 174 | wl_list_for_each_safe(input_method, next, |
| 175 | &text_input->input_methods, link) { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 176 | if (!input_method->context) |
| 177 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 178 | zwp_input_method_context_v1_send_surrounding_text( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 179 | input_method->context->resource, text, cursor, anchor); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 180 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 184 | text_input_activate(struct wl_client *client, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 185 | struct wl_resource *resource, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 186 | struct wl_resource *seat, |
| 187 | struct wl_resource *surface) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 188 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 189 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 190 | struct weston_seat *weston_seat = wl_resource_get_user_data(seat); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 191 | struct input_method *input_method = weston_seat->input_method; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 192 | struct weston_compositor *ec = text_input->ec; |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 193 | struct text_input *current; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 194 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 195 | if (input_method->input == text_input) |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 196 | return; |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 197 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 198 | if (input_method->input) |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 199 | deactivate_input_method(input_method); |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 200 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 201 | input_method->input = text_input; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 202 | wl_list_insert(&text_input->input_methods, &input_method->link); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 203 | input_method_init_seat(weston_seat); |
| 204 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 205 | text_input->surface = wl_resource_get_user_data(surface); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 206 | |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 207 | input_method_context_create(text_input, input_method); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 208 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 209 | current = text_input->manager->current_panel; |
| 210 | |
| 211 | if (current && current != text_input) { |
| 212 | current->input_panel_visible = false; |
| 213 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
| 214 | text_input->manager->current_panel = NULL; |
| 215 | } |
| 216 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 217 | if (text_input->input_panel_visible) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 218 | wl_signal_emit(&ec->show_input_panel_signal, |
| 219 | text_input->surface); |
| 220 | wl_signal_emit(&ec->update_input_panel_signal, |
| 221 | &text_input->cursor_rectangle); |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 222 | text_input->manager->current_panel = text_input; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 223 | } |
Jan Arne Petersen | de3b6a1 | 2012-08-10 16:47:21 +0200 | [diff] [blame] | 224 | |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 225 | zwp_text_input_v1_send_enter(text_input->resource, |
| 226 | text_input->surface->resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 230 | text_input_deactivate(struct wl_client *client, |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 231 | struct wl_resource *resource, |
| 232 | struct wl_resource *seat) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 233 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 234 | struct weston_seat *weston_seat = wl_resource_get_user_data(seat); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 235 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 236 | if (weston_seat->input_method->input) |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 237 | deactivate_input_method(weston_seat->input_method); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 241 | text_input_reset(struct wl_client *client, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 242 | struct wl_resource *resource) |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 243 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 244 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 245 | struct input_method *input_method, *next; |
| 246 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 247 | wl_list_for_each_safe(input_method, next, |
| 248 | &text_input->input_methods, link) { |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 249 | if (!input_method->context) |
| 250 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 251 | zwp_input_method_context_v1_send_reset( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 252 | input_method->context->resource); |
Jan Arne Petersen | c1e481e | 2012-09-09 23:08:46 +0200 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 257 | text_input_set_cursor_rectangle(struct wl_client *client, |
Jan Arne Petersen | 7ef8eff | 2013-04-18 16:47:23 +0200 | [diff] [blame] | 258 | struct wl_resource *resource, |
| 259 | int32_t x, |
| 260 | int32_t y, |
| 261 | int32_t width, |
| 262 | int32_t height) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 263 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 264 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 265 | struct weston_compositor *ec = text_input->ec; |
| 266 | |
| 267 | text_input->cursor_rectangle.x1 = x; |
| 268 | text_input->cursor_rectangle.y1 = y; |
| 269 | text_input->cursor_rectangle.x2 = x + width; |
| 270 | text_input->cursor_rectangle.y2 = y + height; |
| 271 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 272 | wl_signal_emit(&ec->update_input_panel_signal, |
| 273 | &text_input->cursor_rectangle); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 277 | text_input_set_content_type(struct wl_client *client, |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 278 | struct wl_resource *resource, |
| 279 | uint32_t hint, |
| 280 | uint32_t purpose) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 281 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 282 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 283 | struct input_method *input_method, *next; |
| 284 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 285 | wl_list_for_each_safe(input_method, next, |
| 286 | &text_input->input_methods, link) { |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 287 | if (!input_method->context) |
| 288 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 289 | zwp_input_method_context_v1_send_content_type( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 290 | input_method->context->resource, hint, purpose); |
Jan Arne Petersen | 26ffa81 | 2013-01-16 21:26:43 +0100 | [diff] [blame] | 291 | } |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 294 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 295 | text_input_invoke_action(struct wl_client *client, |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 296 | struct wl_resource *resource, |
| 297 | uint32_t button, |
| 298 | uint32_t index) |
| 299 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 300 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 301 | struct input_method *input_method, *next; |
| 302 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 303 | wl_list_for_each_safe(input_method, next, |
| 304 | &text_input->input_methods, link) { |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 305 | if (!input_method->context) |
| 306 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 307 | zwp_input_method_context_v1_send_invoke_action( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 308 | input_method->context->resource, button, index); |
Jan Arne Petersen | adfedc1 | 2013-01-16 21:26:46 +0100 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 312 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 313 | text_input_commit_state(struct wl_client *client, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 314 | struct wl_resource *resource, |
| 315 | uint32_t serial) |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 316 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 317 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 318 | struct input_method *input_method, *next; |
| 319 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 320 | wl_list_for_each_safe(input_method, next, |
| 321 | &text_input->input_methods, link) { |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 322 | if (!input_method->context) |
| 323 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 324 | zwp_input_method_context_v1_send_commit_state( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 325 | input_method->context->resource, serial); |
Jan Arne Petersen | 0eabcaa | 2013-01-31 15:52:20 +0100 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 329 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 330 | text_input_show_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 331 | struct wl_resource *resource) |
| 332 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 333 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 334 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 335 | |
Derek Foreman | d09dbb3 | 2014-12-05 15:38:39 -0600 | [diff] [blame] | 336 | text_input->input_panel_visible = true; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 337 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 338 | if (!wl_list_empty(&text_input->input_methods)) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 339 | wl_signal_emit(&ec->show_input_panel_signal, |
| 340 | text_input->surface); |
| 341 | wl_signal_emit(&ec->update_input_panel_signal, |
| 342 | &text_input->cursor_rectangle); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 343 | } |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 347 | text_input_hide_input_panel(struct wl_client *client, |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 348 | struct wl_resource *resource) |
| 349 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 350 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 351 | struct weston_compositor *ec = text_input->ec; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 352 | |
Derek Foreman | d09dbb3 | 2014-12-05 15:38:39 -0600 | [diff] [blame] | 353 | text_input->input_panel_visible = false; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 354 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 355 | if (!wl_list_empty(&text_input->input_methods) && |
| 356 | text_input == text_input->manager->current_panel) { |
| 357 | text_input->manager->current_panel = NULL; |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 358 | wl_signal_emit(&ec->hide_input_panel_signal, ec); |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 359 | } |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 362 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 363 | text_input_set_preferred_language(struct wl_client *client, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 364 | struct wl_resource *resource, |
| 365 | const char *language) |
| 366 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 367 | struct text_input *text_input = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 368 | struct input_method *input_method, *next; |
| 369 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 370 | wl_list_for_each_safe(input_method, next, |
| 371 | &text_input->input_methods, link) { |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 372 | if (!input_method->context) |
| 373 | continue; |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 374 | zwp_input_method_context_v1_send_preferred_language( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 375 | input_method->context->resource, language); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 379 | static const struct zwp_text_input_v1_interface text_input_implementation = { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 380 | text_input_activate, |
| 381 | text_input_deactivate, |
| 382 | text_input_show_input_panel, |
| 383 | text_input_hide_input_panel, |
| 384 | text_input_reset, |
| 385 | text_input_set_surrounding_text, |
| 386 | text_input_set_content_type, |
| 387 | text_input_set_cursor_rectangle, |
| 388 | text_input_set_preferred_language, |
| 389 | text_input_commit_state, |
| 390 | text_input_invoke_action |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 391 | }; |
| 392 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 393 | 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] | 394 | struct wl_resource *resource, |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 395 | uint32_t id) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 396 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 397 | struct text_input_manager *text_input_manager = |
| 398 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 399 | struct text_input *text_input; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 400 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 401 | text_input = zalloc(sizeof *text_input); |
| 402 | if (text_input == NULL) |
| 403 | return; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 404 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 405 | text_input->resource = |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 406 | wl_resource_create(client, &zwp_text_input_v1_interface, 1, id); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 407 | wl_resource_set_implementation(text_input->resource, |
| 408 | &text_input_implementation, |
| 409 | text_input, destroy_text_input); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 410 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 411 | text_input->ec = text_input_manager->ec; |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 412 | text_input->manager = text_input_manager; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 413 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 414 | wl_list_init(&text_input->input_methods); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 415 | }; |
| 416 | |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 417 | static const struct zwp_text_input_manager_v1_interface manager_implementation = { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 418 | text_input_manager_create_text_input |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 422 | bind_text_input_manager(struct wl_client *client, |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 423 | void *data, |
| 424 | uint32_t version, |
| 425 | uint32_t id) |
| 426 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 427 | struct text_input_manager *text_input_manager = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 428 | struct wl_resource *resource; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 429 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 430 | /* No checking for duplicate binding necessary. */ |
| 431 | resource = |
| 432 | wl_resource_create(client, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 433 | &zwp_text_input_manager_v1_interface, 1, id); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 434 | if (resource) |
| 435 | wl_resource_set_implementation(resource, |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 436 | &manager_implementation, |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 437 | text_input_manager, NULL); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 441 | text_input_manager_notifier_destroy(struct wl_listener *listener, void *data) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 442 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 443 | struct text_input_manager *text_input_manager = |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 444 | container_of(listener, |
| 445 | struct text_input_manager, |
| 446 | destroy_listener); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 447 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 448 | wl_global_destroy(text_input_manager->text_input_manager_global); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 449 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 450 | free(text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 451 | } |
| 452 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 453 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 454 | text_input_manager_create(struct weston_compositor *ec) |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 455 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 456 | struct text_input_manager *text_input_manager; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 457 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 458 | text_input_manager = zalloc(sizeof *text_input_manager); |
| 459 | if (text_input_manager == NULL) |
| 460 | return; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 461 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 462 | text_input_manager->ec = ec; |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 463 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 464 | text_input_manager->text_input_manager_global = |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 465 | wl_global_create(ec->wl_display, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 466 | &zwp_text_input_manager_v1_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 467 | text_input_manager, bind_text_input_manager); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 468 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 469 | text_input_manager->destroy_listener.notify = |
| 470 | text_input_manager_notifier_destroy; |
| 471 | wl_signal_add(&ec->destroy_signal, |
| 472 | &text_input_manager->destroy_listener); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 475 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 476 | input_method_context_destroy(struct wl_client *client, |
| 477 | struct wl_resource *resource) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 478 | { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 479 | wl_resource_destroy(resource); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 482 | static void |
| 483 | input_method_context_commit_string(struct wl_client *client, |
| 484 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 485 | uint32_t serial, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 486 | const char *text) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 487 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 488 | struct input_method_context *context = |
| 489 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 490 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 491 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 492 | zwp_text_input_v1_send_commit_string(context->input->resource, |
| 493 | serial, text); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 494 | } |
| 495 | |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 496 | static void |
| 497 | input_method_context_preedit_string(struct wl_client *client, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 498 | struct wl_resource *resource, |
Jan Arne Petersen | c7d2a98 | 2013-01-16 21:26:39 +0100 | [diff] [blame] | 499 | uint32_t serial, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 500 | const char *text, |
| 501 | const char *commit) |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 502 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 503 | struct input_method_context *context = |
| 504 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 505 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 506 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 507 | zwp_text_input_v1_send_preedit_string(context->input->resource, |
| 508 | serial, text, commit); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void |
| 512 | input_method_context_preedit_styling(struct wl_client *client, |
| 513 | struct wl_resource *resource, |
| 514 | uint32_t index, |
| 515 | uint32_t length, |
| 516 | uint32_t style) |
| 517 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 518 | struct input_method_context *context = |
| 519 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 520 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 521 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 522 | zwp_text_input_v1_send_preedit_styling(context->input->resource, |
| 523 | index, length, style); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void |
| 527 | input_method_context_preedit_cursor(struct wl_client *client, |
| 528 | struct wl_resource *resource, |
| 529 | int32_t cursor) |
| 530 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 531 | struct input_method_context *context = |
| 532 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 533 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 534 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 535 | zwp_text_input_v1_send_preedit_cursor(context->input->resource, |
| 536 | cursor); |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 537 | } |
| 538 | |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 539 | static void |
| 540 | input_method_context_delete_surrounding_text(struct wl_client *client, |
| 541 | struct wl_resource *resource, |
| 542 | int32_t index, |
| 543 | uint32_t length) |
| 544 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 545 | struct input_method_context *context = |
| 546 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 547 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 548 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 549 | zwp_text_input_v1_send_delete_surrounding_text( |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 550 | context->input->resource, index, length); |
Jan Arne Petersen | e202bae | 2012-09-09 23:08:44 +0200 | [diff] [blame] | 551 | } |
| 552 | |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 553 | static void |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 554 | input_method_context_cursor_position(struct wl_client *client, |
| 555 | struct wl_resource *resource, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 556 | int32_t index, |
| 557 | int32_t anchor) |
| 558 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 559 | struct input_method_context *context = |
| 560 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 561 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 562 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 563 | zwp_text_input_v1_send_cursor_position(context->input->resource, |
| 564 | index, anchor); |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 568 | input_method_context_modifiers_map(struct wl_client *client, |
| 569 | struct wl_resource *resource, |
| 570 | struct wl_array *map) |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 571 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 572 | struct input_method_context *context = |
| 573 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 574 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 575 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 576 | zwp_text_input_v1_send_modifiers_map(context->input->resource, |
| 577 | map); |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static void |
| 581 | input_method_context_keysym(struct wl_client *client, |
| 582 | struct wl_resource *resource, |
| 583 | uint32_t serial, |
| 584 | uint32_t time, |
| 585 | uint32_t sym, |
| 586 | uint32_t state, |
| 587 | uint32_t modifiers) |
| 588 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 589 | struct input_method_context *context = |
| 590 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 591 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 592 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 593 | zwp_text_input_v1_send_keysym(context->input->resource, |
| 594 | serial, time, |
| 595 | sym, state, modifiers); |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 598 | static void |
| 599 | unbind_keyboard(struct wl_resource *resource) |
| 600 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 601 | struct input_method_context *context = |
| 602 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 603 | |
| 604 | input_method_context_end_keyboard_grab(context); |
| 605 | context->keyboard = NULL; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 609 | input_method_context_grab_key(struct weston_keyboard_grab *grab, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 610 | uint32_t time, uint32_t key, uint32_t state_w) |
| 611 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 612 | struct weston_keyboard *keyboard = grab->keyboard; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 613 | struct wl_display *display; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 614 | uint32_t serial; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 615 | |
| 616 | if (!keyboard->input_method_resource) |
| 617 | return; |
| 618 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 619 | display = wl_client_get_display( |
| 620 | wl_resource_get_client(keyboard->input_method_resource)); |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 621 | serial = wl_display_next_serial(display); |
| 622 | wl_keyboard_send_key(keyboard->input_method_resource, |
| 623 | serial, time, key, state_w); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static void |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 627 | input_method_context_grab_modifier(struct weston_keyboard_grab *grab, |
| 628 | uint32_t serial, |
| 629 | uint32_t mods_depressed, |
| 630 | uint32_t mods_latched, |
| 631 | uint32_t mods_locked, |
| 632 | uint32_t group) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 633 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 634 | struct weston_keyboard *keyboard = grab->keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 635 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 636 | if (!keyboard->input_method_resource) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 637 | return; |
| 638 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 639 | wl_keyboard_send_modifiers(keyboard->input_method_resource, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 640 | serial, mods_depressed, mods_latched, |
| 641 | mods_locked, group); |
| 642 | } |
| 643 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 644 | static void |
| 645 | input_method_context_grab_cancel(struct weston_keyboard_grab *grab) |
| 646 | { |
| 647 | weston_keyboard_end_grab(grab->keyboard); |
| 648 | } |
| 649 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 650 | static const struct weston_keyboard_grab_interface input_method_context_grab = { |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 651 | input_method_context_grab_key, |
| 652 | input_method_context_grab_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 653 | input_method_context_grab_cancel, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | static void |
| 657 | input_method_context_grab_keyboard(struct wl_client *client, |
| 658 | struct wl_resource *resource, |
| 659 | uint32_t id) |
| 660 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 661 | struct input_method_context *context = |
| 662 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 663 | struct wl_resource *cr; |
| 664 | struct weston_seat *seat = context->input_method->seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 665 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 666 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 667 | cr = wl_resource_create(client, &wl_keyboard_interface, 1, id); |
| 668 | wl_resource_set_implementation(cr, NULL, context, unbind_keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 669 | |
| 670 | context->keyboard = cr; |
| 671 | |
| 672 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 673 | keyboard->xkb_info->keymap_fd, |
| 674 | keyboard->xkb_info->keymap_size); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 675 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 676 | if (keyboard->grab != &keyboard->default_grab) { |
| 677 | weston_keyboard_end_grab(keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 678 | } |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 679 | weston_keyboard_start_grab(keyboard, &keyboard->input_method_grab); |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 680 | keyboard->input_method_resource = cr; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 683 | static void |
| 684 | input_method_context_key(struct wl_client *client, |
| 685 | struct wl_resource *resource, |
| 686 | uint32_t serial, |
| 687 | uint32_t time, |
| 688 | uint32_t key, |
| 689 | uint32_t state_w) |
| 690 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 691 | struct input_method_context *context = |
| 692 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 693 | struct weston_seat *seat = context->input_method->seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 694 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 695 | struct weston_keyboard_grab *default_grab = &keyboard->default_grab; |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 696 | |
| 697 | default_grab->interface->key(default_grab, time, key, state_w); |
| 698 | } |
| 699 | |
| 700 | static void |
| 701 | input_method_context_modifiers(struct wl_client *client, |
| 702 | struct wl_resource *resource, |
| 703 | uint32_t serial, |
| 704 | uint32_t mods_depressed, |
| 705 | uint32_t mods_latched, |
| 706 | uint32_t mods_locked, |
| 707 | uint32_t group) |
| 708 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 709 | struct input_method_context *context = |
| 710 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 711 | |
| 712 | struct weston_seat *seat = context->input_method->seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 713 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 714 | struct weston_keyboard_grab *default_grab = &keyboard->default_grab; |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 715 | |
| 716 | default_grab->interface->modifiers(default_grab, |
| 717 | serial, mods_depressed, |
| 718 | mods_latched, mods_locked, |
| 719 | group); |
| 720 | } |
| 721 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 722 | static void |
| 723 | input_method_context_language(struct wl_client *client, |
| 724 | struct wl_resource *resource, |
| 725 | uint32_t serial, |
| 726 | const char *language) |
| 727 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 728 | struct input_method_context *context = |
| 729 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 730 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 731 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 732 | zwp_text_input_v1_send_language(context->input->resource, |
| 733 | serial, language); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void |
| 737 | input_method_context_text_direction(struct wl_client *client, |
| 738 | struct wl_resource *resource, |
| 739 | uint32_t serial, |
| 740 | uint32_t direction) |
| 741 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 742 | struct input_method_context *context = |
| 743 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 744 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 745 | if (context->input) |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 746 | zwp_text_input_v1_send_text_direction(context->input->resource, |
| 747 | serial, direction); |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 751 | static const struct zwp_input_method_context_v1_interface context_implementation = { |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 752 | input_method_context_destroy, |
Jan Arne Petersen | 43f4aa8 | 2012-09-09 23:08:43 +0200 | [diff] [blame] | 753 | input_method_context_commit_string, |
| 754 | input_method_context_preedit_string, |
Jan Arne Petersen | 4653531 | 2013-01-16 21:26:38 +0100 | [diff] [blame] | 755 | input_method_context_preedit_styling, |
| 756 | input_method_context_preedit_cursor, |
Jan Arne Petersen | ce8a443 | 2012-09-09 23:08:45 +0200 | [diff] [blame] | 757 | input_method_context_delete_surrounding_text, |
Jan Arne Petersen | 1cc9e08 | 2013-01-31 15:52:23 +0100 | [diff] [blame] | 758 | input_method_context_cursor_position, |
Jan Arne Petersen | d9be93b | 2012-11-18 19:06:43 +0100 | [diff] [blame] | 759 | input_method_context_modifiers_map, |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 760 | input_method_context_keysym, |
Jan Arne Petersen | 337df95 | 2012-11-18 19:06:46 +0100 | [diff] [blame] | 761 | input_method_context_grab_keyboard, |
| 762 | input_method_context_key, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 763 | input_method_context_modifiers, |
| 764 | input_method_context_language, |
| 765 | input_method_context_text_direction |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 766 | }; |
| 767 | |
| 768 | static void |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 769 | destroy_input_method_context(struct wl_resource *resource) |
| 770 | { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 771 | struct input_method_context *context = |
| 772 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 773 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 774 | if (context->keyboard) |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 775 | wl_resource_destroy(context->keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 776 | |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 777 | if (context->input_method && context->input_method->context == context) |
| 778 | context->input_method->context = NULL; |
| 779 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 780 | free(context); |
| 781 | } |
| 782 | |
| 783 | static void |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 784 | input_method_context_create(struct text_input *input, |
Jan Arne Petersen | 00191c7 | 2013-04-18 16:47:33 +0200 | [diff] [blame] | 785 | struct input_method *input_method) |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 786 | { |
| 787 | struct input_method_context *context; |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 788 | struct wl_resource *binding; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 789 | |
| 790 | if (!input_method->input_method_binding) |
| 791 | return; |
| 792 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 793 | context = zalloc(sizeof *context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 794 | if (context == NULL) |
| 795 | return; |
| 796 | |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 797 | binding = input_method->input_method_binding; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 798 | context->resource = |
| 799 | wl_resource_create(wl_resource_get_client(binding), |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 800 | &zwp_input_method_context_v1_interface, |
| 801 | 1, 0); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 802 | wl_resource_set_implementation(context->resource, |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 803 | &context_implementation, |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 804 | context, destroy_input_method_context); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 805 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 806 | context->input = input; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 807 | context->input_method = input_method; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 808 | input_method->context = context; |
| 809 | |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 810 | |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 811 | zwp_input_method_v1_send_activate(binding, context->resource); |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static void |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 815 | input_method_context_end_keyboard_grab(struct input_method_context *context) |
| 816 | { |
Derek Foreman | f0aaa41 | 2014-12-08 10:48:29 -0600 | [diff] [blame] | 817 | struct weston_keyboard_grab *grab; |
| 818 | struct weston_keyboard *keyboard; |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 819 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 820 | keyboard = weston_seat_get_keyboard(context->input_method->seat); |
| 821 | if (!keyboard) |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 822 | return; |
| 823 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 824 | grab = &keyboard->input_method_grab; |
Derek Foreman | f0aaa41 | 2014-12-08 10:48:29 -0600 | [diff] [blame] | 825 | keyboard = grab->keyboard; |
| 826 | if (!keyboard) |
| 827 | return; |
| 828 | |
| 829 | if (keyboard->grab == grab) |
| 830 | weston_keyboard_end_grab(keyboard); |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 831 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 832 | keyboard->input_method_resource = NULL; |
| 833 | } |
Jan Arne Petersen | 466b9c1 | 2012-11-18 19:06:45 +0100 | [diff] [blame] | 834 | |
| 835 | static void |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 836 | unbind_input_method(struct wl_resource *resource) |
| 837 | { |
Jason Ekstrand | 89d3199 | 2013-06-14 10:07:59 -0500 | [diff] [blame] | 838 | struct input_method *input_method = wl_resource_get_user_data(resource); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 839 | |
| 840 | input_method->input_method_binding = NULL; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 841 | input_method->context = NULL; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 845 | bind_input_method(struct wl_client *client, |
| 846 | void *data, |
| 847 | uint32_t version, |
| 848 | uint32_t id) |
| 849 | { |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 850 | struct input_method *input_method = data; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 851 | struct text_backend *text_backend = input_method->text_backend; |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 852 | struct wl_resource *resource; |
| 853 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 854 | resource = |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 855 | wl_resource_create(client, |
| 856 | &zwp_input_method_v1_interface, 1, id); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 857 | |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 858 | if (input_method->input_method_binding != NULL) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 859 | wl_resource_post_error(resource, |
| 860 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 861 | "interface object already bound"); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 862 | return; |
| 863 | } |
| 864 | |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 865 | if (text_backend->input_method.client != client) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 866 | wl_resource_post_error(resource, |
| 867 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 868 | "permission to bind " |
| 869 | "input_method denied"); |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 870 | return; |
| 871 | } |
| 872 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 873 | wl_resource_set_implementation(resource, NULL, input_method, |
| 874 | unbind_input_method); |
Jan Arne Petersen | b41531a | 2013-04-18 16:47:31 +0200 | [diff] [blame] | 875 | input_method->input_method_binding = resource; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static void |
| 879 | input_method_notifier_destroy(struct wl_listener *listener, void *data) |
| 880 | { |
Kristian Høgsberg | f97f379 | 2012-07-22 11:51:42 -0400 | [diff] [blame] | 881 | struct input_method *input_method = |
| 882 | container_of(listener, struct input_method, destroy_listener); |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 883 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 884 | if (input_method->input) |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 885 | deactivate_input_method(input_method); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 886 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 887 | wl_global_destroy(input_method->input_method_global); |
Rob Bradford | ead3ef8 | 2013-07-24 16:57:32 +0100 | [diff] [blame] | 888 | wl_list_remove(&input_method->destroy_listener.link); |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 889 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 890 | free(input_method); |
| 891 | } |
| 892 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 893 | static void |
| 894 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 895 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 896 | struct weston_keyboard *keyboard = data; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 897 | struct input_method *input_method = |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 898 | container_of(listener, struct input_method, |
| 899 | keyboard_focus_listener); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 900 | struct weston_surface *surface = keyboard->focus; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 901 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 902 | if (!input_method->input) |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 903 | return; |
| 904 | |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 905 | if (!surface || input_method->input->surface != surface) |
Derek Foreman | 516d603 | 2015-05-08 17:08:40 -0500 | [diff] [blame] | 906 | deactivate_input_method(input_method); |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | static void |
| 910 | input_method_init_seat(struct weston_seat *seat) |
| 911 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 912 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
| 913 | |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 914 | if (seat->input_method->focus_listener_initialized) |
| 915 | return; |
| 916 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 917 | if (keyboard) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 918 | seat->input_method->keyboard_focus_listener.notify = |
| 919 | handle_keyboard_focus; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 920 | wl_signal_add(&keyboard->focus_signal, |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 921 | &seat->input_method->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 922 | keyboard->input_method_grab.interface = |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 923 | &input_method_context_grab; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 924 | } |
| 925 | |
Derek Foreman | ddc2c97 | 2015-07-15 13:00:32 -0500 | [diff] [blame] | 926 | seat->input_method->focus_listener_initialized = true; |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 927 | } |
| 928 | |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 929 | static void launch_input_method(struct text_backend *text_backend); |
| 930 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 931 | static void |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 932 | respawn_input_method_process(struct text_backend *text_backend) |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 933 | { |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 934 | uint32_t time; |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 935 | |
| 936 | /* if input_method dies more than 5 times in 10 seconds, give up */ |
| 937 | time = weston_compositor_get_time(); |
| 938 | if (time - text_backend->input_method.deathstamp > 10000) { |
| 939 | text_backend->input_method.deathstamp = time; |
| 940 | text_backend->input_method.deathcount = 0; |
| 941 | } |
| 942 | |
| 943 | text_backend->input_method.deathcount++; |
| 944 | if (text_backend->input_method.deathcount > 5) { |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 945 | weston_log("input_method disconnected, giving up.\n"); |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 946 | return; |
| 947 | } |
| 948 | |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 949 | weston_log("input_method disconnected, respawning...\n"); |
Eduardo Lima (Etrunko) | 2733700 | 2013-05-14 13:09:31 -0300 | [diff] [blame] | 950 | launch_input_method(text_backend); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static void |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 954 | input_method_client_notifier(struct wl_listener *listener, void *data) |
| 955 | { |
| 956 | struct text_backend *text_backend; |
| 957 | |
| 958 | text_backend = container_of(listener, struct text_backend, |
| 959 | client_listener); |
| 960 | |
| 961 | text_backend->input_method.client = NULL; |
| 962 | respawn_input_method_process(text_backend); |
| 963 | } |
| 964 | |
| 965 | static void |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 966 | launch_input_method(struct text_backend *text_backend) |
| 967 | { |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 968 | if (!text_backend->input_method.path) |
| 969 | return; |
| 970 | |
Murray Calavera | f65f89b | 2015-06-09 20:28:06 +0000 | [diff] [blame] | 971 | if (strcmp(text_backend->input_method.path, "") == 0) |
| 972 | return; |
| 973 | |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 974 | text_backend->input_method.client = |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 975 | weston_client_start(text_backend->compositor, |
| 976 | text_backend->input_method.path); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 977 | |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 978 | if (!text_backend->input_method.client) { |
Murray Calavera | 972d1af | 2015-06-09 20:29:28 +0000 | [diff] [blame] | 979 | weston_log("not able to start %s\n", |
| 980 | text_backend->input_method.path); |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 981 | return; |
| 982 | } |
| 983 | |
| 984 | text_backend->client_listener.notify = input_method_client_notifier; |
| 985 | wl_client_add_destroy_listener(text_backend->input_method.client, |
| 986 | &text_backend->client_listener); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | static void |
Murray Calavera | 2588124 | 2015-06-10 21:15:30 +0000 | [diff] [blame] | 990 | text_backend_seat_created(struct text_backend *text_backend, |
| 991 | struct weston_seat *seat) |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 992 | { |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 993 | struct input_method *input_method; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 994 | struct weston_compositor *ec = seat->compositor; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 995 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 996 | input_method = zalloc(sizeof *input_method); |
| 997 | if (input_method == NULL) |
| 998 | return; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 999 | |
Philipp Brüschweiler | b13b9ff | 2012-09-09 23:08:31 +0200 | [diff] [blame] | 1000 | input_method->seat = seat; |
Derek Foreman | 0f29923 | 2015-05-08 17:08:41 -0500 | [diff] [blame] | 1001 | input_method->input = NULL; |
Derek Foreman | ddc2c97 | 2015-07-15 13:00:32 -0500 | [diff] [blame] | 1002 | input_method->focus_listener_initialized = false; |
Jan Arne Petersen | 620cd62 | 2012-09-09 23:08:32 +0200 | [diff] [blame] | 1003 | input_method->context = NULL; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1004 | input_method->text_backend = text_backend; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 1005 | |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 1006 | input_method->input_method_global = |
Jonas Ådahl | b57f472 | 2015-11-17 16:00:30 +0800 | [diff] [blame] | 1007 | wl_global_create(ec->wl_display, |
| 1008 | &zwp_input_method_v1_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 1009 | input_method, bind_input_method); |
Philipp Brüschweiler | f25602b | 2012-07-11 22:25:31 +0200 | [diff] [blame] | 1010 | |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 1011 | input_method->destroy_listener.notify = input_method_notifier_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 1012 | wl_signal_add(&seat->destroy_signal, &input_method->destroy_listener); |
Jan Arne Petersen | e829adc | 2012-08-10 16:47:22 +0200 | [diff] [blame] | 1013 | |
| 1014 | seat->input_method = input_method; |
Jan Arne Petersen | 1f17be4 | 2012-06-21 21:52:18 +0200 | [diff] [blame] | 1015 | } |
Jan Arne Petersen | cd8cdcc | 2012-08-10 16:47:23 +0200 | [diff] [blame] | 1016 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1017 | static void |
Murray Calavera | 2588124 | 2015-06-10 21:15:30 +0000 | [diff] [blame] | 1018 | handle_seat_created(struct wl_listener *listener, void *data) |
| 1019 | { |
| 1020 | struct weston_seat *seat = data; |
| 1021 | struct text_backend *text_backend = |
| 1022 | container_of(listener, struct text_backend, |
| 1023 | seat_created_listener); |
| 1024 | |
| 1025 | text_backend_seat_created(text_backend, seat); |
| 1026 | } |
| 1027 | |
| 1028 | static void |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1029 | text_backend_configuration(struct text_backend *text_backend) |
| 1030 | { |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 1031 | struct weston_config *config = wet_get_config(text_backend->compositor); |
Kristian Høgsberg | 00fd7b8 | 2013-05-23 21:45:51 -0400 | [diff] [blame] | 1032 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 1033 | char *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 1034 | int ret; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1035 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 1036 | section = weston_config_get_section(config, |
Kristian Høgsberg | 00fd7b8 | 2013-05-23 21:45:51 -0400 | [diff] [blame] | 1037 | "input-method", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 1038 | ret = asprintf(&client, "%s/weston-keyboard", |
| 1039 | weston_config_get_libexec_dir()); |
| 1040 | if (ret < 0) |
| 1041 | client = NULL; |
Kristian Høgsberg | 00fd7b8 | 2013-05-23 21:45:51 -0400 | [diff] [blame] | 1042 | weston_config_section_get_string(section, "path", |
| 1043 | &text_backend->input_method.path, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 1044 | client); |
| 1045 | free(client); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 1048 | WL_EXPORT void |
| 1049 | text_backend_destroy(struct text_backend *text_backend) |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1050 | { |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 1051 | if (text_backend->input_method.client) { |
| 1052 | /* disable respawn */ |
| 1053 | wl_list_remove(&text_backend->client_listener.link); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1054 | wl_client_destroy(text_backend->input_method.client); |
Derek Foreman | 89dcea9 | 2015-06-25 15:49:49 -0500 | [diff] [blame] | 1055 | } |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1056 | |
| 1057 | free(text_backend->input_method.path); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1058 | free(text_backend); |
| 1059 | } |
| 1060 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 1061 | WL_EXPORT struct text_backend * |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1062 | text_backend_init(struct weston_compositor *ec) |
| 1063 | { |
| 1064 | struct text_backend *text_backend; |
Murray Calavera | 2588124 | 2015-06-10 21:15:30 +0000 | [diff] [blame] | 1065 | struct weston_seat *seat; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1066 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 1067 | text_backend = zalloc(sizeof(*text_backend)); |
| 1068 | if (text_backend == NULL) |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 1069 | return NULL; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1070 | |
| 1071 | text_backend->compositor = ec; |
| 1072 | |
Murray Calavera | 2588124 | 2015-06-10 21:15:30 +0000 | [diff] [blame] | 1073 | text_backend_configuration(text_backend); |
| 1074 | |
| 1075 | wl_list_for_each(seat, &ec->seat_list, link) |
| 1076 | text_backend_seat_created(text_backend, seat); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1077 | text_backend->seat_created_listener.notify = handle_seat_created; |
| 1078 | wl_signal_add(&ec->seat_created_signal, |
| 1079 | &text_backend->seat_created_listener); |
| 1080 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 1081 | text_input_manager_create(ec); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1082 | |
Derek Foreman | b4bacd2 | 2015-06-25 15:49:47 -0500 | [diff] [blame] | 1083 | launch_input_method(text_backend); |
| 1084 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 1085 | return text_backend; |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 1086 | } |