dix: update pointer acceleration code to use ValuatorMask
Signed-off-by: Simon Thum <simon.thum@gmx.de> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
8128846e16
commit
a4b8526185
|
@ -791,17 +791,14 @@ moveRelative(DeviceIntPtr dev, int *x, int *y, ValuatorMask *mask)
|
||||||
* Accelerate the data in valuators based on the device's acceleration scheme.
|
* Accelerate the data in valuators based on the device's acceleration scheme.
|
||||||
*
|
*
|
||||||
* @param dev The device which's pointer is to be moved.
|
* @param dev The device which's pointer is to be moved.
|
||||||
* @param first The first valuator in @valuators
|
* @param valuators Valuator mask
|
||||||
* @param num Total number of valuators in @valuators.
|
|
||||||
* @param valuators Valuator data for each axis between @first and
|
|
||||||
* @first+@num.
|
|
||||||
* @param ms Current time.
|
* @param ms Current time.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
accelPointer(DeviceIntPtr dev, int first, int num, int *valuators, CARD32 ms)
|
accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
|
||||||
{
|
{
|
||||||
if (dev->valuator->accelScheme.AccelSchemeProc)
|
if (dev->valuator->accelScheme.AccelSchemeProc)
|
||||||
dev->valuator->accelScheme.AccelSchemeProc(dev, first, num, valuators, ms);
|
dev->valuator->accelScheme.AccelSchemeProc(dev, valuators, ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1170,20 +1167,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
|
||||||
moveAbsolute(pDev, &x, &y, &mask);
|
moveAbsolute(pDev, &x, &y, &mask);
|
||||||
} else {
|
} else {
|
||||||
if (flags & POINTER_ACCELERATE) {
|
if (flags & POINTER_ACCELERATE) {
|
||||||
/* FIXME: Pointer acceleration only requires X and Y values. This
|
accelPointer(pDev, &mask, ms);
|
||||||
* should be converted to masked valuators. */
|
|
||||||
int vals[2];
|
|
||||||
vals[0] = valuator_mask_isset(&mask, 0) ?
|
|
||||||
valuator_mask_get(&mask, 0) : 0;
|
|
||||||
vals[1] = valuator_mask_isset(&mask, 1) ?
|
|
||||||
valuator_mask_get(&mask, 1) : 0;
|
|
||||||
accelPointer(pDev, 0, 2, vals, ms);
|
|
||||||
|
|
||||||
if (valuator_mask_isset(&mask, 0))
|
|
||||||
valuator_mask_set(&mask, 0, vals[0]);
|
|
||||||
if (valuator_mask_isset(&mask, 1))
|
|
||||||
valuator_mask_set(&mask, 1, vals[1]);
|
|
||||||
|
|
||||||
/* The pointer acceleration code modifies the fractional part
|
/* The pointer acceleration code modifies the fractional part
|
||||||
* in-place, so we need to extract this information first */
|
* in-place, so we need to extract this information first */
|
||||||
x_frac = pDev->last.remainder[0];
|
x_frac = pDev->last.remainder[0];
|
||||||
|
|
125
dix/ptrveloc.c
125
dix/ptrveloc.c
|
@ -1071,32 +1071,28 @@ GetDevicePredictableAccelData(
|
||||||
void
|
void
|
||||||
acceleratePointerPredictable(
|
acceleratePointerPredictable(
|
||||||
DeviceIntPtr dev,
|
DeviceIntPtr dev,
|
||||||
int first_valuator,
|
ValuatorMask* val,
|
||||||
int num_valuators,
|
|
||||||
int *valuators,
|
|
||||||
int evtime)
|
int evtime)
|
||||||
{
|
{
|
||||||
float fdx, fdy, tmp, mult; /* no need to init */
|
float fdx, fdy, tmp, mult; /* no need to init */
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0, tmpi;
|
||||||
int *px = NULL, *py = NULL;
|
|
||||||
DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
|
DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
|
||||||
Bool soften = TRUE;
|
Bool soften = TRUE;
|
||||||
|
|
||||||
if (!num_valuators || !valuators || !velocitydata)
|
if (!velocitydata)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (velocitydata->statistics.profile_number == AccelProfileNone &&
|
if (velocitydata->statistics.profile_number == AccelProfileNone &&
|
||||||
velocitydata->const_acceleration == 1.0f) {
|
velocitydata->const_acceleration == 1.0f) {
|
||||||
return; /*we're inactive anyway, so skip the whole thing.*/
|
return; /*we're inactive anyway, so skip the whole thing.*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first_valuator == 0) {
|
if (valuator_mask_isset(val, 0)) {
|
||||||
dx = valuators[0];
|
dx = valuator_mask_get(val, 0);
|
||||||
px = &valuators[0];
|
|
||||||
}
|
}
|
||||||
if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) {
|
|
||||||
dy = valuators[1 - first_valuator];
|
if (valuator_mask_isset(val, 1)) {
|
||||||
py = &valuators[1 - first_valuator];
|
dy = valuator_mask_get(val, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dx || dy){
|
if (dx || dy){
|
||||||
|
@ -1108,15 +1104,15 @@ acceleratePointerPredictable(
|
||||||
if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
|
if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
|
||||||
/* invoke acceleration profile to determine acceleration */
|
/* invoke acceleration profile to determine acceleration */
|
||||||
mult = ComputeAcceleration (dev, velocitydata,
|
mult = ComputeAcceleration (dev, velocitydata,
|
||||||
dev->ptrfeed->ctrl.threshold,
|
dev->ptrfeed->ctrl.threshold,
|
||||||
(float)dev->ptrfeed->ctrl.num /
|
(float)dev->ptrfeed->ctrl.num /
|
||||||
(float)dev->ptrfeed->ctrl.den);
|
(float)dev->ptrfeed->ctrl.den);
|
||||||
|
|
||||||
if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
|
if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
|
||||||
ApplySofteningAndConstantDeceleration( velocitydata,
|
ApplySofteningAndConstantDeceleration(velocitydata,
|
||||||
dx, dy,
|
dx, dy,
|
||||||
&fdx, &fdy,
|
&fdx, &fdy,
|
||||||
(mult > 1.0f) && soften);
|
(mult > 1.0f) && soften);
|
||||||
|
|
||||||
if (dx) {
|
if (dx) {
|
||||||
tmp = mult * fdx + dev->last.remainder[0];
|
tmp = mult * fdx + dev->last.remainder[0];
|
||||||
|
@ -1125,13 +1121,15 @@ acceleratePointerPredictable(
|
||||||
* process each axis conditionally, there's no danger
|
* process each axis conditionally, there's no danger
|
||||||
* of a toggling remainder. Its lack of guarantees likely
|
* of a toggling remainder. Its lack of guarantees likely
|
||||||
* makes it faster on the average target. */
|
* makes it faster on the average target. */
|
||||||
*px = lrintf(tmp);
|
tmpi = lrintf(tmp);
|
||||||
dev->last.remainder[0] = tmp - (float)*px;
|
valuator_mask_set(val, 0, tmpi);
|
||||||
|
dev->last.remainder[0] = tmp - (float)tmpi;
|
||||||
}
|
}
|
||||||
if (dy) {
|
if (dy) {
|
||||||
tmp = mult * fdy + dev->last.remainder[1];
|
tmp = mult * fdy + dev->last.remainder[1];
|
||||||
*py = lrintf(tmp);
|
tmpi = lrintf(tmp);
|
||||||
dev->last.remainder[1] = tmp - (float)*py;
|
valuator_mask_set(val, 1, tmpi);
|
||||||
|
dev->last.remainder[1] = tmp - (float)tmpi;
|
||||||
}
|
}
|
||||||
DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n",
|
DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n",
|
||||||
*px, *py, dev->last.remainder[0], dev->last.remainder[1], fdx, fdy);
|
*px, *py, dev->last.remainder[0], dev->last.remainder[1], fdx, fdy);
|
||||||
|
@ -1152,25 +1150,18 @@ acceleratePointerPredictable(
|
||||||
void
|
void
|
||||||
acceleratePointerLightweight(
|
acceleratePointerLightweight(
|
||||||
DeviceIntPtr dev,
|
DeviceIntPtr dev,
|
||||||
int first_valuator,
|
ValuatorMask* val,
|
||||||
int num_valuators,
|
|
||||||
int *valuators,
|
|
||||||
int ignored)
|
int ignored)
|
||||||
{
|
{
|
||||||
float mult = 0.0;
|
float mult = 0.0, tmpf;
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0, tmpi;
|
||||||
int *px = NULL, *py = NULL;
|
|
||||||
|
|
||||||
if (!num_valuators || !valuators)
|
if (valuator_mask_isset(val, 0)) {
|
||||||
return;
|
dx = valuator_mask_get(val, 0);
|
||||||
|
|
||||||
if (first_valuator == 0) {
|
|
||||||
dx = valuators[0];
|
|
||||||
px = &valuators[0];
|
|
||||||
}
|
}
|
||||||
if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) {
|
|
||||||
dy = valuators[1 - first_valuator];
|
if (valuator_mask_isset(val, 1)) {
|
||||||
py = &valuators[1 - first_valuator];
|
dy = valuator_mask_get(val, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dx && !dy)
|
if (!dx && !dy)
|
||||||
|
@ -1180,45 +1171,45 @@ acceleratePointerLightweight(
|
||||||
/* modeled from xf86Events.c */
|
/* modeled from xf86Events.c */
|
||||||
if (dev->ptrfeed->ctrl.threshold) {
|
if (dev->ptrfeed->ctrl.threshold) {
|
||||||
if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) {
|
if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) {
|
||||||
dev->last.remainder[0] = ((float)dx *
|
tmpf = ((float)dx *
|
||||||
(float)(dev->ptrfeed->ctrl.num)) /
|
(float)(dev->ptrfeed->ctrl.num)) /
|
||||||
(float)(dev->ptrfeed->ctrl.den) +
|
(float)(dev->ptrfeed->ctrl.den) +
|
||||||
dev->last.remainder[0];
|
dev->last.remainder[0];
|
||||||
if (px) {
|
if (dx) {
|
||||||
*px = (int)dev->last.remainder[0];
|
tmpi = (int) tmpf;
|
||||||
dev->last.remainder[0] = dev->last.remainder[0] -
|
valuator_mask_set(val, 0, tmpi);
|
||||||
(float)(*px);
|
dev->last.remainder[0] = tmpf - (float)tmpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->last.remainder[1] = ((float)dy *
|
tmpf = ((float)dy *
|
||||||
(float)(dev->ptrfeed->ctrl.num)) /
|
(float)(dev->ptrfeed->ctrl.num)) /
|
||||||
(float)(dev->ptrfeed->ctrl.den) +
|
(float)(dev->ptrfeed->ctrl.den) +
|
||||||
dev->last.remainder[1];
|
dev->last.remainder[1];
|
||||||
if (py) {
|
if (dy) {
|
||||||
*py = (int)dev->last.remainder[1];
|
tmpi = (int) tmpf;
|
||||||
dev->last.remainder[1] = dev->last.remainder[1] -
|
valuator_mask_set(val, 1, tmpi);
|
||||||
(float)(*py);
|
dev->last.remainder[1] = tmpf - (float)tmpi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mult = pow((float)dx * (float)dx + (float)dy * (float)dy,
|
mult = pow((float)dx * (float)dx + (float)dy * (float)dy,
|
||||||
((float)(dev->ptrfeed->ctrl.num) /
|
((float)(dev->ptrfeed->ctrl.num) /
|
||||||
(float)(dev->ptrfeed->ctrl.den) - 1.0) /
|
(float)(dev->ptrfeed->ctrl.den) - 1.0) /
|
||||||
2.0) / 2.0;
|
2.0) / 2.0;
|
||||||
if (dx) {
|
if (dx) {
|
||||||
dev->last.remainder[0] = mult * (float)dx +
|
tmpf = mult * (float)dx +
|
||||||
dev->last.remainder[0];
|
dev->last.remainder[0];
|
||||||
*px = (int)dev->last.remainder[0];
|
tmpi = (int) tmpf;
|
||||||
dev->last.remainder[0] = dev->last.remainder[0] -
|
valuator_mask_set(val, 0, tmpi);
|
||||||
(float)(*px);
|
dev->last.remainder[0] = tmpf - (float)tmpi;
|
||||||
}
|
}
|
||||||
if (dy) {
|
if (dy) {
|
||||||
dev->last.remainder[1] = mult * (float)dy +
|
tmpf = mult * (float)dy +
|
||||||
dev->last.remainder[1];
|
dev->last.remainder[1];
|
||||||
*py = (int)dev->last.remainder[1];
|
tmpi = (int)tmpf;
|
||||||
dev->last.remainder[1] = dev->last.remainder[1] -
|
valuator_mask_set(val, 1, tmpi);
|
||||||
(float)(*py);
|
dev->last.remainder[1] = tmpf - (float)tmpi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,8 @@ typedef struct _ClassesRec *ClassesPtr;
|
||||||
typedef struct _SpriteRec *SpritePtr;
|
typedef struct _SpriteRec *SpritePtr;
|
||||||
typedef union _GrabMask GrabMask;
|
typedef union _GrabMask GrabMask;
|
||||||
|
|
||||||
|
typedef struct _ValuatorMask ValuatorMask;
|
||||||
|
|
||||||
typedef struct _EventList {
|
typedef struct _EventList {
|
||||||
xEvent* event;
|
xEvent* event;
|
||||||
int evlen; /* length of allocated memory for event in bytes. This is not
|
int evlen; /* length of allocated memory for event in bytes. This is not
|
||||||
|
@ -141,10 +143,8 @@ typedef void (*DeviceUnwrapProc)(
|
||||||
|
|
||||||
/* pointer acceleration handling */
|
/* pointer acceleration handling */
|
||||||
typedef void (*PointerAccelSchemeProc)(
|
typedef void (*PointerAccelSchemeProc)(
|
||||||
DeviceIntPtr /*pDev*/,
|
DeviceIntPtr /*device*/,
|
||||||
int /*first_valuator*/,
|
ValuatorMask* /*valuators*/,
|
||||||
int /*num_valuators*/,
|
|
||||||
int* /*valuators*/,
|
|
||||||
int /*evtime*/);
|
int /*evtime*/);
|
||||||
|
|
||||||
typedef void (*DeviceCallbackProc)(
|
typedef void (*DeviceCallbackProc)(
|
||||||
|
@ -163,8 +163,6 @@ typedef struct _DeviceRec {
|
||||||
Bool on; /* used by DDX to keep state */
|
Bool on; /* used by DDX to keep state */
|
||||||
} DeviceRec, *DevicePtr;
|
} DeviceRec, *DevicePtr;
|
||||||
|
|
||||||
typedef struct _ValuatorMask ValuatorMask;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int click, bell, bell_pitch, bell_duration;
|
int click, bell, bell_pitch, bell_duration;
|
||||||
Bool autoRepeat;
|
Bool autoRepeat;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Copyright © 2006-2009 Simon Thum simon dot thum at gmx dot de
|
* Copyright © 2006-2011 Simon Thum simon dot thum at gmx dot de
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef POINTERVELOCITY_H
|
#ifndef POINTERVELOCITY_H
|
||||||
#define POINTERVELOCITY_H
|
#define POINTERVELOCITY_H
|
||||||
|
|
||||||
#include <input.h> /* DeviceIntPtr */
|
#include <input.h>
|
||||||
|
|
||||||
/* constants for acceleration profiles */
|
/* constants for acceleration profiles */
|
||||||
|
|
||||||
|
@ -134,11 +134,9 @@ InitPredictableAccelerationScheme(DeviceIntPtr dev,
|
||||||
struct _ValuatorAccelerationRec* protoScheme);
|
struct _ValuatorAccelerationRec* protoScheme);
|
||||||
|
|
||||||
extern _X_INTERNAL void
|
extern _X_INTERNAL void
|
||||||
acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
|
acceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask* val, int evtime);
|
||||||
int num_valuators, int *valuators, int evtime);
|
|
||||||
|
|
||||||
extern _X_INTERNAL void
|
extern _X_INTERNAL void
|
||||||
acceleratePointerLightweight(DeviceIntPtr dev, int first_valuator,
|
acceleratePointerLightweight(DeviceIntPtr dev, ValuatorMask* val, int evtime);
|
||||||
int num_valuators, int *valuators, int ignored);
|
|
||||||
|
|
||||||
#endif /* POINTERVELOCITY_H */
|
#endif /* POINTERVELOCITY_H */
|
||||||
|
|
Loading…
Reference in New Issue