From 5e06d61e4238f7e2ebc9ac4750ff477423b02279 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 27 Aug 2017 17:35:12 -0400 Subject: implement touch up and touch down --- examples/pointer.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/pointer.c b/examples/pointer.c index bae205f5..98b4735a 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -58,12 +58,20 @@ struct touch_point { double x, y; }; -static void warp_to_touch(struct sample_state *sample) { - wlr_log(L_DEBUG, "TODO: warp to touch"); +static void warp_to_touch(struct sample_state *sample, struct wlr_input_device *dev) { + if (sample->touch_points->length == 0) { + return; + } + + double x = 0, y = 0; for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; - wlr_log(L_DEBUG, "have point x=%f,y=%f", point->x, point->y); + x += point->x; + y += point->y; } + x /= sample->touch_points->length; + y /= sample->touch_points->length; + wlr_cursor_warp_absolute(sample->cursor, dev, x, y); } static void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -248,7 +256,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { } } - warp_to_touch(sample); + warp_to_touch(sample, event->device); } static void handle_touch_down(struct wl_listener *listener, void *data) { @@ -262,7 +270,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { free(point); } - warp_to_touch(sample); + warp_to_touch(sample, event->device); } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -277,7 +285,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { } } - warp_to_touch(sample); + warp_to_touch(sample, event->device); } static void handle_touch_cancel(struct wl_listener *listener, void *data) { -- cgit v1.2.3