2012-05-17 12:18:17 +02:00
|
|
|
/*
|
2015-05-06 13:14:23 +10:00
|
|
|
* Copyright © 2006-2009 Simon Thum
|
2012-05-17 12:18:17 +02:00
|
|
|
* Copyright © 2012 Jonas Ådahl
|
2015-05-28 08:23:59 +10:00
|
|
|
* Copyright © 2014-2015 Red Hat, Inc.
|
2012-05-17 12:18:17 +02:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2012-05-17 12:18:17 +02:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2012-05-17 12:18:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2013-05-22 18:03:19 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
#include <assert.h>
|
2012-05-17 12:18:17 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdint.h>
|
2014-05-18 19:20:39 +02:00
|
|
|
#include <stdio.h>
|
2012-05-17 12:18:17 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2014-07-04 09:29:11 +10:00
|
|
|
#include "filter-private.h"
|
2012-05-17 12:18:17 +02:00
|
|
|
#include "filter.h"
|
2014-07-14 16:19:33 +10:00
|
|
|
#include "libinput-util.h"
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2018-04-11 11:41:16 +10:00
|
|
|
#define MOTION_TIMEOUT ms2us(1000)
|
|
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
struct normalized_coords
|
2013-11-10 17:55:40 +01:00
|
|
|
filter_dispatch(struct motion_filter *filter,
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
const struct device_float_coords *unaccelerated,
|
2014-04-08 12:29:45 +02:00
|
|
|
void *data,
|
|
|
|
|
uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2015-03-19 11:02:51 +10:00
|
|
|
return filter->interface->filter(filter, unaccelerated, data, time);
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:32:20 +10:00
|
|
|
struct normalized_coords
|
|
|
|
|
filter_dispatch_constant(struct motion_filter *filter,
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
const struct device_float_coords *unaccelerated,
|
2015-08-17 16:32:20 +10:00
|
|
|
void *data,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
return filter->interface->filter_constant(filter, unaccelerated, data, time);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 21:12:13 +02:00
|
|
|
struct normalized_coords
|
|
|
|
|
filter_dispatch_scroll(struct motion_filter *filter,
|
|
|
|
|
const struct device_float_coords *unaccelerated,
|
|
|
|
|
void *data,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
return filter->interface->filter_scroll(filter, unaccelerated, data, time);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 09:54:06 +10:00
|
|
|
void
|
|
|
|
|
filter_restart(struct motion_filter *filter, void *data, uint64_t time)
|
|
|
|
|
{
|
2015-08-27 13:13:47 +10:00
|
|
|
if (filter->interface->restart)
|
|
|
|
|
filter->interface->restart(filter, data, time);
|
2015-06-10 09:54:06 +10:00
|
|
|
}
|
|
|
|
|
|
2014-07-04 09:39:05 +10:00
|
|
|
void
|
|
|
|
|
filter_destroy(struct motion_filter *filter)
|
|
|
|
|
{
|
2015-08-27 13:13:47 +10:00
|
|
|
if (!filter || !filter->interface->destroy)
|
2014-07-04 09:39:05 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filter->interface->destroy(filter);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
bool
|
|
|
|
|
filter_set_speed(struct motion_filter *filter, double speed_adjustment)
|
|
|
|
|
{
|
2015-08-04 15:48:40 +10:00
|
|
|
return filter->interface->set_speed(filter, speed_adjustment);
|
2014-07-03 15:53:56 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
filter_get_speed(struct motion_filter *filter)
|
|
|
|
|
{
|
2015-08-04 15:48:40 +10:00
|
|
|
return filter->speed_adjustment;
|
2014-07-03 15:53:56 +10:00
|
|
|
}
|
|
|
|
|
|
2015-08-27 13:13:47 +10:00
|
|
|
enum libinput_config_accel_profile
|
|
|
|
|
filter_get_type(struct motion_filter *filter)
|
|
|
|
|
{
|
|
|
|
|
return filter->interface->type;
|
|
|
|
|
}
|
|
|
|
|
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
bool
|
|
|
|
|
filter_set_accel_config(struct motion_filter *filter,
|
|
|
|
|
struct libinput_config_accel *accel_config)
|
|
|
|
|
{
|
|
|
|
|
assert(filter_get_type(filter) == accel_config->profile);
|
|
|
|
|
|
|
|
|
|
if (!filter->interface->set_accel_config)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return filter->interface->set_accel_config(filter, accel_config);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 12:56:22 +10:00
|
|
|
void
|
2018-08-17 15:12:58 +02:00
|
|
|
trackers_init(struct pointer_trackers *trackers, int ntrackers)
|
2017-11-28 14:30:26 +10:00
|
|
|
{
|
|
|
|
|
trackers->trackers = zalloc(ntrackers * sizeof(*trackers->trackers));
|
|
|
|
|
trackers->ntrackers = ntrackers;
|
|
|
|
|
trackers->cur_tracker = 0;
|
2018-04-10 13:25:53 +10:00
|
|
|
trackers->smoothener = NULL;
|
2017-11-28 14:30:26 +10:00
|
|
|
}
|
|
|
|
|
|
2018-04-10 16:26:46 +10:00
|
|
|
void
|
2018-04-11 11:49:15 +10:00
|
|
|
trackers_free(struct pointer_trackers *trackers)
|
2018-04-10 16:26:46 +10:00
|
|
|
{
|
|
|
|
|
free(trackers->trackers);
|
2022-11-22 11:34:06 +10:00
|
|
|
pointer_delta_smoothener_destroy(trackers->smoothener);
|
2018-04-10 16:26:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2018-04-11 11:49:15 +10:00
|
|
|
trackers_reset(struct pointer_trackers *trackers, uint64_t time)
|
2018-04-10 16:26:46 +10:00
|
|
|
{
|
|
|
|
|
unsigned int offset;
|
|
|
|
|
struct pointer_tracker *tracker;
|
|
|
|
|
|
|
|
|
|
for (offset = 1; offset < trackers->ntrackers; offset++) {
|
2018-04-11 11:49:15 +10:00
|
|
|
tracker = trackers_by_offset(trackers, offset);
|
2018-04-10 16:26:46 +10:00
|
|
|
tracker->time = 0;
|
|
|
|
|
tracker->dir = 0;
|
|
|
|
|
tracker->delta.x = 0;
|
|
|
|
|
tracker->delta.y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 11:49:15 +10:00
|
|
|
tracker = trackers_by_offset(trackers, 0);
|
2018-04-10 16:26:46 +10:00
|
|
|
tracker->time = time;
|
|
|
|
|
tracker->dir = UNDEFINED_DIRECTION;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 12:56:22 +10:00
|
|
|
void
|
2018-04-11 11:49:15 +10:00
|
|
|
trackers_feed(struct pointer_trackers *trackers,
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
const struct device_float_coords *delta,
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2017-11-28 14:30:26 +10:00
|
|
|
unsigned int i, current;
|
|
|
|
|
struct pointer_tracker *ts = trackers->trackers;
|
|
|
|
|
|
|
|
|
|
assert(trackers->ntrackers);
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2017-11-28 14:30:26 +10:00
|
|
|
for (i = 0; i < trackers->ntrackers; i++) {
|
|
|
|
|
ts[i].delta.x += delta->x;
|
|
|
|
|
ts[i].delta.y += delta->y;
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-28 14:30:26 +10:00
|
|
|
current = (trackers->cur_tracker + 1) % trackers->ntrackers;
|
|
|
|
|
trackers->cur_tracker = current;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2017-11-28 14:30:26 +10:00
|
|
|
ts[current].delta.x = 0.0;
|
|
|
|
|
ts[current].delta.y = 0.0;
|
|
|
|
|
ts[current].time = time;
|
|
|
|
|
ts[current].dir = device_float_get_direction(*delta);
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-10 12:56:22 +10:00
|
|
|
struct pointer_tracker *
|
2018-04-11 11:49:15 +10:00
|
|
|
trackers_by_offset(struct pointer_trackers *trackers, unsigned int offset)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2017-11-28 14:30:26 +10:00
|
|
|
unsigned int index = (trackers->cur_tracker + trackers->ntrackers - offset) %
|
|
|
|
|
trackers->ntrackers;
|
|
|
|
|
return &trackers->trackers[index];
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
2022-09-02 14:53:45 +10:00
|
|
|
calculate_trackers_velocity(const struct pointer_tracker *tracker,
|
|
|
|
|
uint64_t time,
|
|
|
|
|
struct pointer_delta_smoothener *smoothener)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2017-07-02 16:35:35 +02:00
|
|
|
uint64_t tdelta = time - tracker->time + 1;
|
|
|
|
|
|
2018-04-10 13:25:53 +10:00
|
|
|
if (smoothener && tdelta < smoothener->threshold)
|
|
|
|
|
tdelta = smoothener->value;
|
2017-07-02 16:35:35 +02:00
|
|
|
|
|
|
|
|
return hypot(tracker->delta.x, tracker->delta.y) /
|
|
|
|
|
(double)tdelta; /* units/us */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-10 13:25:53 +10:00
|
|
|
static double
|
2022-09-02 14:53:45 +10:00
|
|
|
trackers_velocity_after_timeout(const struct pointer_tracker *tracker,
|
|
|
|
|
struct pointer_delta_smoothener *smoothener)
|
2015-04-22 12:25:13 +10:00
|
|
|
{
|
|
|
|
|
/* First movement after timeout needs special handling.
|
|
|
|
|
*
|
|
|
|
|
* When we trigger the timeout, the last event is too far in the
|
|
|
|
|
* past to use it for velocity calculation across multiple tracker
|
|
|
|
|
* values.
|
|
|
|
|
*
|
|
|
|
|
* Use the motion timeout itself to calculate the speed rather than
|
|
|
|
|
* the last tracker time. This errs on the side of being too fast
|
|
|
|
|
* for really slow movements but provides much more useful initial
|
|
|
|
|
* movement in normal use-cases (pause, move, pause, move)
|
|
|
|
|
*/
|
2018-04-11 11:49:15 +10:00
|
|
|
return calculate_trackers_velocity(tracker,
|
2022-09-02 14:18:26 +10:00
|
|
|
tracker->time + MOTION_TIMEOUT,
|
|
|
|
|
smoothener);
|
2015-04-22 12:25:13 +10:00
|
|
|
}
|
|
|
|
|
|
2016-12-13 15:31:27 +10:00
|
|
|
/**
|
|
|
|
|
* Calculate the velocity based on the tracker data. Velocity is averaged
|
|
|
|
|
* across multiple historical values, provided those values aren't "too
|
|
|
|
|
* different" to our current one. That includes either being too far in the
|
|
|
|
|
* past, moving into a different direction or having too much of a velocity
|
|
|
|
|
* change between events.
|
|
|
|
|
*/
|
2018-04-10 15:12:58 +10:00
|
|
|
double
|
2018-04-11 11:49:15 +10:00
|
|
|
trackers_velocity(struct pointer_trackers *trackers, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2018-04-24 14:28:01 +10:00
|
|
|
const double MAX_VELOCITY_DIFF = v_ms2us(1); /* units/us */
|
2012-05-17 12:18:17 +02:00
|
|
|
double result = 0.0;
|
2014-05-24 21:49:13 +02:00
|
|
|
double initial_velocity = 0.0;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2018-04-11 11:49:15 +10:00
|
|
|
unsigned int dir = trackers_by_offset(trackers, 0)->dir;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
/* Find least recent vector within a timelimit, maximum velocity diff
|
|
|
|
|
* and direction threshold. */
|
2022-09-05 08:48:12 +10:00
|
|
|
for (unsigned int offset = 1; offset < trackers->ntrackers; offset++) {
|
|
|
|
|
const struct pointer_tracker *tracker =
|
|
|
|
|
trackers_by_offset(trackers, offset);
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2016-12-13 15:28:29 +10:00
|
|
|
/* Bug: time running backwards */
|
|
|
|
|
if (tracker->time > time)
|
|
|
|
|
break;
|
|
|
|
|
|
2012-05-17 12:18:17 +02:00
|
|
|
/* Stop if too far away in time */
|
2016-12-13 15:28:29 +10:00
|
|
|
if (time - tracker->time > MOTION_TIMEOUT) {
|
2015-04-22 12:25:13 +10:00
|
|
|
if (offset == 1)
|
2018-04-11 11:49:15 +10:00
|
|
|
result = trackers_velocity_after_timeout(
|
2018-04-10 13:25:53 +10:00
|
|
|
tracker,
|
|
|
|
|
trackers->smoothener);
|
2012-05-17 12:18:17 +02:00
|
|
|
break;
|
2015-04-22 12:25:13 +10:00
|
|
|
}
|
|
|
|
|
|
2022-09-05 08:48:12 +10:00
|
|
|
double velocity = calculate_trackers_velocity(tracker,
|
|
|
|
|
time,
|
|
|
|
|
trackers->smoothener);
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
/* Stop if direction changed */
|
|
|
|
|
dir &= tracker->dir;
|
2015-04-22 12:25:13 +10:00
|
|
|
if (dir == 0) {
|
|
|
|
|
/* First movement after dirchange - velocity is that
|
|
|
|
|
* of the last movement */
|
|
|
|
|
if (offset == 1)
|
|
|
|
|
result = velocity;
|
2012-05-17 12:18:17 +02:00
|
|
|
break;
|
2015-04-22 12:25:13 +10:00
|
|
|
}
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2018-04-24 15:01:39 +10:00
|
|
|
/* Always average the first two events. On some touchpads
|
|
|
|
|
* where the first event is jumpy, this somewhat reduces
|
|
|
|
|
* pointer jumps on slow motions. */
|
|
|
|
|
if (initial_velocity == 0.0 || offset <= 2) {
|
2014-05-24 21:49:13 +02:00
|
|
|
result = initial_velocity = velocity;
|
|
|
|
|
} else {
|
|
|
|
|
/* Stop if velocity differs too much from initial */
|
2022-09-05 08:48:12 +10:00
|
|
|
double velocity_diff = fabs(initial_velocity - velocity);
|
2014-05-24 21:49:13 +02:00
|
|
|
if (velocity_diff > MAX_VELOCITY_DIFF)
|
|
|
|
|
break;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2014-05-24 21:49:13 +02:00
|
|
|
result = velocity;
|
|
|
|
|
}
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-04 15:45:53 +10:00
|
|
|
return result; /* units/us */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
/**
|
|
|
|
|
* Calculate the acceleration factor for our current velocity, averaging
|
|
|
|
|
* between our current and the most recent velocity to smoothen out changes.
|
|
|
|
|
*
|
|
|
|
|
* @param accel The acceleration filter
|
|
|
|
|
* @param data Caller-specific data
|
2022-09-02 14:18:26 +10:00
|
|
|
* @param velocity Velocity - depending on the caller this may be in
|
|
|
|
|
* device-units per µs or normalized per µs
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
* @param last_velocity Previous velocity in device-units per µs
|
|
|
|
|
* @param time Current time in µs
|
|
|
|
|
*
|
|
|
|
|
* @return A unitless acceleration factor, to be applied to the delta
|
|
|
|
|
*/
|
2018-04-10 16:20:45 +10:00
|
|
|
double
|
|
|
|
|
calculate_acceleration_simpsons(struct motion_filter *filter,
|
|
|
|
|
accel_profile_func_t profile,
|
|
|
|
|
void *data,
|
|
|
|
|
double velocity,
|
|
|
|
|
double last_velocity,
|
|
|
|
|
uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
double factor;
|
|
|
|
|
|
2020-08-27 19:52:34 +02:00
|
|
|
/* Use Simpson's rule to calculate the average acceleration between
|
2012-05-17 12:18:17 +02:00
|
|
|
* the previous motion and the most recent. */
|
2018-04-10 16:20:45 +10:00
|
|
|
factor = profile(filter, data, velocity, time);
|
|
|
|
|
factor += profile(filter, data, last_velocity, time);
|
|
|
|
|
factor += 4.0 * profile(filter, data, (last_velocity + velocity) / 2, time);
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
factor = factor / 6.0;
|
|
|
|
|
|
2014-07-08 11:45:36 +10:00
|
|
|
return factor; /* unitless factor */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|