Makes it possible to use from the touchpad code. Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net> --- src/filter.c | 60 ++--------------------------------------------------- src/libinput-util.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 58 deletions(-)
diff --git a/src/filter.c b/src/filter.c index e1fb2a9..d65adfb 100644 --- a/src/filter.c +++ b/src/filter.c @@ -29,6 +29,7 @@ #include <math.h> #include "filter.h" +#include "libinput-util.h" void filter_dispatch(struct motion_filter *filter, @@ -84,63 +85,6 @@ struct pointer_accelerator { int cur_tracker; }; -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 int -get_direction(int dx, int dy) -{ - int dir = UNDEFINED_DIRECTION; - int d1, d2; - double r; - - if (abs(dx) < 2 && abs(dy) < 2) { - if (dx > 0 && dy > 0) - dir = S | SE | E; - else if (dx > 0 && dy < 0) - dir = N | NE | E; - else if (dx < 0 && dy > 0) - dir = S | SW | W; - else if (dx < 0 && dy < 0) - dir = N | NW | W; - else if (dx > 0) - dir = NE | E | SE; - else if (dx < 0) - dir = NW | W | SW; - else if (dy > 0) - dir = SE | S | SW; - else if (dy < 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 void feed_trackers(struct pointer_accelerator *accel, double dx, double dy, @@ -160,7 +104,7 @@ feed_trackers(struct pointer_accelerator *accel, trackers[current].dx = 0.0; trackers[current].dy = 0.0; trackers[current].time = time; - trackers[current].dir = get_direction(dx, dy); + trackers[current].dir = vector_get_direction(dx, dy); } static struct pointer_tracker * diff --git a/src/libinput-util.h b/src/libinput-util.h index 2558a3d..c0235ef 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -24,6 +24,7 @@ #define LIBINPUT_UTIL_H #include <unistd.h> +#include <math.h> #include "libinput.h" @@ -92,4 +93,61 @@ 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(int dx, int dy) +{ + int dir = UNDEFINED_DIRECTION; + int d1, d2; + double r; + + if (abs(dx) < 2 && abs(dy) < 2) { + if (dx > 0 && dy > 0) + dir = S | SE | E; + else if (dx > 0 && dy < 0) + dir = N | NE | E; + else if (dx < 0 && dy > 0) + dir = S | SW | W; + else if (dx < 0 && dy < 0) + dir = N | NW | W; + else if (dx > 0) + dir = NE | E | SE; + else if (dx < 0) + dir = NW | W | SW; + else if (dy > 0) + dir = SE | S | SW; + else if (dy < 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; +} + #endif /* LIBINPUT_UTIL_H */ -- 1.9.3 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel