[PATCH weston v2 4/5] tests: implement touch in test-helpers

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


Let the client bind to wl_touch. Since we have our own seat,
we know that the compositor will have wl_touch capability.

Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
 tests/weston-test-client-helper.c | 79 +++++++++++++++++++++++++++++++++++++++
 tests/weston-test-client-helper.h | 13 +++++++
 2 files changed, 92 insertions(+)

diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 17a0ec4..f0fc40f 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -272,6 +272,71 @@ static const struct wl_keyboard_listener keyboard_listener = {
 };
 
 static void
+touch_handle_down(void *data, struct wl_touch *wl_touch,
+		  uint32_t serial, uint32_t time, struct wl_surface *surface,
+		  int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+{
+	struct touch *touch = data;
+
+	touch->down_x = wl_fixed_to_int(x_w);
+	touch->down_y = wl_fixed_to_int(y_w);
+	touch->id = id;
+
+	fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
+		touch->down_x, touch->down_y, surface, id);
+}
+
+static void
+touch_handle_up(void *data, struct wl_touch *wl_touch,
+		uint32_t serial, uint32_t time, int32_t id)
+{
+	struct touch *touch = data;
+	touch->up_id = id;
+
+	fprintf(stderr, "test-client: got touch up, id: %d\n", id);
+}
+
+static void
+touch_handle_motion(void *data, struct wl_touch *wl_touch,
+		    uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+{
+	struct touch *touch = data;
+	touch->x = wl_fixed_to_int(x_w);
+	touch->y = wl_fixed_to_int(y_w);
+
+	fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
+		touch->x, touch->y, id);
+}
+
+static void
+touch_handle_frame(void *data, struct wl_touch *wl_touch)
+{
+	struct touch *touch = data;
+
+	++touch->frame_no;
+
+	fprintf(stderr, "test-client: got touch frame (%d)\n", touch->frame_no);
+}
+
+static void
+touch_handle_cancel(void *data, struct wl_touch *wl_touch)
+{
+	struct touch *touch = data;
+
+	++touch->cancel_no;
+
+	fprintf(stderr, "test-client: got touch cancel (%d)\n", touch->cancel_no);
+}
+
+static const struct wl_touch_listener touch_listener = {
+	touch_handle_down,
+	touch_handle_up,
+	touch_handle_motion,
+	touch_handle_frame,
+	touch_handle_cancel,
+};
+
+static void
 surface_enter(void *data,
 	      struct wl_surface *wl_surface, struct wl_output *output)
 {
@@ -379,6 +444,7 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 	struct input *input = client->input;
 	struct pointer *pointer;
 	struct keyboard *keyboard;
+	struct touch *touch;
 
 	/* we were waiting for the right seat, so it is possible that
 	 * we don't have the input created yet and this event is
@@ -415,6 +481,19 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 		input->keyboard = NULL;
 	}
 
+	if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
+		touch = xzalloc(sizeof *touch);
+		touch->wl_touch = wl_seat_get_touch(seat);
+		wl_touch_set_user_data(touch->wl_touch, touch);
+		wl_touch_add_listener(touch->wl_touch, &touch_listener,
+				      touch);
+		input->touch = touch;
+	} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
+		wl_touch_destroy(input->touch->wl_touch);
+		free(input->touch);
+		input->touch = NULL;
+	}
+
 	input->caps = caps;
 }
 
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index ff411b8..1ee56a7 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -62,6 +62,7 @@ struct input {
 	struct wl_seat *wl_seat;
 	struct pointer *pointer;
 	struct keyboard *keyboard;
+	struct touch *touch;
 	char *seat_name;
 	enum wl_seat_capability caps;
 };
@@ -90,6 +91,18 @@ struct keyboard {
 	} repeat_info;
 };
 
+struct touch {
+	struct wl_touch *wl_touch;
+	int down_x;
+	int down_y;
+	int x;
+	int y;
+	int id;
+	int up_id; /* id of last wl_touch.up event */
+	int frame_no;
+	int cancel_no;
+};
+
 struct output {
 	struct wl_output *wl_output;
 	int x;
-- 
2.1.0



More information about the wayland-devel mailing list