mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-06 13:00:15 +01:00
filter: switch to normalized_coords
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
ea1c39f702
commit
69d5bbbeba
5 changed files with 47 additions and 51 deletions
|
|
@ -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;
|
||||
*dy_unaccel = unaccelerated.y;
|
||||
|
||||
if (motion.dx != 0.0 || motion.dy != 0.0)
|
||||
filter_dispatch(tp->device->pointer.filter, &motion, tp, time);
|
||||
|
||||
*dx = motion.dx;
|
||||
*dy = motion.dy;
|
||||
*dx = accelerated.x;
|
||||
*dy = accelerated.y;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
50
src/filter.c
50
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);
|
||||
|
|
|
|||
|
|
@ -28,15 +28,13 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue