From ddcf1f61bf4e68ddec4c3429c771bd9d9e46a7f8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 23 Mar 2017 13:46:51 +1000 Subject: [PATCH 1/6] touchpad: move edge palm detection into a helper too Just code cleanup, no changes. Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index eb950a2c..e891dea4 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -664,16 +664,11 @@ tp_palm_detect_multifinger(struct tp_dispatch *tp, struct tp_touch *t, uint64_t return false; } -static void -tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) +static inline bool +tp_palm_detect_edge(struct tp_dispatch *tp, + struct tp_touch *t, + uint64_t time) { - - if (tp_palm_detect_dwt_triggered(tp, t, time)) - goto out; - - if (tp_palm_detect_trackpoint_triggered(tp, t, time)) - goto out; - if (t->palm.state == PALM_EDGE) { if (tp_palm_detect_multifinger(tp, t, time)) { t->palm.state = PALM_NONE; @@ -689,31 +684,49 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) evdev_log_debug(tp->device, "palm: touch released, out of edge zone\n"); } - return; + return false; } else if (tp_palm_detect_multifinger(tp, t, time)) { - return; + return false; } /* palm must start in exclusion zone, it's ok to move into the zone without being a palm */ if (t->state != TOUCH_BEGIN || (t->point.x > tp->palm.left_edge && t->point.x < tp->palm.right_edge)) - return; + return false; /* don't detect palm in software button areas, it's likely that legitimate touches start in the area covered by the exclusion zone */ if (tp->buttons.is_clickpad && tp_button_is_inside_softbutton_area(tp, t)) - return; + return false; if (tp_touch_get_edge(tp, t) & EDGE_RIGHT) - return; + return false; t->palm.state = PALM_EDGE; t->palm.time = time; t->palm.first = t->point; + return true; +} + +static void +tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) +{ + + if (tp_palm_detect_dwt_triggered(tp, t, time)) + goto out; + + if (tp_palm_detect_trackpoint_triggered(tp, t, time)) + goto out; + + if (tp_palm_detect_edge(tp, t, time)) + goto out; + + return; + out: evdev_log_debug(tp->device, "palm: palm detected (%s)\n", From 5a63c82822bbeae7b97708204893b9a0f40e0d1e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 23 Mar 2017 13:55:32 +1000 Subject: [PATCH 2/6] touchpad: make palm detection logging a bit easier Nested trinary conditions are fun, but... Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index e891dea4..3fd1f29a 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -715,6 +715,8 @@ tp_palm_detect_edge(struct tp_dispatch *tp, static void tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { + const char *palm_state; + enum touch_palm_state oldstate = t->palm.state; if (tp_palm_detect_dwt_triggered(tp, t, time)) goto out; @@ -726,12 +728,28 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) goto out; return; - out: + if (oldstate == t->palm.state) + return; + + switch (t->palm.state) { + case PALM_EDGE: + palm_state = "edge"; + break; + case PALM_TYPING: + palm_state = "typing"; + break; + case PALM_TRACKPOINT: + palm_state = "trackpoint"; + break; + case PALM_NONE: + default: + abort(); + break; + } evdev_log_debug(tp->device, "palm: palm detected (%s)\n", - t->palm.state == PALM_EDGE ? "edge" : - t->palm.state == PALM_TYPING ? "typing" : "trackpoint"); + palm_state); } static inline const char* From 160d60eb859a3e78ba0bb10be70e534ca499dee4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 3 Apr 2017 13:27:52 +1000 Subject: [PATCH 3/6] touchpad: always enable trackpoint palm detection Trackpoints are situated so that a user is pretty much guaranteed to trigger some palm interaction, even if on a small touchpad. Always enable trackpoint monitoring on touchpads where required. Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 3fd1f29a..93223938 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -2239,6 +2239,8 @@ tp_init_palmdetect(struct tp_dispatch *tp, !tp_is_tpkb_combo_below(device)) return; + tp->palm.monitor_trackpoint = true; + evdev_device_get_size(device, &width, &height); /* Enable palm detection on touchpads >= 70 mm. Anything smaller From 76fce6cdddaee901ba47b1a47ecdc4e1e5e46f32 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 3 Apr 2017 13:31:50 +1000 Subject: [PATCH 4/6] touchpad: move edge palm init to separate helper Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 93223938..21fdc462 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -2224,23 +2224,14 @@ tp_init_dwt(struct tp_dispatch *tp, return; } -static void -tp_init_palmdetect(struct tp_dispatch *tp, - struct evdev_device *device) +static inline void +tp_init_palmdetect_edge(struct tp_dispatch *tp, + struct evdev_device *device) { double width, height; struct phys_coords mm = { 0.0, 0.0 }; struct device_coords edges; - tp->palm.right_edge = INT_MAX; - tp->palm.left_edge = INT_MIN; - - if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD && - !tp_is_tpkb_combo_below(device)) - return; - - tp->palm.monitor_trackpoint = true; - evdev_device_get_size(device, &width, &height); /* Enable palm detection on touchpads >= 70 mm. Anything smaller @@ -2256,8 +2247,23 @@ tp_init_palmdetect(struct tp_dispatch *tp, mm.x = width * 0.95; edges = evdev_device_mm_to_units(device, &mm); tp->palm.right_edge = edges.x; +} + +static void +tp_init_palmdetect(struct tp_dispatch *tp, + struct evdev_device *device) +{ + + tp->palm.right_edge = INT_MAX; + tp->palm.left_edge = INT_MIN; + + if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD && + !tp_is_tpkb_combo_below(device)) + return; tp->palm.monitor_trackpoint = true; + + tp_init_palmdetect_edge(tp, device); } static void From 7d1a047b7c2f7acf6fdce5ac5d352bd909605234 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 3 Apr 2017 15:15:01 +1000 Subject: [PATCH 5/6] touchpad: add helper function for stopping current actions Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 21fdc462..f41dd68e 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -276,6 +276,14 @@ tp_end_sequence(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) tp_end_touch(tp, t, time); } +static void +tp_stop_actions(struct tp_dispatch *tp, uint64_t time) +{ + tp_edge_scroll_stop_events(tp, time); + tp_gesture_cancel(tp, time); + tp_tap_suspend(tp, time); +} + struct normalized_coords tp_get_delta(struct tp_touch *t) { @@ -1395,9 +1403,7 @@ tp_trackpoint_event(uint64_t time, struct libinput_event *event, void *data) return; if (!tp->palm.trackpoint_active) { - tp_edge_scroll_stop_events(tp, time); - tp_gesture_cancel(tp, time); - tp_tap_suspend(tp, time); + tp_stop_actions(tp, time); tp->palm.trackpoint_active = true; } @@ -1510,9 +1516,7 @@ tp_keyboard_event(uint64_t time, struct libinput_event *event, void *data) ARRAY_LENGTH(tp->dwt.mod_mask))) return; - tp_edge_scroll_stop_events(tp, time); - tp_gesture_cancel(tp, time); - tp_tap_suspend(tp, time); + tp_stop_actions(tp, time); tp->dwt.keyboard_active = true; timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1; } else { From 9495713b05d244b0293cbf4fc5e6a7094ee50e27 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 3 Apr 2017 13:58:42 +1000 Subject: [PATCH 6/6] touchpad: add MT_TOOL-based palm detection If the touchpad driver tells us something is a palm, go with that. https://bugs.freedesktop.org/show_bug.cgi?id=100243 Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad.c | 41 ++++++++++++++++++++ src/evdev-mt-touchpad.h | 4 ++ test/test-touchpad.c | 83 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index f41dd68e..8585351d 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -341,6 +341,11 @@ tp_process_absolute(struct tp_dispatch *tp, t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; + case ABS_MT_TOOL_TYPE: + t->is_tool_palm = e->value == MT_TOOL_PALM; + t->dirty = true; + tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; + break; } } @@ -622,6 +627,31 @@ tp_palm_detect_trackpoint_triggered(struct tp_dispatch *tp, return false; } +static bool +tp_palm_detect_tool_triggered(struct tp_dispatch *tp, + struct tp_touch *t, + uint64_t time) +{ + if (!tp->palm.use_mt_tool) + return false; + + if (t->palm.state != PALM_NONE && + t->palm.state != PALM_TOOL_PALM) + return false; + + if (t->palm.state == PALM_NONE && + t->is_tool_palm) + t->palm.state = PALM_TOOL_PALM; + else if (t->palm.state == PALM_TOOL_PALM && + !t->is_tool_palm) + t->palm.state = PALM_NONE; + + if (t->palm.state == PALM_TOOL_PALM) + tp_stop_actions(tp, time); + + return t->palm.state == PALM_TOOL_PALM; +} + static inline bool tp_palm_detect_move_out_of_edge(struct tp_dispatch *tp, struct tp_touch *t, @@ -732,6 +762,9 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) if (tp_palm_detect_trackpoint_triggered(tp, t, time)) goto out; + if (tp_palm_detect_tool_triggered(tp, t, time)) + goto out; + if (tp_palm_detect_edge(tp, t, time)) goto out; @@ -750,6 +783,9 @@ out: case PALM_TRACKPOINT: palm_state = "trackpoint"; break; + case PALM_TOOL_PALM: + palm_state = "tool-palm"; + break; case PALM_NONE: default: abort(); @@ -2267,6 +2303,11 @@ tp_init_palmdetect(struct tp_dispatch *tp, tp->palm.monitor_trackpoint = true; + if (libevdev_has_event_code(device->evdev, + EV_ABS, + ABS_MT_TOOL_TYPE)) + tp->palm.use_mt_tool = true; + tp_init_palmdetect_edge(tp, device); } diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 2d531b5e..93dd37b4 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -66,6 +66,7 @@ enum touch_palm_state { PALM_EDGE, PALM_TYPING, PALM_TRACKPOINT, + PALM_TOOL_PALM, }; enum button_event { @@ -154,6 +155,7 @@ struct tp_touch { struct device_coords point; uint64_t millis; int pressure; + bool is_tool_palm; /* MT_TOOL_PALM */ bool was_down; /* if distance == 0, false for pure hovering touches */ @@ -347,6 +349,8 @@ struct tp_dispatch { uint64_t trackpoint_last_event_time; uint32_t trackpoint_event_count; bool monitor_trackpoint; + + bool use_mt_tool; } palm; struct { diff --git a/test/test-touchpad.c b/test/test-touchpad.c index c0de99bb..2731500a 100644 --- a/test/test-touchpad.c +++ b/test/test-touchpad.c @@ -1293,6 +1293,86 @@ START_TEST(touchpad_palm_detect_both_edges) } END_TEST +static inline bool +touchpad_has_tool_palm(struct litest_device *dev) +{ + return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE); +} + +START_TEST(touchpad_palm_detect_tool_palm) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (!touchpad_has_tool_palm(dev)) + return; + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10, 1); + litest_drain_events(li); + + litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10, 1); + litest_touch_up(dev, 0); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_palm_detect_tool_palm_on_off) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (!touchpad_has_tool_palm(dev)) + return; + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10, 1); + litest_drain_events(li); + + litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10, 1); + + litest_assert_empty_queue(li); + + litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_touch_move_to(dev, 0, 50, 40, 70, 70, 10, 1); + litest_touch_up(dev, 0); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); +} +END_TEST + +START_TEST(touchpad_palm_detect_tool_palm_tap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (!touchpad_has_tool_palm(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); + litest_touch_down(dev, 0, 50, 50); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_up(dev, 0); + libinput_dispatch(li); + litest_timeout_tap(); + + litest_assert_empty_queue(li); +} +END_TEST + START_TEST(touchpad_left_handed) { struct litest_device *dev = litest_current_device(); @@ -4987,6 +5067,9 @@ litest_setup_tests_touchpad(void) litest_add("touchpad:palm", touchpad_no_palm_detect_at_edge_for_edge_scrolling, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add("touchpad:palm", touchpad_no_palm_detect_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add("touchpad:palm", touchpad_palm_detect_both_edges, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm_on_off, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add("touchpad:left-handed", touchpad_left_handed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); litest_add_for_device("touchpad:left-handed", touchpad_left_handed_appletouch, LITEST_APPLETOUCH);