diff options
author | Marek Chalupa <mchqwerty@gmail.com> | 2015-03-30 09:20:07 -0400 |
---|---|---|
committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2015-03-31 11:11:59 +0300 |
commit | 8a5523c3ec7bd8b216bac610b0e9e5bdba88f68c (patch) | |
tree | 36c49295efa8886749443819ac66bc0a45d754f6 /tests/weston-test-client-helper.c | |
parent | c3c3fc411eec1233f68098c630dd7892fc762308 (diff) | |
download | weston-8a5523c3ec7bd8b216bac610b0e9e5bdba88f68c.tar.gz |
tests: implement touch in test-helpers
Let the client bind to wl_touch. Since we have our own seat,
we know that the compositor will have wl_touch capability.
v2: rebased due to changes in previous commit
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests/weston-test-client-helper.c')
-rw-r--r-- | tests/weston-test-client-helper.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 2e424dce..9a031e3e 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) { @@ -376,6 +441,7 @@ input_update_devices(struct input *input) { struct pointer *pointer; struct keyboard *keyboard; + struct touch *touch; struct wl_seat *seat = input->wl_seat; enum wl_seat_capability caps = input->caps; @@ -405,6 +471,19 @@ input_update_devices(struct input *input) free(input->keyboard); 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; + } } static void |