mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 18:10:28 +01:00
Change vector_get_direction input to a normalized_coords struct
Change vector_get_direction input to a normalized_coords type rather 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@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
209215946b
commit
254f4f255f
4 changed files with 63 additions and 60 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue