summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2014-06-24 16:23:10 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2014-06-25 11:11:39 +1000
commitc0af1b57d4063f0894ade2ba2f57a149ad454f7f (patch)
tree74930062e2931b797a8219ad34291f8915da48e5
parentc9a01969d8e5ad527fede479be0b032a46a4f18d (diff)
downloadlibinput-c0af1b57d4063f0894ade2ba2f57a149ad454f7f.tar.gz
touchpad: Avoid spurious motion event for scroll movement below threshold
If the user puts down to fingers to scroll, then changes his mind and lifts them, without having them moved past the initial scroll threshold in either direction, then any movement which he has done will cause a spurious scroll event when the second finger down is lifted first. The problem is that t->is_pointer was not being set to false in this case, since that is done in tp_post_twofinger_scroll after checking scroll.state which never gets set in this scenario. Instead of changing the order, simply completely remove scroll.state completely it is a boolean, and everywhere we check for it we also check for the axis bits in state.direction, so it is not necessary. Also add a check to ensure there are no spurious motion events. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/evdev-mt-touchpad.c17
-rw-r--r--src/evdev-mt-touchpad.h6
-rw-r--r--test/touchpad.c27
3 files changed, 23 insertions, 27 deletions
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 4811bf31..04ea93c6 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -464,17 +464,11 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
tp_filter_motion(tp, &dx, &dy, time);
/* Require at least three px scrolling to start */
- if (dy <= -3.0 || dy >= 3.0) {
- tp->scroll.state = SCROLL_STATE_SCROLLING;
+ if (dy <= -3.0 || dy >= 3.0)
tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
- }
- if (dx <= -3.0 || dx >= 3.0) {
- tp->scroll.state = SCROLL_STATE_SCROLLING;
- tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
- }
- if (tp->scroll.state == SCROLL_STATE_NONE)
- return;
+ if (dx <= -3.0 || dx >= 3.0)
+ tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
/* Stop spurious MOTION events at the end of scrolling */
tp_for_each_touch(tp, t)
@@ -500,9 +494,6 @@ 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_SCROLL_VERTICAL))
pointer_notify_axis(&tp->device->base,
@@ -515,7 +506,6 @@ tp_stop_scroll_events(struct tp_dispatch *tp, uint64_t time)
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
0);
- tp->scroll.state = SCROLL_STATE_NONE;
tp->scroll.direction = 0;
}
@@ -732,7 +722,6 @@ static int
tp_init_scroll(struct tp_dispatch *tp)
{
tp->scroll.direction = 0;
- tp->scroll.state = SCROLL_STATE_NONE;
return 0;
}
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 0b1457db..7afb3c46 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -72,11 +72,6 @@ enum button_state {
BUTTON_STATE_IGNORE,
};
-enum scroll_state {
- SCROLL_STATE_NONE,
- SCROLL_STATE_SCROLLING
-};
-
enum tp_tap_state {
TAP_STATE_IDLE = 4,
TAP_STATE_TOUCH,
@@ -192,7 +187,6 @@ struct tp_dispatch {
} buttons; /* physical buttons */
struct {
- enum scroll_state state;
enum libinput_pointer_axis direction;
} scroll;
diff --git a/test/touchpad.c b/test/touchpad.c
index fa777e4f..288805ef 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -1027,16 +1027,27 @@ START_TEST(clickpad_topsoftbuttons_move_out_ignore)
END_TEST
static void
-test_2fg_scroll(struct litest_device *dev, int dx, int dy)
+test_2fg_scroll(struct litest_device *dev, int dx, int dy, int sleep)
{
+ struct libinput *li = dev->libinput;
+
litest_touch_down(dev, 0, 47, 50);
litest_touch_down(dev, 1, 53, 50);
litest_touch_move_to(dev, 0, 47, 50, 47 + dx, 50 + dy, 5);
litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
+ /* Avoid a small scroll being seen as a tap */
+ if (sleep) {
+ libinput_dispatch(li);
+ msleep(sleep);
+ libinput_dispatch(li);
+ }
+
litest_touch_up(dev, 1);
litest_touch_up(dev, 0);
+
+ libinput_dispatch(li);
}
static void
@@ -1046,8 +1057,6 @@ check_2fg_scroll(struct litest_device *dev, int axis, int dir)
struct libinput_event *event, *next_event;
struct libinput_event_pointer *ptrev;
- libinput_dispatch(li);
-
event = libinput_get_event(li);
next_event = libinput_get_event(li);
ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
@@ -1091,14 +1100,18 @@ START_TEST(touchpad_2fg_scroll)
/* Note this mixes in a tiny amount of movement in the wrong direction,
which should be ignored */
- test_2fg_scroll(dev, 1, 40);
+ test_2fg_scroll(dev, 1, 40, 0);
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
- test_2fg_scroll(dev, 1, -40);
+ test_2fg_scroll(dev, 1, -40, 0);
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
- test_2fg_scroll(dev, 40, 1);
+ test_2fg_scroll(dev, 40, 1, 0);
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
- test_2fg_scroll(dev, -40, 1);
+ test_2fg_scroll(dev, -40, 1, 0);
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
+
+ /* 2fg scroll smaller than the threshold should not generate events */
+ test_2fg_scroll(dev, 1, 1, 200);
+ litest_assert_empty_queue(li);
}
END_TEST