[PATCH libinput 2/3] touchpad: convert normalized_length to physical coordinates
Peter Hutterer
peter.hutterer at who-t.net
Tue Jan 24 05:46:06 UTC 2017
Now that the acceleration code doesn't use dpi-normalized coordinates anymore,
we don't need to use them in the touchpad code. Switch to physical distances
instead, it makes debugging a lot saner.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evdev-mt-touchpad-gestures.c | 10 ++++++----
src/evdev-mt-touchpad-tap.c | 9 ++++-----
src/evdev-mt-touchpad.c | 7 +++----
src/evdev-mt-touchpad.h | 12 ++++++++++++
src/libinput-private.h | 6 ++++++
5 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index de3ec4f..9ba5942 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -186,18 +186,20 @@ tp_gesture_get_direction(struct tp_dispatch *tp, struct tp_touch *touch,
unsigned int nfingers)
{
struct normalized_coords normalized;
+ struct phys_coords mm;
struct device_float_coords delta;
- double move_threshold = TP_MM_TO_DPI_NORMALIZED(1);
+ double move_threshold = 1.0; /* mm */
move_threshold *= (nfingers - 1);
delta = device_delta(touch->point, touch->gesture.initial);
+ mm = tp_phys_delta(tp, delta);
- normalized = tp_normalize_delta(tp, delta);
-
- if (normalized_length(normalized) < move_threshold)
+ if (length_in_mm(mm) < move_threshold)
return UNDEFINED_DIRECTION;
+ normalized = tp_normalize_delta(tp, delta);
+
return normalized_get_direction(normalized);
}
diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
index ffd9d0b..9fba521 100644
--- a/src/evdev-mt-touchpad-tap.c
+++ b/src/evdev-mt-touchpad-tap.c
@@ -36,7 +36,7 @@
#define DEFAULT_TAP_INITIAL_TIMEOUT_PERIOD ms2us(100)
#define DEFAULT_TAP_TIMEOUT_PERIOD ms2us(180)
#define DEFAULT_DRAG_TIMEOUT_PERIOD ms2us(300)
-#define DEFAULT_TAP_MOVE_THRESHOLD TP_MM_TO_DPI_NORMALIZED(1.3)
+#define DEFAULT_TAP_MOVE_THRESHOLD 1.3 /* mm */
enum tap_event {
TAP_EVENT_TOUCH = 12,
@@ -734,11 +734,10 @@ static bool
tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp,
struct tp_touch *t)
{
- struct normalized_coords norm =
- tp_normalize_delta(tp, device_delta(t->point,
- t->tap.initial));
+ struct phys_coords mm =
+ tp_phys_delta(tp, device_delta(t->point, t->tap.initial));
- return normalized_length(norm) > DEFAULT_TAP_MOVE_THRESHOLD;
+ return length_in_mm(mm) > DEFAULT_TAP_MOVE_THRESHOLD;
}
static bool
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index ca00c40..fe9e642 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -751,12 +751,11 @@ tp_thumb_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
t->thumb.initial = t->point;
else if (t->state == TOUCH_UPDATE) {
struct device_float_coords delta;
- struct normalized_coords normalized;
+ struct phys_coords mm;
delta = device_delta(t->point, t->thumb.initial);
- normalized = tp_normalize_delta(tp, delta);
- if (normalized_length(normalized) >
- TP_MM_TO_DPI_NORMALIZED(7)) {
+ mm = tp_phys_delta(tp, delta);
+ if (length_in_mm(mm) > 7) {
t->thumb.state = THUMB_STATE_NO;
goto out;
}
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index b9ca5bf..fb15956 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -399,6 +399,18 @@ tp_normalize_delta(const struct tp_dispatch *tp,
return normalized;
}
+static inline struct phys_coords
+tp_phys_delta(const struct tp_dispatch *tp,
+ struct device_float_coords delta)
+{
+ struct phys_coords mm;
+
+ mm.x = delta.x / tp->device->abs.absinfo_x->resolution;
+ mm.y = delta.y / tp->device->abs.absinfo_y->resolution;
+
+ return mm;
+}
+
/**
* Takes a dpi-normalized set of coordinates, returns a set of coordinates
* in the x-axis' coordinate space.
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 40cc926..2bd523e 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -699,6 +699,12 @@ normalized_is_zero(struct normalized_coords norm)
return norm.x == 0.0 && norm.y == 0.0;
}
+static inline double
+length_in_mm(struct phys_coords mm)
+{
+ return hypot(mm.x, mm.y);
+}
+
enum directions {
N = 1 << 0,
NE = 1 << 1,
--
2.9.3
More information about the wayland-devel
mailing list