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.
28 #include "../src/compositor.h"
29 #include "wayland-test-server-protocol.h"
32 struct weston_compositor *compositor;
33 struct weston_layer layer;
34 struct weston_process process;
37 struct weston_test_surface {
38 struct weston_surface *surface;
40 struct weston_test *test;
44 test_client_sigchld(struct weston_process *process, int status)
46 struct weston_test *test =
47 container_of(process, struct weston_test, process);
51 wl_display_terminate(test->compositor->wl_display);
54 static struct weston_seat *
55 get_seat(struct weston_test *test)
57 struct wl_list *seat_list;
58 struct weston_seat *seat;
60 seat_list = &test->compositor->seat_list;
61 assert(wl_list_length(seat_list) == 1);
62 seat = container_of(seat_list->next, struct weston_seat, link);
68 notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
70 struct weston_seat *seat = get_seat(test);
71 struct weston_pointer *pointer = seat->pointer;
73 wl_test_send_pointer_position(resource, pointer->x, pointer->y);
77 test_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
79 struct weston_test_surface *test_surface = surface->configure_private;
80 struct weston_test *test = test_surface->test;
82 if (wl_list_empty(&surface->layer_link))
83 wl_list_insert(&test->layer.surface_list,
84 &surface->layer_link);
86 weston_surface_configure(surface, test_surface->x, test_surface->y,
89 if (!weston_surface_is_mapped(surface))
90 weston_surface_update_transform(surface);
94 move_surface(struct wl_client *client, struct wl_resource *resource,
95 struct wl_resource *surface_resource,
98 struct weston_surface *surface =
99 wl_resource_get_user_data(surface_resource);
100 struct weston_test_surface *test_surface;
102 surface->configure = test_surface_configure;
103 if (surface->configure_private == NULL)
104 surface->configure_private = malloc(sizeof *test_surface);
105 test_surface = surface->configure_private;
106 if (test_surface == NULL) {
107 wl_resource_post_no_memory(resource);
111 test_surface->surface = surface;
112 test_surface->test = wl_resource_get_user_data(resource);
118 move_pointer(struct wl_client *client, struct wl_resource *resource,
119 int32_t x, int32_t y)
121 struct weston_test *test = wl_resource_get_user_data(resource);
122 struct weston_seat *seat = get_seat(test);
123 struct weston_pointer *pointer = seat->pointer;
125 test->compositor->focus = 1;
127 notify_motion(seat, 100,
128 wl_fixed_from_int(x) - pointer->x,
129 wl_fixed_from_int(y) - pointer->y);
131 notify_pointer_position(test, resource);
135 send_button(struct wl_client *client, struct wl_resource *resource,
136 int32_t button, uint32_t state)
138 struct weston_test *test = wl_resource_get_user_data(resource);
139 struct weston_seat *seat = get_seat(test);
141 test->compositor->focus = 1;
143 notify_button(seat, 100, button, state);
147 activate_surface(struct wl_client *client, struct wl_resource *resource,
148 struct wl_resource *surface_resource)
150 struct weston_surface *surface = surface_resource ?
151 wl_resource_get_user_data(surface_resource) : NULL;
152 struct weston_test *test = wl_resource_get_user_data(resource);
153 struct weston_seat *seat;
155 seat = get_seat(test);
158 weston_surface_activate(surface, seat);
159 notify_keyboard_focus_in(seat, &seat->keyboard->keys,
160 STATE_UPDATE_AUTOMATIC);
163 notify_keyboard_focus_out(seat);
164 weston_surface_activate(surface, seat);
169 send_key(struct wl_client *client, struct wl_resource *resource,
170 uint32_t key, enum wl_keyboard_key_state state)
172 struct weston_test *test = wl_resource_get_user_data(resource);
173 struct weston_seat *seat = get_seat(test);
175 test->compositor->focus = 1;
177 notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
180 static const struct wl_test_interface test_implementation = {
189 bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
191 struct weston_test *test = data;
192 struct wl_resource *resource;
194 resource = wl_resource_create(client, &wl_test_interface, 1, id);
195 wl_resource_set_implementation(resource,
196 &test_implementation, test, NULL);
198 notify_pointer_position(test, resource);
202 idle_launch_client(void *data)
204 struct weston_test *test = data;
209 path = getenv("WESTON_TEST_CLIENT_PATH");
216 sigfillset(&allsigs);
217 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
218 execl(path, path, NULL);
219 weston_log("compositor: executing '%s' failed: %m\n", path);
223 test->process.pid = pid;
224 test->process.cleanup = test_client_sigchld;
225 weston_watch_process(&test->process);
229 module_init(struct weston_compositor *ec,
230 int *argc, char *argv[])
232 struct weston_test *test;
233 struct wl_event_loop *loop;
235 test = zalloc(sizeof *test);
239 test->compositor = ec;
240 weston_layer_init(&test->layer, &ec->cursor_layer.link);
242 if (wl_global_create(ec->wl_display, &wl_test_interface, 1,
243 test, bind_test) == NULL)
246 loop = wl_display_get_event_loop(ec->wl_display);
247 wl_event_loop_add_idle(loop, idle_launch_client, test);