2 * Copyright © 2012 Intel Corporation
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:
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.
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
32 #include "weston-test-client-helper.h"
33 #include "text-input-unstable-v1-client-protocol.h"
35 struct text_input_state {
41 text_input_commit_string(void *data,
42 struct zwp_text_input_v1 *text_input,
49 text_input_preedit_string(void *data,
50 struct zwp_text_input_v1 *text_input,
58 text_input_delete_surrounding_text(void *data,
59 struct zwp_text_input_v1 *text_input,
66 text_input_cursor_position(void *data,
67 struct zwp_text_input_v1 *text_input,
74 text_input_preedit_styling(void *data,
75 struct zwp_text_input_v1 *text_input,
83 text_input_preedit_cursor(void *data,
84 struct zwp_text_input_v1 *text_input,
90 text_input_modifiers_map(void *data,
91 struct zwp_text_input_v1 *text_input,
97 text_input_keysym(void *data,
98 struct zwp_text_input_v1 *text_input,
108 text_input_enter(void *data,
109 struct zwp_text_input_v1 *text_input,
110 struct wl_surface *surface)
113 struct text_input_state *state = data;
115 fprintf(stderr, "%s\n", __FUNCTION__);
117 state->activated += 1;
121 text_input_leave(void *data,
122 struct zwp_text_input_v1 *text_input)
124 struct text_input_state *state = data;
126 state->deactivated += 1;
130 text_input_input_panel_state(void *data,
131 struct zwp_text_input_v1 *text_input,
137 text_input_language(void *data,
138 struct zwp_text_input_v1 *text_input,
140 const char *language)
145 text_input_text_direction(void *data,
146 struct zwp_text_input_v1 *text_input,
152 static const struct zwp_text_input_v1_listener text_input_listener = {
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,
165 text_input_text_direction
170 struct client *client;
171 struct global *global;
172 struct zwp_text_input_manager_v1 *factory;
173 struct zwp_text_input_v1 *text_input;
174 struct text_input_state state;
176 client = create_client_and_test_surface(100, 100, 100, 100);
180 wl_list_for_each(global, &client->global_list, link) {
181 if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0)
182 factory = wl_registry_bind(client->wl_registry,
184 &zwp_text_input_manager_v1_interface, 1);
189 memset(&state, 0, sizeof state);
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,
195 /* Make sure our test surface has keyboard focus. */
196 weston_test_activate_surface(client->test->weston_test,
197 client->surface->wl_surface);
198 client_roundtrip(client);
199 assert(client->input->keyboard->focus == client->surface);
201 /* Activate test model and make sure we get enter event. */
202 zwp_text_input_v1_activate(text_input, client->input->wl_seat,
203 client->surface->wl_surface);
204 client_roundtrip(client);
205 assert(state.activated == 1 && state.deactivated == 0);
207 /* Deactivate test model and make sure we get leave event. */
208 zwp_text_input_v1_deactivate(text_input, client->input->wl_seat);
209 client_roundtrip(client);
210 assert(state.activated == 1 && state.deactivated == 1);
212 /* Activate test model again. */
213 zwp_text_input_v1_activate(text_input, client->input->wl_seat,
214 client->surface->wl_surface);
215 client_roundtrip(client);
216 assert(state.activated == 2 && state.deactivated == 1);
218 /* Take keyboard focus away and verify we get leave event. */
219 weston_test_activate_surface(client->test->weston_test, NULL);
220 client_roundtrip(client);
221 assert(state.activated == 2 && state.deactivated == 2);