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
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-22 18:03:19 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
#include <assert.h>
|
2014-05-18 19:20:39 +02:00
|
|
|
#include <stdio.h>
|
2012-05-17 12:18:17 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include "filter.h"
|
2014-07-14 16:19:33 +10:00
|
|
|
#include "libinput-util.h"
|
2014-07-04 09:29:11 +10:00
|
|
|
#include "filter-private.h"
|
2012-05-17 12:18:17 +02:00
|
|
|
|
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,
|
2015-03-19 11:02:51 +10:00
|
|
|
const struct normalized_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
|
|
|
}
|
|
|
|
|
|
2014-07-04 09:39:05 +10:00
|
|
|
void
|
|
|
|
|
filter_destroy(struct motion_filter *filter)
|
|
|
|
|
{
|
|
|
|
|
if (!filter)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filter->interface->destroy(filter);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
bool
|
|
|
|
|
filter_set_speed(struct motion_filter *filter,
|
|
|
|
|
double speed)
|
|
|
|
|
{
|
|
|
|
|
return filter->interface->set_speed(filter, speed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
filter_get_speed(struct motion_filter *filter)
|
|
|
|
|
{
|
|
|
|
|
return filter->speed;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-17 12:18:17 +02:00
|
|
|
/*
|
2014-05-18 19:20:39 +02:00
|
|
|
* Default parameters for pointer acceleration profiles.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-07-08 12:09:20 +10:00
|
|
|
#define DEFAULT_THRESHOLD 0.4 /* in units/ms */
|
2014-07-08 11:45:36 +10:00
|
|
|
#define DEFAULT_ACCELERATION 2.0 /* unitless factor */
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
#define DEFAULT_INCLINE 1.1 /* unitless factor */
|
2014-05-18 19:20:39 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Pointer acceleration filter constants
|
2012-05-17 12:18:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-07-08 11:45:36 +10:00
|
|
|
#define MAX_VELOCITY_DIFF 1.0 /* units/ms */
|
2012-05-17 12:18:17 +02:00
|
|
|
#define MOTION_TIMEOUT 300 /* (ms) */
|
|
|
|
|
#define NUM_POINTER_TRACKERS 16
|
|
|
|
|
|
|
|
|
|
struct pointer_tracker {
|
2015-03-19 11:02:51 +10:00
|
|
|
struct normalized_coords delta; /* delta to most recent event */
|
2014-07-08 11:45:36 +10:00
|
|
|
uint64_t time; /* ms */
|
2012-05-17 12:18:17 +02:00
|
|
|
int dir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct pointer_accelerator;
|
|
|
|
|
struct pointer_accelerator {
|
2013-11-10 17:55:40 +01:00
|
|
|
struct motion_filter base;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
accel_profile_func_t profile;
|
|
|
|
|
|
2014-07-08 11:45:36 +10:00
|
|
|
double velocity; /* units/ms */
|
|
|
|
|
double last_velocity; /* units/ms */
|
2015-03-19 11:02:51 +10:00
|
|
|
struct normalized_coords last;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
struct pointer_tracker *trackers;
|
|
|
|
|
int cur_tracker;
|
2014-07-03 15:32:40 +10:00
|
|
|
|
|
|
|
|
double threshold; /* units/ms */
|
|
|
|
|
double accel; /* unitless factor */
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
double incline; /* incline of the function */
|
2012-05-17 12:18:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
feed_trackers(struct pointer_accelerator *accel,
|
2015-03-19 11:02:51 +10:00
|
|
|
const struct normalized_coords *delta,
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
int i, current;
|
|
|
|
|
struct pointer_tracker *trackers = accel->trackers;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_POINTER_TRACKERS; i++) {
|
2015-03-19 11:02:51 +10:00
|
|
|
trackers[i].delta.x += delta->x;
|
|
|
|
|
trackers[i].delta.y += delta->y;
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current = (accel->cur_tracker + 1) % NUM_POINTER_TRACKERS;
|
|
|
|
|
accel->cur_tracker = current;
|
|
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
trackers[current].delta.x = 0.0;
|
|
|
|
|
trackers[current].delta.y = 0.0;
|
2012-05-17 12:18:17 +02:00
|
|
|
trackers[current].time = time;
|
2015-03-25 15:05:19 +01:00
|
|
|
trackers[current].dir = normalized_get_direction(*delta);
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct pointer_tracker *
|
|
|
|
|
tracker_by_offset(struct pointer_accelerator *accel, unsigned int offset)
|
|
|
|
|
{
|
|
|
|
|
unsigned int index =
|
|
|
|
|
(accel->cur_tracker + NUM_POINTER_TRACKERS - offset)
|
|
|
|
|
% NUM_POINTER_TRACKERS;
|
|
|
|
|
return &accel->trackers[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
2014-04-08 12:29:45 +02:00
|
|
|
calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
2015-03-19 11:33:55 +10:00
|
|
|
double tdelta = time - tracker->time + 1;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2015-03-24 13:14:19 +01:00
|
|
|
return normalized_length(tracker->delta) / tdelta; /* units/ms */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
2014-04-08 12:29:45 +02:00
|
|
|
calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
struct pointer_tracker *tracker;
|
|
|
|
|
double velocity;
|
|
|
|
|
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
|
|
|
double velocity_diff;
|
|
|
|
|
unsigned int offset;
|
|
|
|
|
|
|
|
|
|
unsigned int dir = tracker_by_offset(accel, 0)->dir;
|
|
|
|
|
|
|
|
|
|
/* Find least recent vector within a timelimit, maximum velocity diff
|
|
|
|
|
* and direction threshold. */
|
2014-05-24 21:49:13 +02:00
|
|
|
for (offset = 1; offset < NUM_POINTER_TRACKERS; offset++) {
|
2012-05-17 12:18:17 +02:00
|
|
|
tracker = tracker_by_offset(accel, offset);
|
|
|
|
|
|
|
|
|
|
/* Stop if too far away in time */
|
|
|
|
|
if (time - tracker->time > MOTION_TIMEOUT ||
|
|
|
|
|
tracker->time > time)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Stop if direction changed */
|
|
|
|
|
dir &= tracker->dir;
|
|
|
|
|
if (dir == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
velocity = calculate_tracker_velocity(tracker, time);
|
|
|
|
|
|
2014-05-24 21:49:13 +02:00
|
|
|
if (initial_velocity == 0.0) {
|
|
|
|
|
result = initial_velocity = velocity;
|
|
|
|
|
} else {
|
|
|
|
|
/* Stop if velocity differs too much from initial */
|
|
|
|
|
velocity_diff = fabs(initial_velocity - velocity);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-07-08 11:45:36 +10:00
|
|
|
return result; /* units/ms */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
|
|
|
|
acceleration_profile(struct pointer_accelerator *accel,
|
2014-04-08 12:29:45 +02:00
|
|
|
void *data, double velocity, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
return accel->profile(&accel->base, data, velocity, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
|
|
|
|
calculate_acceleration(struct pointer_accelerator *accel,
|
2014-04-08 12:29:45 +02:00
|
|
|
void *data, double velocity, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
double factor;
|
|
|
|
|
|
|
|
|
|
/* Use Simpson's rule to calculate the avarage acceleration between
|
|
|
|
|
* the previous motion and the most recent. */
|
|
|
|
|
factor = acceleration_profile(accel, data, velocity, time);
|
|
|
|
|
factor += acceleration_profile(accel, data, accel->last_velocity, time);
|
|
|
|
|
factor += 4.0 *
|
|
|
|
|
acceleration_profile(accel, data,
|
|
|
|
|
(accel->last_velocity + velocity) / 2,
|
|
|
|
|
time);
|
|
|
|
|
|
|
|
|
|
factor = factor / 6.0;
|
|
|
|
|
|
2014-07-08 11:45:36 +10:00
|
|
|
return factor; /* unitless factor */
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
static struct normalized_coords
|
2013-11-10 17:55:40 +01:00
|
|
|
accelerator_filter(struct motion_filter *filter,
|
2015-03-19 11:02:51 +10:00
|
|
|
const struct normalized_coords *unaccelerated,
|
2014-04-08 12:29:45 +02:00
|
|
|
void *data, uint64_t time)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
struct pointer_accelerator *accel =
|
|
|
|
|
(struct pointer_accelerator *) filter;
|
2014-07-08 11:45:36 +10:00
|
|
|
double velocity; /* units/ms */
|
|
|
|
|
double accel_value; /* unitless factor */
|
2015-03-19 11:02:51 +10:00
|
|
|
struct normalized_coords accelerated;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
feed_trackers(accel, unaccelerated, time);
|
2012-05-17 12:18:17 +02:00
|
|
|
velocity = calculate_velocity(accel, time);
|
|
|
|
|
accel_value = calculate_acceleration(accel, data, velocity, time);
|
|
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
accelerated.x = accel_value * unaccelerated->x;
|
|
|
|
|
accelerated.y = accel_value * unaccelerated->y;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
2015-03-19 11:02:51 +10:00
|
|
|
accel->last = *unaccelerated;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
accel->last_velocity = velocity;
|
2015-03-19 11:02:51 +10:00
|
|
|
|
|
|
|
|
return accelerated;
|
2012-05-17 12:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-11-10 17:55:40 +01:00
|
|
|
accelerator_destroy(struct motion_filter *filter)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
struct pointer_accelerator *accel =
|
|
|
|
|
(struct pointer_accelerator *) filter;
|
|
|
|
|
|
|
|
|
|
free(accel->trackers);
|
|
|
|
|
free(accel);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
static bool
|
|
|
|
|
accelerator_set_speed(struct motion_filter *filter,
|
|
|
|
|
double speed)
|
|
|
|
|
{
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
struct pointer_accelerator *accel_filter =
|
|
|
|
|
(struct pointer_accelerator *)filter;
|
|
|
|
|
|
2014-07-03 15:53:56 +10:00
|
|
|
assert(speed >= -1.0 && speed <= 1.0);
|
|
|
|
|
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
/* delay when accel kicks in */
|
2015-04-09 16:42:00 +02:00
|
|
|
accel_filter->threshold = DEFAULT_THRESHOLD - speed / 4.0;
|
|
|
|
|
if (accel_filter->threshold < 0.2)
|
|
|
|
|
accel_filter->threshold = 0.2;
|
2014-07-03 15:53:56 +10:00
|
|
|
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
/* adjust max accel factor */
|
2015-04-09 16:42:00 +02:00
|
|
|
accel_filter->accel = DEFAULT_ACCELERATION + speed * 1.5;
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
|
|
|
|
|
/* higher speed -> faster to reach max */
|
2015-04-09 16:42:00 +02:00
|
|
|
accel_filter->incline = DEFAULT_INCLINE + speed * 0.75;
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
|
|
|
|
|
filter->speed = speed;
|
2014-07-03 15:53:56 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
struct motion_filter_interface accelerator_interface = {
|
2012-05-17 12:18:17 +02:00
|
|
|
accelerator_filter,
|
2014-07-03 15:53:56 +10:00
|
|
|
accelerator_destroy,
|
|
|
|
|
accelerator_set_speed,
|
2012-05-17 12:18:17 +02:00
|
|
|
};
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
struct motion_filter *
|
2014-10-30 16:34:13 -05:00
|
|
|
create_pointer_accelerator_filter(accel_profile_func_t profile)
|
2012-05-17 12:18:17 +02:00
|
|
|
{
|
|
|
|
|
struct pointer_accelerator *filter;
|
|
|
|
|
|
2015-02-03 09:20:59 +10:00
|
|
|
filter = zalloc(sizeof *filter);
|
2012-05-17 12:18:17 +02:00
|
|
|
if (filter == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
filter->base.interface = &accelerator_interface;
|
|
|
|
|
|
|
|
|
|
filter->profile = profile;
|
|
|
|
|
filter->last_velocity = 0.0;
|
2015-03-19 11:02:51 +10:00
|
|
|
filter->last.x = 0;
|
|
|
|
|
filter->last.y = 0;
|
2012-05-17 12:18:17 +02:00
|
|
|
|
|
|
|
|
filter->trackers =
|
|
|
|
|
calloc(NUM_POINTER_TRACKERS, sizeof *filter->trackers);
|
|
|
|
|
filter->cur_tracker = 0;
|
|
|
|
|
|
2014-07-03 15:32:40 +10:00
|
|
|
filter->threshold = DEFAULT_THRESHOLD;
|
|
|
|
|
filter->accel = DEFAULT_ACCELERATION;
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
filter->incline = DEFAULT_INCLINE;
|
2014-07-03 15:32:40 +10:00
|
|
|
|
2012-05-17 12:18:17 +02:00
|
|
|
return &filter->base;
|
|
|
|
|
}
|
2014-05-26 23:20:42 +02:00
|
|
|
|
2014-05-18 19:20:39 +02:00
|
|
|
double
|
2014-09-19 11:10:17 +10:00
|
|
|
pointer_accel_profile_linear(struct motion_filter *filter,
|
|
|
|
|
void *data,
|
|
|
|
|
double speed_in,
|
|
|
|
|
uint64_t time)
|
2014-05-18 19:20:39 +02:00
|
|
|
{
|
2014-07-03 15:32:40 +10:00
|
|
|
struct pointer_accelerator *accel_filter =
|
|
|
|
|
(struct pointer_accelerator *)filter;
|
|
|
|
|
|
2014-09-19 11:10:17 +10:00
|
|
|
double s1, s2;
|
2014-07-03 15:32:40 +10:00
|
|
|
const double max_accel = accel_filter->accel; /* unitless factor */
|
|
|
|
|
const double threshold = accel_filter->threshold; /* units/ms */
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
const double incline = accel_filter->incline;
|
2014-09-19 11:10:17 +10:00
|
|
|
|
|
|
|
|
s1 = min(1, speed_in * 5);
|
filter: adjust acceleration curve depending on speed
The acceleration curve consists of four parts, in ascii-art like this:
_____________
/
____/
/
/
where the x axis is the speed, y is the acceleration factor.
The first plateau is at the acceleration factor 1 (i.e. unaccelerated
movement), the second plateau is at the max acceleration factor. The threshold
in the code defines where and how long the plateau is.
This patch adjusts the curve based on a [-1, 1] range. For anything below 0,
the plateau is longer (i.e. accel kicks in at a higher speed), the second
incline is flatter (i.e. accel kicks in slower) and the max accel factor is
lower (i.e. maximum speed is slower). For anything above 0, the inverse is
true, acceleration kicks in earlier, harder and is faster in general. So the
default/min/max curves overlaid look something like this:
________ max
| _______ default
| / _____ min
_|_/_/
/
/
Note that there's a limit to what ascii art can do...
Note that there are additional tweaks we can introduce later, such as
decreaseing the unaccelerated speed of the device (i.e. lowering the first
plateau).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-09-19 14:25:22 +10:00
|
|
|
s2 = 1 + (speed_in - threshold) * incline;
|
2014-09-19 11:10:17 +10:00
|
|
|
|
|
|
|
|
return min(max_accel, s2 > 1 ? s2 : s1);
|
2014-05-18 19:20:39 +02:00
|
|
|
}
|
2015-03-13 13:56:14 +10:00
|
|
|
|
|
|
|
|
double
|
|
|
|
|
touchpad_accel_profile_linear(struct motion_filter *filter,
|
|
|
|
|
void *data,
|
|
|
|
|
double speed_in,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
/* Once normalized, touchpads see the same
|
|
|
|
|
acceleration as mice. that is technically correct but
|
|
|
|
|
subjectively wrong, we expect a touchpad to be a lot
|
|
|
|
|
slower than a mouse. Apply a magic factor here and proceed
|
|
|
|
|
as normal. */
|
|
|
|
|
const double TP_MAGIC_SLOWDOWN = 0.4;
|
|
|
|
|
double speed_out;
|
|
|
|
|
|
|
|
|
|
speed_in *= TP_MAGIC_SLOWDOWN;
|
|
|
|
|
|
|
|
|
|
speed_out = pointer_accel_profile_linear(filter, data, speed_in, time);
|
|
|
|
|
|
|
|
|
|
return speed_out * TP_MAGIC_SLOWDOWN;
|
|
|
|
|
}
|
2015-04-23 14:32:40 -04:00
|
|
|
|
|
|
|
|
double
|
|
|
|
|
touchpad_lenovo_x230_accel_profile(struct motion_filter *filter,
|
|
|
|
|
void *data,
|
|
|
|
|
double speed_in,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
/* Keep the magic factor from touchpad_accel_profile_linear. */
|
|
|
|
|
const double TP_MAGIC_SLOWDOWN = 0.4;
|
|
|
|
|
|
|
|
|
|
/* Those touchpads presents an actual lower resolution that what is
|
|
|
|
|
* advertised. We see some jumps from the cursor due to the big steps
|
|
|
|
|
* in X and Y when we are receiving data.
|
|
|
|
|
* Apply a factor to minimize those jumps at low speed, and try
|
|
|
|
|
* keeping the same feeling as regular touchpads at high speed.
|
|
|
|
|
* It still feels slower but it is usable at least */
|
|
|
|
|
const double TP_MAGIC_LOW_RES_FACTOR = 4.0;
|
|
|
|
|
double speed_out;
|
|
|
|
|
struct pointer_accelerator *accel_filter =
|
|
|
|
|
(struct pointer_accelerator *)filter;
|
|
|
|
|
|
|
|
|
|
double s1, s2;
|
|
|
|
|
const double max_accel = accel_filter->accel *
|
|
|
|
|
TP_MAGIC_LOW_RES_FACTOR; /* unitless factor */
|
|
|
|
|
const double threshold = accel_filter->threshold /
|
|
|
|
|
TP_MAGIC_LOW_RES_FACTOR; /* units/ms */
|
|
|
|
|
const double incline = accel_filter->incline * TP_MAGIC_LOW_RES_FACTOR;
|
|
|
|
|
|
|
|
|
|
speed_in *= TP_MAGIC_SLOWDOWN / TP_MAGIC_LOW_RES_FACTOR;
|
|
|
|
|
|
|
|
|
|
s1 = min(1, speed_in * 5);
|
|
|
|
|
s2 = 1 + (speed_in - threshold) * incline;
|
|
|
|
|
|
|
|
|
|
speed_out = min(max_accel, s2 > 1 ? s2 : s1);
|
|
|
|
|
|
|
|
|
|
return speed_out * TP_MAGIC_SLOWDOWN / TP_MAGIC_LOW_RES_FACTOR;
|
|
|
|
|
}
|