[PATCH libinput 3/3] Add a normalized_length helper function and use this where applicable
Hans de Goede
hdegoede at redhat.com
Tue Mar 24 05:14:19 PDT 2015
Add a normalized_length helper function and use this where applicable,
just a minor cleanup.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
src/evdev-mt-touchpad-tap.c | 10 +++-------
src/filter.c | 4 +---
src/libinput-private.h | 7 +++++++
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
index cb8fa2e..6a1ada5 100644
--- a/src/evdev-mt-touchpad-tap.c
+++ b/src/evdev-mt-touchpad-tap.c
@@ -530,14 +530,10 @@ 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 dc29928..dd4bd58 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 ec5caf6..4b3c174 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -24,6 +24,7 @@
#define LIBINPUT_PRIVATE_H
#include <errno.h>
+#include <math.h>
#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 */
--
2.3.3
More information about the wayland-devel
mailing list