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 <sys/socket.h>
30 #include "test-runner.h"
33 struct weston_seat *seat;
34 struct weston_surface *surface;
36 uint32_t expect_key_state;
41 handle_keyboard_state(struct test_client *client)
43 struct context *context = client->data;
44 uint32_t key, key_state;
47 assert(sscanf(client->buf, "%u %u %d", &key, &key_state, &focus));
49 assert(key == context->expect_key);
50 assert(key_state == context->expect_key_state);
51 assert(focus == context->expect_focus);
53 if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED) {
54 context->expect_key_state = WL_KEYBOARD_KEY_STATE_RELEASED;
55 notify_key(context->seat, 100, context->expect_key,
56 context->expect_key_state,
57 STATE_UPDATE_AUTOMATIC);
59 context->expect_focus = 0;
60 notify_keyboard_focus_out(context->seat);
61 } else if (context->expect_key < 10) {
62 context->expect_key++;
63 context->expect_focus = 1;
64 context->expect_key_state = WL_KEYBOARD_KEY_STATE_PRESSED;
65 notify_keyboard_focus_in(context->seat,
66 &context->seat->keyboard.keys,
67 STATE_UPDATE_AUTOMATIC);
68 notify_key(context->seat, 100, context->expect_key,
69 context->expect_key_state,
70 STATE_UPDATE_AUTOMATIC);
72 test_client_send(client, "bye\n");
76 test_client_send(client, "send-keyboard-state\n");
80 handle_surface(struct test_client *client)
83 struct context *context = client->data;
84 struct wl_resource *resource;
85 struct wl_list *seat_list;
87 assert(sscanf(client->buf, "surface %u", &id) == 1);
88 fprintf(stderr, "server: got surface id %u\n", id);
89 resource = wl_client_get_object(client->client, id);
91 assert(strcmp(resource->object.interface->name, "wl_surface") == 0);
93 context->surface = (struct weston_surface *) resource;
94 weston_surface_set_color(context->surface, 0.0, 0.0, 0.0, 1.0);
95 weston_surface_configure(context->surface, 100, 100, 100, 100);
96 weston_surface_update_transform(context->surface);
97 weston_surface_damage(context->surface);
99 seat_list = &client->compositor->seat_list;
100 assert(wl_list_length(seat_list) == 1);
101 context->seat = container_of(seat_list->next, struct weston_seat, link);
103 context->seat->keyboard.focus = context->surface;
104 notify_keyboard_focus_out(context->seat);
106 test_client_send(client, "send-keyboard-state\n");
107 client->handle = handle_keyboard_state;
112 struct context *context;
113 struct test_client *client;
115 client = test_client_launch(compositor, "test-client");
116 client->terminate = 1;
118 test_client_send(client, "create-surface\n");
119 client->handle = handle_surface;
121 context = calloc(1, sizeof *context);
123 client->data = context;