From: Peter Hutterer Date: Thu, 19 Mar 2015 01:02:51 +0000 (+1000) Subject: filter: switch to normalized_coords X-Git-Tag: 0.13.0~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69d5bbbeba90ca67825db868a272e84777b33a1d;p=platform%2Fupstream%2Flibinput.git filter: switch to normalized_coords Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 998249f..d4995c9 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -64,21 +64,27 @@ tp_filter_motion(struct tp_dispatch *tp, double *dx_unaccel, double *dy_unaccel, uint64_t time) { - struct motion_params motion; + struct normalized_coords unaccelerated; + struct normalized_coords accelerated; - motion.dx = *dx; - motion.dy = *dy; + unaccelerated.x = *dx; + unaccelerated.y = *dy; + + if (unaccelerated.x != 0.0 || unaccelerated.y != 0.0) + accelerated = filter_dispatch(tp->device->pointer.filter, + &unaccelerated, + tp, + time); + else + accelerated = unaccelerated; if (dx_unaccel) - *dx_unaccel = motion.dx; + *dx_unaccel = unaccelerated.x; if (dy_unaccel) - *dy_unaccel = motion.dy; - - if (motion.dx != 0.0 || motion.dy != 0.0) - filter_dispatch(tp->device->pointer.filter, &motion, tp, time); + *dy_unaccel = unaccelerated.y; - *dx = motion.dx; - *dy = motion.dy; + *dx = accelerated.x; + *dy = accelerated.y; } static inline void diff --git a/src/evdev.c b/src/evdev.c index 284aa1f..bcaf338 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -238,7 +238,6 @@ static void evdev_flush_pending_event(struct evdev_device *device, uint64_t time) { struct libinput *libinput = device->base.seat->libinput; - struct motion_params motion; int slot; int seat_slot; struct libinput_device *base = &device->base; @@ -267,11 +266,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time) } /* Apply pointer acceleration. */ - motion.dx = unaccel.x; - motion.dy = unaccel.y; - filter_dispatch(device->pointer.filter, &motion, device, time); - accel.x = motion.dx; - accel.y = motion.dy; + accel = filter_dispatch(device->pointer.filter, &unaccel, device, time); if (accel.x == 0.0 && accel.y == 0.0 && unaccel.x == 0.0 && unaccel.y == 0.0) { diff --git a/src/filter-private.h b/src/filter-private.h index f0d35b4..0e796f1 100644 --- a/src/filter-private.h +++ b/src/filter-private.h @@ -28,9 +28,10 @@ #include "filter.h" struct motion_filter_interface { - void (*filter)(struct motion_filter *filter, - struct motion_params *motion, - void *data, uint64_t time); + struct normalized_coords (*filter)( + struct motion_filter *filter, + const struct normalized_coords *unaccelerated, + void *data, uint64_t time); void (*destroy)(struct motion_filter *filter); bool (*set_speed)(struct motion_filter *filter, double speed); diff --git a/src/filter.c b/src/filter.c index 306a2fe..7e935bf 100644 --- a/src/filter.c +++ b/src/filter.c @@ -33,12 +33,12 @@ #include "libinput-util.h" #include "filter-private.h" -void +struct normalized_coords filter_dispatch(struct motion_filter *filter, - struct motion_params *motion, + const struct normalized_coords *unaccelerated, void *data, uint64_t time) { - filter->interface->filter(filter, motion, data, time); + return filter->interface->filter(filter, unaccelerated, data, time); } void @@ -80,8 +80,7 @@ filter_get_speed(struct motion_filter *filter) #define NUM_POINTER_TRACKERS 16 struct pointer_tracker { - double dx; /* delta to most recent event, in device units */ - double dy; /* delta to most recent event, in device units */ + struct normalized_coords delta; /* delta to most recent event */ uint64_t time; /* ms */ int dir; }; @@ -94,8 +93,7 @@ struct pointer_accelerator { double velocity; /* units/ms */ double last_velocity; /* units/ms */ - int last_dx; /* device units */ - int last_dy; /* device units */ + struct normalized_coords last; struct pointer_tracker *trackers; int cur_tracker; @@ -107,24 +105,24 @@ struct pointer_accelerator { static void feed_trackers(struct pointer_accelerator *accel, - double dx, double dy, + const struct normalized_coords *delta, uint64_t time) { int i, current; struct pointer_tracker *trackers = accel->trackers; for (i = 0; i < NUM_POINTER_TRACKERS; i++) { - trackers[i].dx += dx; - trackers[i].dy += dy; + trackers[i].delta.x += delta->x; + trackers[i].delta.y += delta->y; } current = (accel->cur_tracker + 1) % NUM_POINTER_TRACKERS; accel->cur_tracker = current; - trackers[current].dx = 0.0; - trackers[current].dy = 0.0; + trackers[current].delta.x = 0.0; + trackers[current].delta.y = 0.0; trackers[current].time = time; - trackers[current].dir = vector_get_direction(dx, dy); + trackers[current].dir = vector_get_direction(delta->x, delta->y); } static struct pointer_tracker * @@ -139,13 +137,9 @@ tracker_by_offset(struct pointer_accelerator *accel, unsigned int offset) static double calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time) { - double dx; - double dy; double distance; - dx = tracker->dx; - dy = tracker->dy; - distance = sqrt(dx*dx + dy*dy); + distance = hypot(tracker->delta.x, tracker->delta.y); return distance / (double)(time - tracker->time); /* units/ms */ } @@ -220,27 +214,29 @@ calculate_acceleration(struct pointer_accelerator *accel, return factor; /* unitless factor */ } -static void +static struct normalized_coords accelerator_filter(struct motion_filter *filter, - struct motion_params *motion, + const struct normalized_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; double velocity; /* units/ms */ double accel_value; /* unitless factor */ + struct normalized_coords accelerated; - feed_trackers(accel, motion->dx, motion->dy, time); + feed_trackers(accel, unaccelerated, time); velocity = calculate_velocity(accel, time); accel_value = calculate_acceleration(accel, data, velocity, time); - motion->dx = accel_value * motion->dx; - motion->dy = accel_value * motion->dy; + accelerated.x = accel_value * unaccelerated->x; + accelerated.y = accel_value * unaccelerated->y; - accel->last_dx = motion->dx; - accel->last_dy = motion->dy; + accel->last = *unaccelerated; accel->last_velocity = velocity; + + return accelerated; } static void @@ -294,8 +290,8 @@ create_pointer_accelerator_filter(accel_profile_func_t profile) filter->profile = profile; filter->last_velocity = 0.0; - filter->last_dx = 0; - filter->last_dy = 0; + filter->last.x = 0; + filter->last.y = 0; filter->trackers = calloc(NUM_POINTER_TRACKERS, sizeof *filter->trackers); diff --git a/src/filter.h b/src/filter.h index f23b691..70363a6 100644 --- a/src/filter.h +++ b/src/filter.h @@ -28,15 +28,13 @@ #include #include -struct motion_params { - double dx, dy; /* in units/ms @ DEFAULT_MOUSE_DPI resolution */ -}; +#include "libinput-private.h" struct motion_filter; -void +struct normalized_coords filter_dispatch(struct motion_filter *filter, - struct motion_params *motion, + const struct normalized_coords *unaccelerated, void *data, uint64_t time); void filter_destroy(struct motion_filter *filter);