From fe93145f8653a3f3136445768a1e84bcce903d84 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 24 Mar 2015 13:14:18 +0100 Subject: [PATCH] Add a delta_coords type and use it were applicable tp_normalize_coords is one of the last functions taking separate x, y values rather a coordinate pair, this commit cleans this up. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-edge-scroll.c | 10 +++------- src/evdev-mt-touchpad-tap.c | 7 +++---- src/evdev-mt-touchpad.c | 25 ++++++++++++------------- src/evdev-mt-touchpad.h | 14 ++++++++------ src/libinput-private.h | 20 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c index d304316a..91ebd28c 100644 --- a/src/evdev-mt-touchpad-edge-scroll.c +++ b/src/evdev-mt-touchpad-edge-scroll.c @@ -313,7 +313,6 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time) struct tp_touch *t; enum libinput_pointer_axis axis; double *delta; - double initial_dx, initial_dy; struct normalized_coords normalized; const struct normalized_coords zero = { 0.0, 0.0 }; const struct discrete_coords zero_discrete = { 0.0, 0.0 }; @@ -361,12 +360,9 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time) t->scroll.edge_state); break; case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW: - initial_dx = t->point.x - t->scroll.initial.x; - initial_dy = t->point.y - t->scroll.initial.y; - tp_normalize_delta(tp, - initial_dx, - initial_dy, - &normalized); + normalized = tp_normalize_delta(tp, + device_delta(t->point, + t->scroll.initial)); if (fabs(*delta) < DEFAULT_SCROLL_THRESHOLD) normalized = zero; break; diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 6bd7c582..09713922 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -531,12 +531,11 @@ tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp, struct tp_touch *t) { int threshold = DEFAULT_TAP_MOVE_THRESHOLD; - double dx, dy; struct normalized_coords normalized; - dx = abs(t->tap.initial.x - t->point.x); - dy = abs(t->tap.initial.y - t->point.y); - tp_normalize_delta(tp, dx, dy, &normalized); + normalized = tp_normalize_delta(tp, + device_delta(t->point, + t->tap.initial)); return normalized.x * normalized.x + normalized.y * normalized.y > threshold * threshold; diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 856af4a2..37ad13a6 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -261,23 +261,22 @@ tp_estimate_delta(int x0, int x1, int x2, int x3) struct normalized_coords tp_get_delta(struct tp_touch *t) { - double dx, dy; /* in device coords */ - struct normalized_coords normalized = { 0.0, 0.0 }; + struct delta_coords delta; + const struct normalized_coords zero = { 0.0, 0.0 }; if (t->history.count < TOUCHPAD_MIN_SAMPLES) - return normalized; + return zero; - dx = tp_estimate_delta(tp_motion_history_offset(t, 0)->x, - tp_motion_history_offset(t, 1)->x, - tp_motion_history_offset(t, 2)->x, - tp_motion_history_offset(t, 3)->x); - dy = tp_estimate_delta(tp_motion_history_offset(t, 0)->y, - 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, &normalized); + delta.dx = tp_estimate_delta(tp_motion_history_offset(t, 0)->x, + tp_motion_history_offset(t, 1)->x, + tp_motion_history_offset(t, 2)->x, + tp_motion_history_offset(t, 3)->x); + delta.dy = tp_estimate_delta(tp_motion_history_offset(t, 0)->y, + tp_motion_history_offset(t, 1)->y, + tp_motion_history_offset(t, 2)->y, + tp_motion_history_offset(t, 3)->y); - return normalized; + return tp_normalize_delta(t->tp, delta); } static void diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 9980f900..0c6d87ee 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -274,13 +274,15 @@ 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, - struct normalized_coords *normalized) +static inline struct normalized_coords +tp_normalize_delta(struct tp_dispatch *tp, struct delta_coords delta) { - normalized->x = dx * tp->accel.x_scale_coeff; - normalized->y = dy * tp->accel.y_scale_coeff; + struct normalized_coords normalized; + + normalized.x = delta.dx * tp->accel.x_scale_coeff; + normalized.y = delta.dy * tp->accel.y_scale_coeff; + + return normalized; } struct normalized_coords diff --git a/src/libinput-private.h b/src/libinput-private.h index e39ac5ea..73f8d157 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -37,6 +37,14 @@ struct device_coords { int x, y; }; +/* + * A delta between 2 device coordinates, + * may be non-discrete because of averaging. + */ +struct delta_coords { + double dx, dy; +}; + /* A dpi-normalized coordinate pair */ struct normalized_coords { double x, y; @@ -353,4 +361,16 @@ libinput_now(struct libinput *libinput) return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000; } + +static inline struct delta_coords +device_delta(struct device_coords a, struct device_coords b) +{ + struct delta_coords delta; + + delta.dx = a.x - b.x; + delta.dy = a.y - b.y; + + return delta; +} + #endif /* LIBINPUT_PRIVATE_H */