[PATCH weston v2 3/5] tests: use special seat

Marek Chalupa mchqwerty at gmail.com
Mon Mar 30 03:37:57 PDT 2015


When running on different backends, we don't know what devices
the backend provides. Create new seat for tests that contains
everything what we need. This is also first step in adding
touch support for tests.

Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
 tests/weston-test-client-helper.c | 60 +++++++++++++++++++++++++++++++++------
 tests/weston-test-client-helper.h |  1 +
 tests/weston-test.c               | 18 ++++++------
 3 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 67a1ad9..17a0ec4 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -375,10 +375,20 @@ static void
 seat_handle_capabilities(void *data, struct wl_seat *seat,
 			 enum wl_seat_capability caps)
 {
-	struct input *input = data;
+	struct client *client = data;
+	struct input *input = client->input;
 	struct pointer *pointer;
 	struct keyboard *keyboard;
 
+	/* we were waiting for the right seat, so it is possible that
+	 * we don't have the input created yet and this event is
+	 * for bad seat or came before seat.name (likely). In such case
+	 * skip the event. It will be called in seat.name */
+	if (!input)
+		return;
+
+	assert(strcmp(input->seat_name, "test-seat") == 0);
+
 	if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
 		pointer = xzalloc(sizeof *pointer);
 		pointer->wl_pointer = wl_seat_get_pointer(seat);
@@ -404,17 +414,45 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 		free(input->keyboard);
 		input->keyboard = NULL;
 	}
+
+	input->caps = caps;
 }
 
 static void
 seat_handle_name(void *data, struct wl_seat *seat, const char *name)
 {
-	struct input *input = data;
+	struct client *client = data;
+	struct input *input;
+	enum wl_seat_capability caps;
+
+	if (strcmp(name, "test-seat") != 0) {
+		/* Weston sends seat.name after seat.capabilities,
+		 * so no other event will use this proxy. We don't even touch
+		 * it in other handlers unless we know that it is the test-seat,
+		 * so we can destroy it without any fear */
+		wl_seat_destroy(seat);
+		return;
+	}
+
+	/* yay! we have the test-seat */
+	input = xzalloc(sizeof *input);
+	assert(input && "No memory");
+
+	assert(client->input == NULL && "Already have an input");
+	client->input = input;
 
 	input->seat_name = strdup(name);
 	assert(input->seat_name && "No memory");
 
-	fprintf(stderr, "test-client: got seat name: %s\n", name);
+	input->wl_seat = seat;
+
+	/* we know that the test-seat has all capabilities.
+	 * Call the handler manually */
+	caps = WL_SEAT_CAPABILITY_POINTER |
+	       WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_TOUCH;
+	seat_handle_capabilities(data, seat, caps);
+
+	fprintf(stderr, "test-client: bound to seat: %s\n", name);
 }
 
 static const struct wl_seat_listener seat_listener = {
@@ -486,10 +524,10 @@ handle_global(void *data, struct wl_registry *registry,
 	      uint32_t id, const char *interface, uint32_t version)
 {
 	struct client *client = data;
-	struct input *input;
 	struct output *output;
 	struct test *test;
 	struct global *global;
+	struct wl_seat *wl_seat;
 
 	global = xzalloc(sizeof *global);
 	global->name = id;
@@ -503,12 +541,13 @@ handle_global(void *data, struct wl_registry *registry,
 			wl_registry_bind(registry, id,
 					 &wl_compositor_interface, version);
 	} else if (strcmp(interface, "wl_seat") == 0) {
-		input = xzalloc(sizeof *input);
-		input->wl_seat =
+		/* bind to seat so that we'll get the name event.
+		 * If it will be the right seat we want, we'll
+		 * get the devices from it later */
+		wl_seat =
 			wl_registry_bind(registry, id,
 					 &wl_seat_interface, version);
-		wl_seat_add_listener(input->wl_seat, &seat_listener, input);
-		client->input = input;
+		wl_seat_add_listener(wl_seat, &seat_listener, client);
 	} else if (strcmp(interface, "wl_shm") == 0) {
 		client->wl_shm =
 			wl_registry_bind(registry, id,
@@ -644,6 +683,11 @@ client_create(int x, int y, int width, int height)
 	/* the output must be initialized */
 	assert(client->output->initialized == 1);
 
+	/* must have seat initialized */
+	assert(client->input);
+	assert(client->input->pointer);
+	assert(client->input->keyboard);
+
 	/* initialize the client surface */
 	surface = xzalloc(sizeof *surface);
 	surface->wl_surface =
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 9be39d9..ff411b8 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -63,6 +63,7 @@ struct input {
 	struct pointer *pointer;
 	struct keyboard *keyboard;
 	char *seat_name;
+	enum wl_seat_capability caps;
 };
 
 struct pointer {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index eb431f3..9f1f49b 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -41,6 +41,7 @@ struct weston_test {
 	struct weston_compositor *compositor;
 	struct weston_layer layer;
 	struct weston_process process;
+	struct weston_seat seat;
 };
 
 struct weston_test_surface {
@@ -70,14 +71,7 @@ test_client_sigchld(struct weston_process *process, int status)
 static struct weston_seat *
 get_seat(struct weston_test *test)
 {
-	struct wl_list *seat_list;
-	struct weston_seat *seat;
-
-	seat_list = &test->compositor->seat_list;
-	assert(wl_list_length(seat_list) == 1);
-	seat = container_of(seat_list->next, struct weston_seat, link);
-
-	return seat;
+	return &test->seat;
 }
 
 static void
@@ -349,6 +343,14 @@ module_init(struct weston_compositor *ec,
 			     test, bind_test) == NULL)
 		return -1;
 
+	/* create our own seat */
+	weston_seat_init(&test->seat, ec, "test-seat");
+
+	/* add devices */
+	weston_seat_init_pointer(&test->seat);
+	weston_seat_init_keyboard(&test->seat, NULL);
+	weston_seat_init_touch(&test->seat);
+
 	loop = wl_display_get_event_loop(ec->wl_display);
 	wl_event_loop_add_idle(loop, idle_launch_client, test);
 
-- 
2.1.0



More information about the wayland-devel mailing list