toytoolkit: Don't draw shadows for maximized windows.
[profile/ivi/weston.git] / tests / keyboard-test.c
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
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.
13  *
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.
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <sys/socket.h>
26 #include <assert.h>
27 #include <unistd.h>
28 #include <string.h>
29
30 #include "test-runner.h"
31
32 struct context {
33         struct weston_seat *seat;
34         struct weston_surface *surface;
35         uint32_t expect_key;
36         uint32_t expect_key_state;
37         int expect_focus;
38 };
39
40 static void
41 handle_keyboard_state(struct test_client *client)
42 {
43         struct context *context = client->data;
44         uint32_t key, key_state;
45         int focus;
46
47         assert(sscanf(client->buf, "%u %u %d", &key, &key_state, &focus));
48         
49         assert(key == context->expect_key);
50         assert(key_state == context->expect_key_state);
51         assert(focus == context->expect_focus);
52
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);
58         } else if (focus) {
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);
71         } else {
72                 test_client_send(client, "bye\n");
73                 return;
74         }
75         
76         test_client_send(client, "send-keyboard-state\n");
77 }
78
79 static void
80 handle_surface(struct test_client *client)
81 {
82         uint32_t id;
83         struct context *context = client->data;
84         struct wl_resource *resource;
85         struct wl_list *seat_list;
86
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);
90         assert(resource);
91         assert(strcmp(resource->object.interface->name, "wl_surface") == 0);
92
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);
98
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);
102
103         context->seat->keyboard.focus = context->surface;
104         notify_keyboard_focus_out(context->seat);
105
106         test_client_send(client, "send-keyboard-state\n");
107         client->handle = handle_keyboard_state;
108 }
109
110 TEST(keyboard_test)
111 {
112         struct context *context;
113         struct test_client *client;
114
115         client = test_client_launch(compositor, "test-client");
116         client->terminate = 1;
117
118         test_client_send(client, "create-surface\n");
119         client->handle = handle_surface;
120
121         context = calloc(1, sizeof *context);
122         assert(context);
123         client->data = context;
124 }