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>
This commit is contained in:
committed by
Pekka Paalanen
parent
c3c3fc411e
commit
8a5523c3ec
@@ -271,6 +271,71 @@ static const struct wl_keyboard_listener keyboard_listener = {
|
|||||||
keyboard_handle_repeat_info,
|
keyboard_handle_repeat_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
surface_enter(void *data,
|
surface_enter(void *data,
|
||||||
struct wl_surface *wl_surface, struct wl_output *output)
|
struct wl_surface *wl_surface, struct wl_output *output)
|
||||||
@@ -376,6 +441,7 @@ input_update_devices(struct input *input)
|
|||||||
{
|
{
|
||||||
struct pointer *pointer;
|
struct pointer *pointer;
|
||||||
struct keyboard *keyboard;
|
struct keyboard *keyboard;
|
||||||
|
struct touch *touch;
|
||||||
|
|
||||||
struct wl_seat *seat = input->wl_seat;
|
struct wl_seat *seat = input->wl_seat;
|
||||||
enum wl_seat_capability caps = input->caps;
|
enum wl_seat_capability caps = input->caps;
|
||||||
@@ -405,6 +471,19 @@ input_update_devices(struct input *input)
|
|||||||
free(input->keyboard);
|
free(input->keyboard);
|
||||||
input->keyboard = NULL;
|
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
|
static void
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ struct input {
|
|||||||
struct wl_seat *wl_seat;
|
struct wl_seat *wl_seat;
|
||||||
struct pointer *pointer;
|
struct pointer *pointer;
|
||||||
struct keyboard *keyboard;
|
struct keyboard *keyboard;
|
||||||
|
struct touch *touch;
|
||||||
char *seat_name;
|
char *seat_name;
|
||||||
enum wl_seat_capability caps;
|
enum wl_seat_capability caps;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
@@ -98,6 +99,18 @@ struct keyboard {
|
|||||||
} repeat_info;
|
} 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 output {
|
||||||
struct wl_output *wl_output;
|
struct wl_output *wl_output;
|
||||||
int x;
|
int x;
|
||||||
|
|||||||
Reference in New Issue
Block a user