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