From 6e27a100b58588e3fc58ae8f6594eb4a1487d867 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 18 Jun 2019 10:16:33 +1000 Subject: [PATCH] touchpad: add a helper function for checking thumb state No functional changes Extracted from Matt Mayfield's thumb detection patches. Signed-off-by: Peter Hutterer --- meson.build | 1 + src/evdev-mt-touchpad-buttons.c | 5 ++--- src/evdev-mt-touchpad-edge-scroll.c | 3 +-- src/evdev-mt-touchpad-tap.c | 4 ++-- src/evdev-mt-touchpad-thumb.c | 32 ++++++++++++++++++++++++++++++++ src/evdev-mt-touchpad.c | 2 +- src/evdev-mt-touchpad.h | 3 +++ 7 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/evdev-mt-touchpad-thumb.c diff --git a/meson.build b/meson.build index ce0c4fc..d43828d 100644 --- a/meson.build +++ b/meson.build @@ -325,6 +325,7 @@ src_libinput = src_libfilter + [ 'src/evdev-mt-touchpad.c', 'src/evdev-mt-touchpad.h', 'src/evdev-mt-touchpad-tap.c', + 'src/evdev-mt-touchpad-thumb.c', 'src/evdev-mt-touchpad-buttons.c', 'src/evdev-mt-touchpad-edge-scroll.c', 'src/evdev-mt-touchpad-gestures.c', diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c index 11d1d6a..6e72193 100644 --- a/src/evdev-mt-touchpad-buttons.c +++ b/src/evdev-mt-touchpad-buttons.c @@ -1042,8 +1042,7 @@ tp_clickfinger_within_distance(struct tp_dispatch *tp, if (!t1 || !t2) return 0; - if (t1->thumb.state == THUMB_STATE_YES || - t2->thumb.state == THUMB_STATE_YES) + if (tp_thumb_ignored(tp, t1) || tp_thumb_ignored(tp, t2)) return 0; x = abs(t1->point.x - t2->point.x); @@ -1098,7 +1097,7 @@ tp_clickfinger_set_button(struct tp_dispatch *tp) if (t->state != TOUCH_BEGIN && t->state != TOUCH_UPDATE) continue; - if (t->thumb.state == THUMB_STATE_YES) + if (tp_thumb_ignored(tp, t)) continue; if (t->palm.state != PALM_NONE) diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c index 497e4bd..4675b4f 100644 --- a/src/evdev-mt-touchpad-edge-scroll.c +++ b/src/evdev-mt-touchpad-edge-scroll.c @@ -398,8 +398,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time) if (!t->dirty) continue; - if (t->palm.state != PALM_NONE || - t->thumb.state == THUMB_STATE_YES) + if (t->palm.state != PALM_NONE || tp_thumb_ignored(tp, t)) continue; /* only scroll with the finger in the previous edge */ diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 37853b3..551c70f 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -1015,7 +1015,7 @@ tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time) /* The simple version: if a touch is a thumb on * begin we ignore it. All other thumb touches * follow the normal tap state for now */ - if (t->thumb.state == THUMB_STATE_YES) { + if (tp_thumb_ignored(tp, t)) { t->tap.is_thumb = true; continue; } @@ -1040,7 +1040,7 @@ tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time) } t->tap.state = TAP_TOUCH_STATE_IDLE; } else if (tp->tap.state != TAP_STATE_IDLE && - t->thumb.state == THUMB_STATE_YES) { + tp_thumb_ignored(tp, t)) { tp_tap_handle_event(tp, t, TAP_EVENT_THUMB, time); } else if (tp->tap.state != TAP_STATE_IDLE && tp_tap_exceeds_motion_threshold(tp, t)) { diff --git a/src/evdev-mt-touchpad-thumb.c b/src/evdev-mt-touchpad-thumb.c new file mode 100644 index 0000000..b207f02 --- /dev/null +++ b/src/evdev-mt-touchpad-thumb.c @@ -0,0 +1,32 @@ +/* + * Copyright © 2019 Matt Mayfield + * Copyright © 2019 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" +#include "evdev-mt-touchpad.h" + +bool +tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t) +{ + return t->thumb.state == THUMB_STATE_YES; +} diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 6619501..ca7e74f 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -774,7 +774,7 @@ tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t) return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) && t->palm.state == PALM_NONE && !t->pinned.is_pinned && - t->thumb.state != THUMB_STATE_YES && + !tp_thumb_ignored(tp, t) && tp_button_touch_active(tp, t) && tp_edge_scroll_touch_active(tp, t); } diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 204fc25..aac47a7 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -677,4 +677,7 @@ tp_palm_tap_is_palm(const struct tp_dispatch *tp, const struct tp_touch *t); void tp_clickpad_middlebutton_apply_config(struct evdev_device *device); +bool +tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t); + #endif -- 2.7.4