Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 1 | /* |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 2 | * Copyright © 2012 Intel Corporation |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 28 | #include <string.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 29 | #include <stdint.h> |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 30 | #include <stdio.h> |
Bryce Harrington | a768026 | 2014-11-19 17:18:34 -0800 | [diff] [blame] | 31 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 32 | #include "weston-test-client-helper.h" |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 33 | #include "text-input-unstable-v1-client-protocol.h" |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 34 | |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 35 | struct text_input_state { |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 36 | int activated; |
| 37 | int deactivated; |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 41 | text_input_commit_string(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 42 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 43 | uint32_t serial, |
| 44 | const char *text) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 45 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 49 | text_input_preedit_string(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 50 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 51 | uint32_t serial, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 52 | const char *text, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 53 | const char *commit) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 54 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 58 | text_input_delete_surrounding_text(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 59 | struct zwp_text_input_v1 *text_input, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 60 | int32_t index, |
| 61 | uint32_t length) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 62 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 66 | text_input_cursor_position(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 67 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 68 | int32_t index, |
| 69 | int32_t anchor) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 74 | text_input_preedit_styling(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 75 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 76 | uint32_t index, |
| 77 | uint32_t length, |
| 78 | uint32_t style) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 83 | text_input_preedit_cursor(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 84 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 85 | int32_t index) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 86 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 90 | text_input_modifiers_map(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 91 | struct zwp_text_input_v1 *text_input, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 92 | struct wl_array *map) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 93 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 97 | text_input_keysym(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 98 | struct zwp_text_input_v1 *text_input, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 99 | uint32_t serial, |
| 100 | uint32_t time, |
| 101 | uint32_t sym, |
| 102 | uint32_t state, |
| 103 | uint32_t modifiers) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 104 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 108 | text_input_enter(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 109 | struct zwp_text_input_v1 *text_input, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 110 | struct wl_surface *surface) |
| 111 | |
| 112 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 113 | struct text_input_state *state = data; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 114 | |
| 115 | fprintf(stderr, "%s\n", __FUNCTION__); |
| 116 | |
| 117 | state->activated += 1; |
| 118 | } |
| 119 | |
| 120 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 121 | text_input_leave(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 122 | struct zwp_text_input_v1 *text_input) |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 123 | { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 124 | struct text_input_state *state = data; |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 125 | |
| 126 | state->deactivated += 1; |
| 127 | } |
| 128 | |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 129 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 130 | text_input_input_panel_state(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 131 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 132 | uint32_t state) |
| 133 | { |
| 134 | } |
| 135 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 136 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 137 | text_input_language(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 138 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 139 | uint32_t serial, |
| 140 | const char *language) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | static void |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 145 | text_input_text_direction(void *data, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 146 | struct zwp_text_input_v1 *text_input, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame] | 147 | uint32_t serial, |
| 148 | uint32_t direction) |
| 149 | { |
| 150 | } |
| 151 | |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 152 | static const struct zwp_text_input_v1_listener text_input_listener = { |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 153 | text_input_enter, |
| 154 | text_input_leave, |
| 155 | text_input_modifiers_map, |
| 156 | text_input_input_panel_state, |
| 157 | text_input_preedit_string, |
| 158 | text_input_preedit_styling, |
| 159 | text_input_preedit_cursor, |
| 160 | text_input_commit_string, |
| 161 | text_input_cursor_position, |
| 162 | text_input_delete_surrounding_text, |
| 163 | text_input_keysym, |
| 164 | text_input_language, |
| 165 | text_input_text_direction |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 166 | }; |
| 167 | |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 168 | TEST(text_test) |
| 169 | { |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 170 | struct client *client; |
| 171 | struct global *global; |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 172 | struct zwp_text_input_manager_v1 *factory; |
| 173 | struct zwp_text_input_v1 *text_input; |
Jan Arne Petersen | 78d00e4 | 2013-04-18 16:47:24 +0200 | [diff] [blame] | 174 | struct text_input_state state; |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 175 | |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 176 | client = create_client_and_test_surface(100, 100, 100, 100); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 177 | assert(client); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 178 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 179 | factory = NULL; |
| 180 | wl_list_for_each(global, &client->global_list, link) { |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 181 | if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0) |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 182 | factory = wl_registry_bind(client->wl_registry, |
| 183 | global->name, |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 184 | &zwp_text_input_manager_v1_interface, 1); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 185 | } |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 186 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 187 | assert(factory); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 188 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 189 | memset(&state, 0, sizeof state); |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 190 | text_input = zwp_text_input_manager_v1_create_text_input(factory); |
| 191 | zwp_text_input_v1_add_listener(text_input, |
| 192 | &text_input_listener, |
| 193 | &state); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 194 | |
| 195 | /* Make sure our test surface has keyboard focus. */ |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 196 | weston_test_activate_surface(client->test->weston_test, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 197 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 198 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 199 | assert(client->input->keyboard->focus == client->surface); |
| 200 | |
| 201 | /* Activate test model and make sure we get enter event. */ |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 202 | zwp_text_input_v1_activate(text_input, client->input->wl_seat, |
| 203 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 204 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 205 | assert(state.activated == 1 && state.deactivated == 0); |
| 206 | |
| 207 | /* Deactivate test model and make sure we get leave event. */ |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 208 | zwp_text_input_v1_deactivate(text_input, client->input->wl_seat); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 209 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 210 | assert(state.activated == 1 && state.deactivated == 1); |
| 211 | |
| 212 | /* Activate test model again. */ |
Jonas Ådahl | 3bcba34 | 2015-11-17 16:00:29 +0800 | [diff] [blame] | 213 | zwp_text_input_v1_activate(text_input, client->input->wl_seat, |
| 214 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 215 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 216 | assert(state.activated == 2 && state.deactivated == 1); |
| 217 | |
| 218 | /* Take keyboard focus away and verify we get leave event. */ |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 219 | weston_test_activate_surface(client->test->weston_test, NULL); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 220 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 221 | assert(state.activated == 2 && state.deactivated == 2); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 222 | } |