2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 #include <linux/input.h>
28 #include "weston-test-client-helper.h"
29 #include "text-client-protocol.h"
31 struct text_input_state {
37 text_input_commit_string(void *data,
38 struct wl_text_input *text_input,
45 text_input_preedit_string(void *data,
46 struct wl_text_input *text_input,
54 text_input_delete_surrounding_text(void *data,
55 struct wl_text_input *text_input,
62 text_input_cursor_position(void *data,
63 struct wl_text_input *text_input,
70 text_input_preedit_styling(void *data,
71 struct wl_text_input *text_input,
79 text_input_preedit_cursor(void *data,
80 struct wl_text_input *text_input,
86 text_input_modifiers_map(void *data,
87 struct wl_text_input *text_input,
93 text_input_keysym(void *data,
94 struct wl_text_input *text_input,
104 text_input_enter(void *data,
105 struct wl_text_input *text_input,
106 struct wl_surface *surface)
109 struct text_input_state *state = data;
111 fprintf(stderr, "%s\n", __FUNCTION__);
113 state->activated += 1;
117 text_input_leave(void *data,
118 struct wl_text_input *text_input)
120 struct text_input_state *state = data;
122 state->deactivated += 1;
126 text_input_input_panel_state(void *data,
127 struct wl_text_input *text_input,
133 text_input_language(void *data,
134 struct wl_text_input *text_input,
136 const char *language)
141 text_input_text_direction(void *data,
142 struct wl_text_input *text_input,
148 static const struct wl_text_input_listener text_input_listener = {
151 text_input_modifiers_map,
152 text_input_input_panel_state,
153 text_input_preedit_string,
154 text_input_preedit_styling,
155 text_input_preedit_cursor,
156 text_input_commit_string,
157 text_input_cursor_position,
158 text_input_delete_surrounding_text,
161 text_input_text_direction
166 struct client *client;
167 struct global *global;
168 struct wl_text_input_manager *factory;
169 struct wl_text_input *text_input;
170 struct text_input_state state;
172 client = client_create(100, 100, 100, 100);
176 wl_list_for_each(global, &client->global_list, link) {
177 if (strcmp(global->interface, "wl_text_input_manager") == 0)
178 factory = wl_registry_bind(client->wl_registry,
180 &wl_text_input_manager_interface, 1);
185 memset(&state, 0, sizeof state);
186 text_input = wl_text_input_manager_create_text_input(factory);
187 wl_text_input_add_listener(text_input, &text_input_listener, &state);
189 /* Make sure our test surface has keyboard focus. */
190 wl_test_activate_surface(client->test->wl_test,
191 client->surface->wl_surface);
192 client_roundtrip(client);
193 assert(client->input->keyboard->focus == client->surface);
195 /* Activate test model and make sure we get enter event. */
196 wl_text_input_activate(text_input, client->input->wl_seat,
197 client->surface->wl_surface);
198 client_roundtrip(client);
199 assert(state.activated == 1 && state.deactivated == 0);
201 /* Deactivate test model and make sure we get leave event. */
202 wl_text_input_deactivate(text_input, client->input->wl_seat);
203 client_roundtrip(client);
204 assert(state.activated == 1 && state.deactivated == 1);
206 /* Activate test model again. */
207 wl_text_input_activate(text_input, client->input->wl_seat,
208 client->surface->wl_surface);
209 client_roundtrip(client);
210 assert(state.activated == 2 && state.deactivated == 1);
212 /* Take keyboard focus away and verify we get leave event. */
213 wl_test_activate_surface(client->test->wl_test, NULL);
214 client_roundtrip(client);
215 assert(state.activated == 2 && state.deactivated == 2);