diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2015-07-28 16:02:05 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2015-08-12 14:06:00 +1000 |
commit | 4c1c572b19dec80b5d08125272f2f635ada2bd57 (patch) | |
tree | ee5ecea6825b8d2d4c2b107c68e4e34bb7251a7e /src | |
parent | e1be2f54cad745b4c6d8764f3352c1be50729985 (diff) |
filter: split trackpoint acceleration out
This is step one to fixing trackpoint acceleration, separating it from the
other acceleration code. No functional changes yet, it still uses the low-dpi
accel method.
https://bugs.freedesktop.org/show_bug.cgi?id=91369
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/evdev.c | 4 | ||||
-rw-r--r-- | src/filter.c | 87 | ||||
-rw-r--r-- | src/filter.h | 8 |
3 files changed, 98 insertions, 1 deletions
diff --git a/src/evdev.c b/src/evdev.c index bb31724..22d51dc 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1861,7 +1861,9 @@ evdev_init_accel(struct evdev_device *device) { struct motion_filter *filter; - if (device->dpi < DEFAULT_MOUSE_DPI) + if (device->tags & EVDEV_TAG_TRACKPOINT) + filter = create_pointer_accelerator_filter_trackpoint(device->dpi); + else if (device->dpi < DEFAULT_MOUSE_DPI) filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi); else filter = create_pointer_accelerator_filter_linear(device->dpi); diff --git a/src/filter.c b/src/filter.c index 0c3e1de..7054faf 100644 --- a/src/filter.c +++ b/src/filter.c @@ -343,6 +343,36 @@ accelerator_filter_low_dpi(struct motion_filter *filter, } static struct normalized_coords +accelerator_filter_trackpoint(struct motion_filter *filter, + const struct normalized_coords *unaccelerated, + void *data, uint64_t time) +{ + struct pointer_accelerator *accel = + (struct pointer_accelerator *) filter; + double accel_value; /* unitless factor */ + struct normalized_coords accelerated; + struct normalized_coords unnormalized; + double dpi_factor = accel->dpi_factor; + + /* trackpoints with a dpi factor have a const accel set, remove that + * and restore device units. The accel profile takes const accel + * into account */ + dpi_factor = min(1.0, dpi_factor); + unnormalized.x = unaccelerated->x * dpi_factor; + unnormalized.y = unaccelerated->y * dpi_factor; + + accel_value = calculate_acceleration_factor(accel, + &unnormalized, + data, + time); + + accelerated.x = accel_value * unnormalized.x; + accelerated.y = accel_value * unnormalized.y; + + return accelerated; +} + +static struct normalized_coords accelerator_filter_x230(struct motion_filter *filter, const struct normalized_coords *unaccelerated, void *data, uint64_t time) @@ -609,6 +639,38 @@ touchpad_lenovo_x230_accel_profile(struct motion_filter *filter, return factor * TP_MAGIC_SLOWDOWN / TP_MAGIC_LOW_RES_FACTOR; } +double +trackpoint_accel_profile(struct motion_filter *filter, + void *data, + double speed_in, /* 1000-dpi normalized */ + uint64_t time) +{ + struct pointer_accelerator *accel_filter = + (struct pointer_accelerator *)filter; + double max_accel = accel_filter->accel; /* unitless factor */ + double threshold = accel_filter->threshold; /* units/ms */ + const double incline = accel_filter->incline; + double factor; + double dpi_factor = accel_filter->dpi_factor; + + /* dpi_factor is always < 1.0, increase max_accel, reduce + the threshold so it kicks in earlier */ + max_accel /= dpi_factor; + threshold *= dpi_factor; + + /* see pointer_accel_profile_linear for a long description */ + if (v_us2ms(speed_in) < 0.07) + factor = 10 * v_us2ms(speed_in) + 0.3; + else if (speed_in < threshold) + factor = 1; + else + factor = incline * v_us2ms(speed_in - threshold) + 1; + + factor = min(max_accel, factor); + + return factor; +} + struct motion_filter_interface accelerator_interface = { accelerator_filter, accelerator_restart, @@ -728,3 +790,28 @@ create_pointer_accelerator_filter_lenovo_x230(int dpi) return &filter->base; } + +struct motion_filter_interface accelerator_interface_trackpoint = { + accelerator_filter_trackpoint, + accelerator_restart, + accelerator_destroy, + accelerator_set_speed, +}; + +struct motion_filter * +create_pointer_accelerator_filter_trackpoint(int dpi) +{ + struct pointer_accelerator *filter; + + filter = create_default_filter(dpi); + if (!filter) + return NULL; + + filter->base.interface = &accelerator_interface_trackpoint; + filter->profile = trackpoint_accel_profile; + filter->threshold = DEFAULT_THRESHOLD; + filter->accel = DEFAULT_ACCELERATION; + filter->incline = DEFAULT_INCLINE; + + return &filter->base; +} diff --git a/src/filter.h b/src/filter.h index 76fc147..fd36da4 100644 --- a/src/filter.h +++ b/src/filter.h @@ -71,6 +71,9 @@ create_pointer_accelerator_filter_touchpad(int dpi); struct motion_filter * create_pointer_accelerator_filter_lenovo_x230(int dpi); +struct motion_filter * +create_pointer_accelerator_filter_trackpoint(int dpi); + /* * Pointer acceleration profiles. */ @@ -95,4 +98,9 @@ touchpad_lenovo_x230_accel_profile(struct motion_filter *filter, void *data, double speed_in, uint64_t time); +double +trackpoint_accel_profile(struct motion_filter *filter, + void *data, + double speed_in, + uint64_t time); #endif /* FILTER_H */ |