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