diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index b5986952..7d6d838e 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -448,6 +448,8 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { const int PALM_TIMEOUT = 200; /* ms */ const int DIRECTIONS = NE|E|SE|SW|W|NW; + struct device_float_coords delta; + int dirs; /* If labelled a touch as palm, we unlabel as palm when we move out of the palm edge zone within the timeout, provided @@ -456,8 +458,9 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) if (t->palm.is_palm) { if (time < t->palm.time + PALM_TIMEOUT && (t->point.x > tp->palm.left_edge && t->point.x < tp->palm.right_edge)) { - int dirs = vector_get_direction(t->point.x - t->palm.first.x, - t->point.y - t->palm.first.y); + delta = device_delta(t->point, t->palm.first); + dirs = normalized_get_direction( + tp_normalize_delta(tp, delta)); if ((dirs & DIRECTIONS) && !(dirs & ~DIRECTIONS)) { t->palm.is_palm = false; } diff --git a/src/filter.c b/src/filter.c index dd4bd58d..033201fc 100644 --- a/src/filter.c +++ b/src/filter.c @@ -122,7 +122,7 @@ feed_trackers(struct pointer_accelerator *accel, trackers[current].delta.x = 0.0; trackers[current].delta.y = 0.0; trackers[current].time = time; - trackers[current].dir = vector_get_direction(delta->x, delta->y); + trackers[current].dir = normalized_get_direction(*delta); } static struct pointer_tracker * diff --git a/src/libinput-private.h b/src/libinput-private.h index 1da7db9d..36b3b40f 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -386,4 +386,61 @@ normalized_is_zero(struct normalized_coords norm) return norm.x == 0.0 && norm.y == 0.0; } +enum directions { + N = 1 << 0, + NE = 1 << 1, + E = 1 << 2, + SE = 1 << 3, + S = 1 << 4, + SW = 1 << 5, + W = 1 << 6, + NW = 1 << 7, + UNDEFINED_DIRECTION = 0xff +}; + +static inline int +normalized_get_direction(struct normalized_coords norm) +{ + int dir = UNDEFINED_DIRECTION; + int d1, d2; + double r; + + if (fabs(norm.x) < 2.0 && fabs(norm.y) < 2.0) { + if (norm.x > 0.0 && norm.y > 0.0) + dir = S | SE | E; + else if (norm.x > 0.0 && norm.y < 0.0) + dir = N | NE | E; + else if (norm.x < 0.0 && norm.y > 0.0) + dir = S | SW | W; + else if (norm.x < 0.0 && norm.y < 0.0) + dir = N | NW | W; + else if (norm.x > 0.0) + dir = NE | E | SE; + else if (norm.x < 0.0) + dir = NW | W | SW; + else if (norm.y > 0.0) + dir = SE | S | SW; + else if (norm.y < 0.0) + dir = NE | N | NW; + } else { + /* Calculate r within the interval [0 to 8) + * + * r = [0 .. 2π] where 0 is North + * d_f = r / 2π ([0 .. 1)) + * d_8 = 8 * d_f + */ + r = atan2(norm.y, norm.x); + r = fmod(r + 2.5*M_PI, 2*M_PI); + r *= 4*M_1_PI; + + /* Mark one or two close enough octants */ + d1 = (int)(r + 0.9) % 8; + d2 = (int)(r + 0.1) % 8; + + dir = (1 << d1) | (1 << d2); + } + + return dir; +} + #endif /* LIBINPUT_PRIVATE_H */ diff --git a/src/libinput-util.h b/src/libinput-util.h index 04515d6d..30f59ecf 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -98,63 +98,6 @@ msleep(unsigned int ms) usleep(ms * 1000); } -enum directions { - N = 1 << 0, - NE = 1 << 1, - E = 1 << 2, - SE = 1 << 3, - S = 1 << 4, - SW = 1 << 5, - W = 1 << 6, - NW = 1 << 7, - UNDEFINED_DIRECTION = 0xff -}; - -static inline int -vector_get_direction(double dx, double dy) -{ - int dir = UNDEFINED_DIRECTION; - int d1, d2; - double r; - - if (fabs(dx) < 2.0 && fabs(dy) < 2.0) { - if (dx > 0.0 && dy > 0.0) - dir = S | SE | E; - else if (dx > 0.0 && dy < 0.0) - dir = N | NE | E; - else if (dx < 0.0 && dy > 0.0) - dir = S | SW | W; - else if (dx < 0.0 && dy < 0.0) - dir = N | NW | W; - else if (dx > 0.0) - dir = NE | E | SE; - else if (dx < 0.0) - dir = NW | W | SW; - else if (dy > 0.0) - dir = SE | S | SW; - else if (dy < 0.0) - dir = NE | N | NW; - } else { - /* Calculate r within the interval [0 to 8) - * - * r = [0 .. 2π] where 0 is North - * d_f = r / 2π ([0 .. 1)) - * d_8 = 8 * d_f - */ - r = atan2(dy, dx); - r = fmod(r + 2.5*M_PI, 2*M_PI); - r *= 4*M_1_PI; - - /* Mark one or two close enough octants */ - d1 = (int)(r + 0.9) % 8; - d2 = (int)(r + 0.1) % 8; - - dir = (1 << d1) | (1 << d2); - } - - return dir; -} - static inline int long_bit_is_set(const unsigned long *array, int bit) {