From 674490ca60e085593ebaf8d17e4486d2a2036ced Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 24 Mar 2015 13:14:19 +0100 Subject: [PATCH] Add a normalized_length helper function and use this where applicable Add a normalized_length helper function and use this where applicable, just a minor cleanup. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-tap.c | 12 ++++-------- src/filter.c | 4 +--- src/libinput-private.h | 7 +++++++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 09713922..4ba4ad28 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -530,15 +530,11 @@ static bool tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp, struct tp_touch *t) { - int threshold = DEFAULT_TAP_MOVE_THRESHOLD; - struct normalized_coords normalized; + struct normalized_coords norm = + tp_normalize_delta(tp, device_delta(t->point, + t->tap.initial)); - normalized = tp_normalize_delta(tp, - device_delta(t->point, - t->tap.initial)); - - return normalized.x * normalized.x + normalized.y * normalized.y - > threshold * threshold; + return normalized_length(norm) > DEFAULT_TAP_MOVE_THRESHOLD; } static bool diff --git a/src/filter.c b/src/filter.c index dc299286..dd4bd58d 100644 --- a/src/filter.c +++ b/src/filter.c @@ -137,11 +137,9 @@ tracker_by_offset(struct pointer_accelerator *accel, unsigned int offset) static double calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time) { - double distance; double tdelta = time - tracker->time + 1; - distance = hypot(tracker->delta.x, tracker->delta.y); - return distance / tdelta; /* units/ms */ + return normalized_length(tracker->delta) / tdelta; /* units/ms */ } static double diff --git a/src/libinput-private.h b/src/libinput-private.h index 73f8d157..31f2dbc1 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -24,6 +24,7 @@ #define LIBINPUT_PRIVATE_H #include +#include #include "linux/input.h" @@ -373,4 +374,10 @@ device_delta(struct device_coords a, struct device_coords b) return delta; } +static inline double +normalized_length(struct normalized_coords norm) +{ + return hypot(norm.x, norm.y); +} + #endif /* LIBINPUT_PRIVATE_H */