From c620cb1319093dca0f0241c04c4c227a40577bdc Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Fri, 14 May 2010 01:30:05 +0200 Subject: Add resting thumb detection to MTFinger Robust thumb detection is essential for more advanced gestures, thumbs being responsible for many false positives. One major feature of the thumb is that its shape is oval, regardless of applied pressure. An index finger pressed hard against the surface also turns oval, but the touch/width ratio then increases significantly. This suggests that it is possible to uniquely identify a resting thumb as a finger with oval shape and normal touch/with ratio. This patch adds detection of resting thumbs to the MTFinger structure. Signed-off-by: Henrik Rydberg --- src/mtstate.c | 26 ++++++++++++++++++++++++++ src/mtstate.h | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/mtstate.c b/src/mtstate.c index c3bcc78..1e2eeef 100644 --- a/src/mtstate.c +++ b/src/mtstate.c @@ -24,6 +24,11 @@ #define TOUCH_WIDTH(hw) (0.05 * hw->width_major) #define TOUCH_SCALE(caps) (0.05 * caps->abs_touch_major.maximum) +#define THUMB_TOUCH(hw) (1.2 * hw->touch_minor) +#define THUMB_WIDTH_TOUCH(hw) (3 * hw->touch_major) +#define THUMB_WIDTH_WIDTH(hw) (1.2 * hw->width_minor) +#define THUMB_WIDTH_SIZE(hw, caps) (0.15 * get_cap_xsize(caps)) + void init_mtstate(struct MTState *s) { memset(s, 0, sizeof(struct MTState)); @@ -39,12 +44,33 @@ static int touching_finger(const struct FingerData *hw, return 1; } +/* + * Thumb detection: + * + * The thumb is large and oval, even when not pressed hard against the + * surface. The width_major parameter is therefore bounded from below + * by all three values touch_major, width_minor, and trackpad size. + * + */ +static int thumb_finger(const struct FingerData *hw, + const struct Capabilities *caps) +{ + if (!caps->has_touch_major || !caps->has_touch_minor || + !caps->has_width_major || !caps->has_width_minor) + return 0; + return hw->touch_major > THUMB_TOUCH(hw) && + hw->width_major > THUMB_WIDTH_TOUCH(hw) && + hw->width_major > THUMB_WIDTH_WIDTH(hw) && + hw->width_major > THUMB_WIDTH_SIZE(hw, caps); +} + static int set_finger(struct MTFinger *f, const struct FingerState *fs, const struct Capabilities *caps) { f->hw = fs->hw; f->id = fs->id; + f->thumb = thumb_finger(&fs->hw, caps); } void extract_mtstate(struct MTState *s, diff --git a/src/mtstate.h b/src/mtstate.h index a8feaa4..ac0b18d 100644 --- a/src/mtstate.h +++ b/src/mtstate.h @@ -26,7 +26,7 @@ struct MTFinger { struct FingerData hw; - int id; + int id, thumb; }; struct MTState { -- cgit v1.2.3