touchpad: permit only one finger on the touchpad at the start of a tap-drag

This only affects the actual dragging part of the tap-and-drag interaction;
n-finger tap-and-drag is supposed to be performed with a n-finger tap
followed by a 1-finger drag.
Allowing a second finger in the middle of a drag is still necessary for a
finger swap, which users may need in long-distance drags, especially when
drag-lock is disabled.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
This commit is contained in:
satrmb 2021-02-12 12:09:07 +01:00 committed by Peter Hutterer
parent a91ecbde74
commit 4ccdacaf95
4 changed files with 26 additions and 280 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 211 KiB

After

Width:  |  Height:  |  Size: 181 KiB

View file

@ -81,18 +81,9 @@ tap_state_to_str(enum tp_tap_state state)
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_2);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_2);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_2);
@ -745,13 +736,11 @@ tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp,
{
switch (event) {
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_2;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
@ -804,139 +793,6 @@ tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp,
}
}
static void
tp_tap_dragging_or_doubletap_2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_3;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
/* We are overwriting saved_release_time, but if this is indeed
a multitap with two fingers, then we will need its previous
value for the click release event we withheld just in case
this is still a drag. */
tp->tap.saved_multitap_release_time = tp->tap.saved_release_time;
tp->tap.saved_release_time = time;
tp_tap_set_timer(tp, time);
break;
}
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_2,
TAP_STATE_2FGTAP_DRAGGING_2,
TAP_STATE_3FGTAP_DRAGGING_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_or_doubletap_2_release_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event,
uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_2,
TAP_STATE_2FGTAP_DRAGGING_2,
TAP_STATE_3FGTAP_DRAGGING_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_2FGTAP_TAPPED;
tp_tap_notify(tp,
tp->tap.saved_multitap_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_notify(tp,
tp->tap.saved_press_time,
2,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_1FGTAP_TAPPED;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_notify(tp,
tp->tap.saved_press_time,
1,
LIBINPUT_BUTTON_STATE_PRESSED);
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
@ -1053,14 +909,12 @@ tp_tap_dragging_tap_handle_event(struct tp_dispatch *tp,
switch (event) {
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
tp_tap_set_timer(tp, time);
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_clear_timer(tp);
tp_tap_move_to_dead(tp, t);
break;
}
case TAP_EVENT_RELEASE:
@ -1105,68 +959,6 @@ tp_tap_dragging_tap_handle_event(struct tp_dispatch *tp,
}
}
static void
tp_tap_dragging_tap_2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_clear_timer(tp);
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_RELEASE: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_TAP,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
tp_tap_set_timer(tp, time);
break;
}
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_2,
TAP_STATE_2FGTAP_DRAGGING_2,
TAP_STATE_3FGTAP_DRAGGING_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_TAP,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
@ -1309,33 +1101,6 @@ tp_tap_handle_event(struct tp_dispatch *tp,
tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time,
3);
break;
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2:
tp_tap_dragging_or_doubletap_2_handle_event(tp, t, event, time,
1);
break;
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2:
tp_tap_dragging_or_doubletap_2_handle_event(tp, t, event, time,
2);
break;
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2:
tp_tap_dragging_or_doubletap_2_handle_event(tp, t, event, time,
3);
break;
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
tp_tap_dragging_or_doubletap_2_release_handle_event(tp, t,
event, time,
1);
break;
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
tp_tap_dragging_or_doubletap_2_release_handle_event(tp, t,
event, time,
2);
break;
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
tp_tap_dragging_or_doubletap_2_release_handle_event(tp, t,
event, time,
3);
break;
case TAP_STATE_1FGTAP_DRAGGING:
tp_tap_dragging_handle_event(tp, t, event, time, 1);
break;
@ -1363,15 +1128,6 @@ tp_tap_handle_event(struct tp_dispatch *tp,
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
tp_tap_dragging_tap_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2:
tp_tap_dragging_tap_2_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2:
tp_tap_dragging_tap_2_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2:
tp_tap_dragging_tap_2_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_1FGTAP_DRAGGING_2:
tp_tap_dragging2_handle_event(tp, t, event, time, 1);
break;
@ -1549,18 +1305,9 @@ tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time)
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2:
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2:
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2:
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE:
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2:
case TAP_STATE_TOUCH_2:
case TAP_STATE_TOUCH_3:
filter_motion = 1;
@ -1901,9 +1648,6 @@ tp_tap_dragging(const struct tp_dispatch *tp)
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2:
return true;
default:
return false;

View file

@ -119,18 +119,9 @@ enum tp_tap_state {
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2,
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP_2_RELEASE,
TAP_STATE_1FGTAP_DRAGGING_OR_TAP,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP,
TAP_STATE_1FGTAP_DRAGGING_OR_TAP_2,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP_2,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP_2,
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
@ -430,8 +421,7 @@ struct tp_dispatch {
enum tp_tap_state state;
uint32_t buttons_pressed;
uint64_t saved_press_time,
saved_release_time,
saved_multitap_release_time;
saved_release_time;
enum libinput_config_tap_button_map map;
enum libinput_config_tap_button_map want_map;

View file

@ -468,7 +468,7 @@ START_TEST(touchpad_multitap_n_drag_2fg)
libinput_dispatch(li);
litest_touch_down(dev, 0, 50, 50);
msleep(10);
litest_touch_move_to(dev, 0, 50, 50, 30, 50, 10);
litest_touch_down(dev, 1, 70, 50);
libinput_dispatch(li);
@ -1645,6 +1645,9 @@ START_TEST(touchpad_tap_n_drag_2fg)
break;
}
litest_touch_down(dev, 0, 30, 70);
libinput_dispatch(li);
litest_timeout_tap();
libinput_dispatch(li);
litest_touch_down(dev, 1, 80, 70);
litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10);
libinput_dispatch(li);
@ -1724,6 +1727,9 @@ START_TEST(touchpad_tap_n_drag_3fg_btntool)
break;
}
litest_touch_down(dev, 0, 30, 70);
libinput_dispatch(li);
litest_timeout_tap();
libinput_dispatch(li);
litest_touch_down(dev, 1, 80, 90);
litest_touch_move_to(dev, 0, 30, 70, 30, 30, 5);
libinput_dispatch(li);
@ -1806,6 +1812,9 @@ START_TEST(touchpad_tap_n_drag_3fg)
break;
}
litest_touch_down(dev, 0, 30, 70);
libinput_dispatch(li);
litest_timeout_tap();
libinput_dispatch(li);
litest_touch_down(dev, 1, 80, 90);
litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10);
libinput_dispatch(li);
@ -4374,6 +4383,9 @@ START_TEST(touchpad_tap_palm_on_drag_2fg)
LIBINPUT_BUTTON_STATE_PRESSED);
litest_touch_down(dev, this, 50, 50);
libinput_dispatch(li);
litest_timeout_tap();
libinput_dispatch(li);
litest_touch_down(dev, other, 60, 50);
libinput_dispatch(li);