From ecb132fef6d47c5d8c21e595c7a8ce5298c276ea Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Fri, 23 May 2014 16:06:23 +0200 Subject: [PATCH] touchpad: Fix sending of scroll stop events Setting tp->scroll.direction = 0 before checking tp->scroll.direction to see if we need to send stop scroll events for vert / horz scrolling does not really work well. Also we need to check direction with an axis mask, not the axis number. While at it also add a tp_stop_scroll_events() helper function for this. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 040939b6..2455c36c 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -500,6 +500,28 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) } } +static void +tp_stop_scroll_events(struct tp_dispatch *tp, uint64_t time) +{ + if (tp->scroll.state == SCROLL_STATE_NONE) + return; + + /* terminate scrolling with a zero scroll event */ + if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL)) + pointer_notify_axis(&tp->device->base, + time, + LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL, + 0); + if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL)) + pointer_notify_axis(&tp->device->base, + time, + LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL, + 0); + + tp->scroll.state = SCROLL_STATE_NONE; + tp->scroll.direction = 0; +} + static int tp_post_scroll_events(struct tp_dispatch *tp, uint64_t time) { @@ -513,22 +535,7 @@ tp_post_scroll_events(struct tp_dispatch *tp, uint64_t time) } if (nfingers_down != 2) { - /* terminate scrolling with a zero scroll event to notify - * caller that it really ended now */ - if (tp->scroll.state != SCROLL_STATE_NONE) { - tp->scroll.state = SCROLL_STATE_NONE; - tp->scroll.direction = 0; - if (tp->scroll.direction & LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL) - pointer_notify_axis(&tp->device->base, - time, - LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL, - 0); - if (tp->scroll.direction & LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL) - pointer_notify_axis(&tp->device->base, - time, - LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL, - 0); - } + tp_stop_scroll_events(tp, time); } else { tp_post_twofinger_scroll(tp, time); return 1;