diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-08-27 17:35:12 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-08-27 17:35:12 -0400 |
commit | 5e06d61e4238f7e2ebc9ac4750ff477423b02279 (patch) | |
tree | 641f3dbd896d4e3ebec62034b0b5eae034ece251 /examples | |
parent | c91469767631c84375678f3428a43c355d2c9742 (diff) |
implement touch up and touch down
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pointer.c | 20 |
1 files changed, 14 insertions, 6 deletions
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) { |