summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2014-02-04 10:38:21 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2014-07-03 13:51:11 +1000
commit2219c12c3aa45b80f235e761e87c17fb9ec70eae (patch)
tree12de201a5dcce94a2103bc6ea998608c2d3cb61c
parent401592870d3d6df3deb669387d58bf632fa0317f (diff)
touchpad: hook up to the tapping configuration
Now that we have run-time changes of the tap.enabled state move the check to the IDLE state only. Otherwise the tap machine may hang if tapping is disabled while a gesture is in progress. Two basic tests are added to check for the tap default setting - which is now "tap disabled by default", for two reasons: * if you don't know that tapping is a thing (or enabled by default), you get spurious button events that make the desktop feel buggy. * if you do know what tapping is and you want it, you usually know where to enable it, or at least you can search for it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/evdev-mt-touchpad-tap.c67
-rw-r--r--src/evdev-mt-touchpad.h1
-rw-r--r--test/touchpad.c54
3 files changed, 117 insertions, 5 deletions
diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
index 8a129634..0f1f837d 100644
--- a/src/evdev-mt-touchpad-tap.c
+++ b/src/evdev-mt-touchpad-tap.c
@@ -467,13 +467,13 @@ tp_tap_handle_event(struct tp_dispatch *tp,
struct libinput *libinput = tp->device->base.seat->libinput;
enum tp_tap_state current;
- if (!tp->tap.enabled)
- return;
-
current = tp->tap.state;
switch(tp->tap.state) {
case TAP_STATE_IDLE:
+ if (!tp->tap.enabled)
+ break;
+
tp_tap_idle_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH:
@@ -612,17 +612,74 @@ tp_tap_handle_timeout(uint64_t time, void *data)
}
}
+static int
+tp_tap_config_count(struct libinput_device *device)
+{
+ struct evdev_dispatch *dispatch;
+ struct tp_dispatch *tp;
+
+ dispatch = ((struct evdev_device *) device)->dispatch;
+ tp = container_of(dispatch, tp, base);
+
+ return min(tp->ntouches, 3); /* we only do up to 3 finger tap */
+}
+
+static enum libinput_config_status
+tp_tap_config_set_enabled(struct libinput_device *device, int enabled)
+{
+ struct evdev_dispatch *dispatch;
+ struct tp_dispatch *tp;
+
+ dispatch = ((struct evdev_device *) device)->dispatch;
+ tp = container_of(dispatch, tp, base);
+
+ tp->tap.enabled = enabled;
+
+ return LIBINPUT_CONFIG_STATUS_SUCCESS;
+}
+
+static int
+tp_tap_config_is_enabled(struct libinput_device *device)
+{
+ struct evdev_dispatch *dispatch;
+ struct tp_dispatch *tp;
+
+ dispatch = ((struct evdev_device *) device)->dispatch;
+ tp = container_of(dispatch, tp, base);
+
+ return tp->tap.enabled;
+}
+
+static int
+tp_tap_config_get_default(struct libinput_device *device)
+{
+ /**
+ * Tapping is disabled by default for two reasons:
+ * * if you don't know that tapping is a thing (or enabled by
+ * default), you get spurious mouse events that make the desktop
+ * feel buggy.
+ * * if you do know what tapping is and you want it, you
+ * usually know where to enable it, or at least you can search for
+ * it.
+ */
+ return false;
+}
+
int
tp_init_tap(struct tp_dispatch *tp)
{
+ tp->tap.config.count = tp_tap_config_count;
+ tp->tap.config.set_enabled = tp_tap_config_set_enabled;
+ tp->tap.config.get_enabled = tp_tap_config_is_enabled;
+ tp->tap.config.get_default = tp_tap_config_get_default;
+ tp->device->base.config.tap = &tp->tap.config;
+
tp->tap.state = TAP_STATE_IDLE;
libinput_timer_init(&tp->tap.timer,
tp->device->base.seat->libinput,
tp_tap_handle_timeout, tp);
- tp->tap.enabled = 1; /* FIXME */
-
return 0;
}
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 6fb9ca4d..c92c2b10 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -199,6 +199,7 @@ struct tp_dispatch {
enum touchpad_event queued;
struct {
+ struct libinput_device_config_tap config;
bool enabled;
struct libinput_timer timer;
enum tp_tap_state state;
diff --git a/test/touchpad.c b/test/touchpad.c
index d7625e92..6a33a440 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -116,6 +116,8 @@ START_TEST(touchpad_1fg_tap)
struct libinput *li = dev->libinput;
struct libinput_event *event;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(li);
litest_touch_down(dev, 0, 50, 50);
@@ -141,6 +143,8 @@ START_TEST(touchpad_1fg_tap_n_drag)
struct libinput *li = dev->libinput;
struct libinput_event *event;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(li);
litest_touch_down(dev, 0, 50, 50);
@@ -191,6 +195,8 @@ START_TEST(touchpad_2fg_tap)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
litest_touch_down(dev, 0, 50, 50);
@@ -215,6 +221,8 @@ START_TEST(touchpad_2fg_tap_inverted)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
litest_touch_down(dev, 0, 50, 50);
@@ -239,6 +247,8 @@ START_TEST(touchpad_1fg_tap_click)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
/* finger down, button click, finger up
@@ -266,6 +276,8 @@ START_TEST(touchpad_2fg_tap_click)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
/* two fingers down, button click, fingers up
@@ -295,6 +307,8 @@ START_TEST(touchpad_2fg_tap_click_apple)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
/* two fingers down, button click, fingers up
@@ -401,6 +415,8 @@ START_TEST(touchpad_1fg_double_tap_click)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
/* one finger down, up, down, button click, finger up
@@ -435,6 +451,8 @@ START_TEST(touchpad_1fg_tap_n_drag_click)
struct libinput *li = dev->libinput;
struct libinput_event *event;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(dev->libinput);
/* one finger down, up, down, move, button click, finger up
@@ -675,6 +693,8 @@ START_TEST(clickpad_softbutton_left_tap_n_drag)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(li);
/* Tap in left button area, then finger down, button click
@@ -715,6 +735,8 @@ START_TEST(clickpad_softbutton_right_tap_n_drag)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
+ libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
+
litest_drain_events(li);
/* Tap in right button area, then finger down, button click
@@ -1191,6 +1213,34 @@ START_TEST(touchpad_2fg_scroll)
}
END_TEST
+START_TEST(touchpad_tap_is_available)
+{
+ struct litest_device *dev = litest_current_device();
+
+ ck_assert_int_ge(libinput_device_config_tap_get_finger_count(dev->libinput_device), 1);
+ ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
+}
+END_TEST
+
+START_TEST(touchpad_tap_is_not_available)
+{
+ struct litest_device *dev = litest_current_device();
+
+ ck_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0);
+ ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
+ ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 1),
+ LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
+}
+END_TEST
+
+START_TEST(touchpad_tap_default)
+{
+ struct litest_device *dev = litest_current_device();
+
+ ck_assert_int_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), 0);
+}
+END_TEST
+
int main(int argc, char **argv) {
litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
@@ -1213,6 +1263,10 @@ int main(int argc, char **argv) {
litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
+ litest_add("touchpad:tap", touchpad_tap_default, LITEST_TOUCHPAD, LITEST_ANY);
+ litest_add("touchpad:tap", touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY);
+ litest_add("touchpad:tap", touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD);
+
litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);