[PATCH libinput 2/2] Change vector_get_direction input to a normalized_coords struct
Peter Hutterer
peter.hutterer at who-t.net
Thu Mar 26 17:32:25 PDT 2015
On Thu, Mar 26, 2015 at 09:57:27AM +0100, Hans de Goede wrote:
> Change vector_get_direction input to a normalized_coords type rather then
typo, then -> than
> passing in a separate x,y pair, and rename it normalized_get_direction to
> match. Since it now depends on the normalized_coords type which gets declared
> in libinput-private.h also move it to libinput-private.h .
>
> Note this commit also contains a functional change wrt the get_direction
> usuage in the palm detection. The palm-detection code was calling get_direction
> on non normalized coordinates, this commits changes the code to normalize
> the coordinates first. This is the right thing to do as calling get_direction
> on non normalized coordinates may result in a wrong direction getting returned
> when the x and y resolution of the touchpad are not identical.
>
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
> src/evdev-mt-touchpad.c | 5 +++--
> src/filter.c | 2 +-
> src/libinput-private.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
> src/libinput-util.h | 57 -------------------------------------------------
> 4 files changed, 61 insertions(+), 60 deletions(-)
>
> diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
> index b598695..8985352 100644
> --- a/src/evdev-mt-touchpad.c
> +++ b/src/evdev-mt-touchpad.c
> @@ -448,6 +448,7 @@ 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;
> + 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 +457,8 @@ 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);
> + dirs = normalized_get_direction(tp_normalize_delta(tp,
> + device_delta(t->point, t->palm.first)));
can we use a tmp variable for delta here? the nesting here makes it a bit confusing
what is an argument to what.
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> for both, otherwise.
Cheers,
Peter
> if ((dirs & DIRECTIONS) && !(dirs & ~DIRECTIONS)) {
> t->palm.is_palm = false;
> }
> diff --git a/src/filter.c b/src/filter.c
> index dd4bd58..033201f 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 1da7db9..36b3b40 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 04515d6..30f59ec 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)
> {
> --
> 2.3.3
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
More information about the wayland-devel
mailing list