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