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