diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 228eb84..62d3c80 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -37,7 +37,8 @@ #define CASE_RETURN_STRING(a) case a: return #a; #define DEFAULT_TAP_TIMEOUT_PERIOD 180 -#define DEFAULT_TAP_MOVE_THRESHOLD 30 +/* in mm for touchpads with resolution, see tp_init_accel() */ +#define DEFAULT_TAP_MOVE_THRESHOLD 3 * 25.4 enum tap_event { TAP_EVENT_TOUCH = 12, @@ -527,12 +528,15 @@ tp_tap_handle_event(struct tp_dispatch *tp, } static bool -tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp, struct tp_touch *t) +tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp, + struct tp_touch *t) { int threshold = DEFAULT_TAP_MOVE_THRESHOLD; double dx, dy; - tp_get_delta(t, &dx, &dy); + dx = abs(t->tap.initial_x - t->x); + dy = abs(t->tap.initial_y - t->y); + tp_normalize_delta(tp, &dx, &dy); return dx * dx + dy * dy > threshold * threshold; } @@ -568,6 +572,8 @@ tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time) if (t->state == TOUCH_BEGIN) { t->tap.state = TAP_TOUCH_STATE_TOUCH; + t->tap.initial_x = t->x; + t->tap.initial_y = t->y; tp_tap_handle_event(tp, t, TAP_EVENT_TOUCH, time); } else if (t->state == TOUCH_END) { tp_tap_handle_event(tp, t, TAP_EVENT_RELEASE, time); diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index b90d84c..9b06522 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -64,8 +64,8 @@ tp_filter_motion(struct tp_dispatch *tp, { struct motion_params motion; - motion.dx = *dx * tp->accel.x_scale_coeff; - motion.dy = *dy * tp->accel.y_scale_coeff; + motion.dx = *dx; + motion.dy = *dy; if (dx_unaccel) *dx_unaccel = motion.dx; @@ -269,6 +269,7 @@ tp_get_delta(struct tp_touch *t, double *dx, double *dy) tp_motion_history_offset(t, 1)->y, tp_motion_history_offset(t, 2)->y, tp_motion_history_offset(t, 3)->y); + tp_normalize_delta(t->tp, dx, dy); } static void diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index f04cc11..65581ae 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -162,6 +162,7 @@ struct tp_touch { struct { enum tp_tap_touch_state state; + int32_t initial_x, initial_y; } tap; struct { @@ -283,6 +284,13 @@ struct tp_dispatch { #define tp_for_each_touch(_tp, _t) \ for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++) +static inline void +tp_normalize_delta(struct tp_dispatch *tp, double *dx, double *dy) +{ + *dx = *dx * tp->accel.x_scale_coeff; + *dy = *dy * tp->accel.y_scale_coeff; +} + void tp_get_delta(struct tp_touch *t, double *dx, double *dy);