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.
25 #include <linux/input.h>
26 #include "weston-test-client-helper.h"
27 #include "../clients/text-client-protocol.h"
29 struct text_input_state {
35 text_input_commit_string(void *data,
36 struct wl_text_input *text_input,
43 text_input_preedit_string(void *data,
44 struct wl_text_input *text_input,
52 text_input_delete_surrounding_text(void *data,
53 struct wl_text_input *text_input,
60 text_input_cursor_position(void *data,
61 struct wl_text_input *text_input,
68 text_input_preedit_styling(void *data,
69 struct wl_text_input *text_input,
77 text_input_preedit_cursor(void *data,
78 struct wl_text_input *text_input,
84 text_input_modifiers_map(void *data,
85 struct wl_text_input *text_input,
91 text_input_keysym(void *data,
92 struct wl_text_input *text_input,
102 text_input_enter(void *data,
103 struct wl_text_input *text_input,
104 struct wl_surface *surface)
107 struct text_input_state *state = data;
109 fprintf(stderr, "%s\n", __FUNCTION__);
111 state->activated += 1;
115 text_input_leave(void *data,
116 struct wl_text_input *text_input)
118 struct text_input_state *state = data;
120 state->deactivated += 1;
124 text_input_input_panel_state(void *data,
125 struct wl_text_input *text_input,
131 text_input_language(void *data,
132 struct wl_text_input *text_input,
134 const char *language)
139 text_input_text_direction(void *data,
140 struct wl_text_input *text_input,
146 static const struct wl_text_input_listener text_input_listener = {
149 text_input_modifiers_map,
150 text_input_input_panel_state,
151 text_input_preedit_string,
152 text_input_preedit_styling,
153 text_input_preedit_cursor,
154 text_input_commit_string,
155 text_input_cursor_position,
156 text_input_delete_surrounding_text,
159 text_input_text_direction
164 struct client *client;
165 struct global *global;
166 struct wl_text_input_manager *factory;
167 struct wl_text_input *text_input;
168 struct text_input_state state;
170 client = client_create(100, 100, 100, 100);
174 wl_list_for_each(global, &client->global_list, link) {
175 if (strcmp(global->interface, "wl_text_input_manager") == 0)
176 factory = wl_registry_bind(client->wl_registry,
178 &wl_text_input_manager_interface, 1);
183 memset(&state, 0, sizeof state);
184 text_input = wl_text_input_manager_create_text_input(factory);
185 wl_text_input_add_listener(text_input, &text_input_listener, &state);
187 /* Make sure our test surface has keyboard focus. */
188 wl_test_activate_surface(client->test->wl_test,
189 client->surface->wl_surface);
190 client_roundtrip(client);
191 assert(client->input->keyboard->focus == client->surface);
193 /* Activate test model and make sure we get enter event. */
194 wl_text_input_activate(text_input, client->input->wl_seat,
195 client->surface->wl_surface);
196 client_roundtrip(client);
197 assert(state.activated == 1 && state.deactivated == 0);
199 /* Deactivate test model and make sure we get leave event. */
200 wl_text_input_deactivate(text_input, client->input->wl_seat);
201 client_roundtrip(client);
202 assert(state.activated == 1 && state.deactivated == 1);
204 /* Activate test model again. */
205 wl_text_input_activate(text_input, client->input->wl_seat,
206 client->surface->wl_surface);
207 client_roundtrip(client);
208 assert(state.activated == 2 && state.deactivated == 1);
210 /* Take keyboard focus away and verify we get leave event. */
211 wl_test_activate_surface(client->test->wl_test, NULL);
212 client_roundtrip(client);
213 assert(state.activated == 2 && state.deactivated == 2);