dix: rename pDev->dev, pVel->vel for consistency

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Simon Thum 2009-06-24 11:33:19 +02:00 committed by Peter Hutterer
parent 373e8c960d
commit 2830e84937
2 changed files with 173 additions and 172 deletions

View File

@ -61,12 +61,12 @@
/* fwds */ /* fwds */
int int
SetAccelerationProfile(DeviceVelocityPtr s, int profile_num); SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
static float static float
SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity, SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity,
float threshold, float acc); float threshold, float acc);
static PointerAccelerationProfileFunc static PointerAccelerationProfileFunc
GetAccelerationProfile(DeviceVelocityPtr s, int profile_num); GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
/*#define PTRACCEL_DEBUGGING*/ /*#define PTRACCEL_DEBUGGING*/
@ -87,21 +87,21 @@ GetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
* Init struct so it should match the average case * Init struct so it should match the average case
*/ */
void void
InitVelocityData(DeviceVelocityPtr s) InitVelocityData(DeviceVelocityPtr vel)
{ {
memset(s, 0, sizeof(DeviceVelocityRec)); memset(vel, 0, sizeof(DeviceVelocityRec));
s->corr_mul = 10.0; /* dots per 10 milisecond should be usable */ vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */
s->const_acceleration = 1.0; /* no acceleration/deceleration */ vel->const_acceleration = 1.0; /* no acceleration/deceleration */
s->reset_time = 300; vel->reset_time = 300;
s->use_softening = 1; vel->use_softening = 1;
s->min_acceleration = 1.0; /* don't decelerate */ vel->min_acceleration = 1.0; /* don't decelerate */
s->max_rel_diff = 0.2; vel->max_rel_diff = 0.2;
s->max_diff = 1.0; vel->max_diff = 1.0;
s->initial_range = 2; vel->initial_range = 2;
s->average_accel = TRUE; vel->average_accel = TRUE;
SetAccelerationProfile(s, AccelProfileClassic); SetAccelerationProfile(vel, AccelProfileClassic);
InitTrackers(s, 16); InitTrackers(vel, 16);
} }
@ -109,9 +109,9 @@ InitVelocityData(DeviceVelocityPtr s)
* Clean up * Clean up
*/ */
void void
FreeVelocityData(DeviceVelocityPtr s){ FreeVelocityData(DeviceVelocityPtr vel){
xfree(s->tracker); xfree(vel->tracker);
SetAccelerationProfile(s, PROFILE_UNINITIALIZE); SetAccelerationProfile(vel, PROFILE_UNINITIALIZE);
} }
@ -119,15 +119,15 @@ FreeVelocityData(DeviceVelocityPtr s){
* dix uninit helper, called through scheme * dix uninit helper, called through scheme
*/ */
void void
AccelerationDefaultCleanup(DeviceIntPtr pDev) AccelerationDefaultCleanup(DeviceIntPtr dev)
{ {
/*sanity check*/ /*sanity check*/
if( pDev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable if( dev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable
&& pDev->valuator->accelScheme.accelData != NULL){ && dev->valuator->accelScheme.accelData != NULL){
pDev->valuator->accelScheme.AccelSchemeProc = NULL; dev->valuator->accelScheme.AccelSchemeProc = NULL;
FreeVelocityData(pDev->valuator->accelScheme.accelData); FreeVelocityData(dev->valuator->accelScheme.accelData);
xfree(pDev->valuator->accelScheme.accelData); xfree(dev->valuator->accelScheme.accelData);
pDev->valuator->accelScheme.accelData = NULL; dev->valuator->accelScheme.accelData = NULL;
} }
} }
@ -143,7 +143,7 @@ static int
AccelSetProfileProperty(DeviceIntPtr dev, Atom atom, AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly) XIPropertyValuePtr val, BOOL checkOnly)
{ {
DeviceVelocityPtr pVel; DeviceVelocityPtr vel;
int profile, *ptr = &profile; int profile, *ptr = &profile;
int rc; int rc;
int nelem = 1; int nelem = 1;
@ -151,8 +151,8 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER)) if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER))
return Success; return Success;
pVel = GetDevicePredictableAccelData(dev); vel = GetDevicePredictableAccelData(dev);
if (!pVel) if (!vel)
return BadValue; return BadValue;
rc = XIPropToInt(val, &nelem, &ptr); rc = XIPropToInt(val, &nelem, &ptr);
@ -161,18 +161,18 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
if (rc) if (rc)
return rc; return rc;
if (GetAccelerationProfile(pVel, profile) == NULL) if (GetAccelerationProfile(vel, profile) == NULL)
return BadValue; return BadValue;
} else } else
SetAccelerationProfile(pVel, profile); SetAccelerationProfile(vel, profile);
return Success; return Success;
} }
static void static void
AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
{ {
int profile = pVel->statistics.profile_number; int profile = vel->statistics.profile_number;
Atom prop_profile_number = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER); Atom prop_profile_number = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32, XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32,
@ -188,7 +188,7 @@ static int
AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly) XIPropertyValuePtr val, BOOL checkOnly)
{ {
DeviceVelocityPtr pVel; DeviceVelocityPtr vel;
float v, *ptr = &v; float v, *ptr = &v;
int rc; int rc;
int nelem = 1; int nelem = 1;
@ -196,8 +196,8 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION)) if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION))
return Success; return Success;
pVel = GetDevicePredictableAccelData(dev); vel = GetDevicePredictableAccelData(dev);
if (!pVel) if (!vel)
return BadValue; return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr); rc = XIPropToFloat(val, &nelem, &ptr);
@ -209,15 +209,15 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
} }
if(v >= 1.0f) if(v >= 1.0f)
pVel->const_acceleration = 1/v; vel->const_acceleration = 1/v;
return Success; return Success;
} }
static void static void
AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
{ {
float fval = 1.0/pVel->const_acceleration; float fval = 1.0/vel->const_acceleration;
Atom prop_const_decel = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION); Atom prop_const_decel = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
XIChangeDeviceProperty(dev, prop_const_decel, XIChangeDeviceProperty(dev, prop_const_decel,
XIGetKnownProperty(XATOM_FLOAT), 32, XIGetKnownProperty(XATOM_FLOAT), 32,
@ -234,7 +234,7 @@ static int
AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly) XIPropertyValuePtr val, BOOL checkOnly)
{ {
DeviceVelocityPtr pVel; DeviceVelocityPtr veloc;
float v, *ptr = &v; float v, *ptr = &v;
int rc; int rc;
int nelem = 1; int nelem = 1;
@ -242,8 +242,8 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION)) if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION))
return Success; return Success;
pVel = GetDevicePredictableAccelData(dev); veloc = GetDevicePredictableAccelData(dev);
if (!pVel) if (!veloc)
return BadValue; return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr); rc = XIPropToFloat(val, &nelem, &ptr);
@ -255,15 +255,15 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
} }
if(v >= 1.0f) if(v >= 1.0f)
pVel->min_acceleration = 1/v; veloc->min_acceleration = 1/v;
return Success; return Success;
} }
static void static void
AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
{ {
float fval = 1.0/pVel->min_acceleration; float fval = 1.0/vel->min_acceleration;
Atom prop_adapt_decel = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION); Atom prop_adapt_decel = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
XIChangeDeviceProperty(dev, prop_adapt_decel, XIGetKnownProperty(XATOM_FLOAT), 32, XIChangeDeviceProperty(dev, prop_adapt_decel, XIGetKnownProperty(XATOM_FLOAT), 32,
@ -280,7 +280,7 @@ static int
AccelSetScaleProperty(DeviceIntPtr dev, Atom atom, AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly) XIPropertyValuePtr val, BOOL checkOnly)
{ {
DeviceVelocityPtr pVel; DeviceVelocityPtr vel;
float v, *ptr = &v; float v, *ptr = &v;
int rc; int rc;
int nelem = 1; int nelem = 1;
@ -288,8 +288,8 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING)) if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING))
return Success; return Success;
pVel = GetDevicePredictableAccelData(dev); vel = GetDevicePredictableAccelData(dev);
if (!pVel) if (!vel)
return BadValue; return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr); rc = XIPropToFloat(val, &nelem, &ptr);
@ -302,15 +302,15 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
} }
if(v > 0) if(v > 0)
pVel->corr_mul = v; vel->corr_mul = v;
return Success; return Success;
} }
static void static void
AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
{ {
float fval = pVel->corr_mul; float fval = vel->corr_mul;
Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING); Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
XIChangeDeviceProperty(dev, prop_velo_scale, XIGetKnownProperty(XATOM_FLOAT), 32, XIChangeDeviceProperty(dev, prop_velo_scale, XIGetKnownProperty(XATOM_FLOAT), 32,
@ -320,17 +320,17 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel)
} }
BOOL BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr device) InitializePredictableAccelerationProperties(DeviceIntPtr dev)
{ {
DeviceVelocityPtr pVel = GetDevicePredictableAccelData(device); DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev);
if(!pVel) if(!vel)
return FALSE; return FALSE;
AccelInitProfileProperty(device, pVel); AccelInitProfileProperty(dev, vel);
AccelInitDecelProperty(device, pVel); AccelInitDecelProperty(dev, vel);
AccelInitAdaptDecelProperty(device, pVel); AccelInitAdaptDecelProperty(dev, vel);
AccelInitScaleProperty(device, pVel); AccelInitScaleProperty(dev, vel);
return TRUE; return TRUE;
} }
@ -339,16 +339,16 @@ InitializePredictableAccelerationProperties(DeviceIntPtr device)
********************/ ********************/
void void
InitTrackers(DeviceVelocityPtr s, int ntracker) InitTrackers(DeviceVelocityPtr vel, int ntracker)
{ {
if(ntracker < 1){ if(ntracker < 1){
ErrorF("(dix ptracc) invalid number of trackers\n"); ErrorF("(dix ptracc) invalid number of trackers\n");
return; return;
} }
xfree(s->tracker); xfree(vel->tracker);
s->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker)); vel->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker));
memset(s->tracker, 0, ntracker * sizeof(MotionTracker)); memset(vel->tracker, 0, ntracker * sizeof(MotionTracker));
s->num_tracker = ntracker; vel->num_tracker = ntracker;
} }
/** /**
@ -437,22 +437,22 @@ GetDirection(int dx, int dy){
#define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker) #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker)
static inline void static inline void
FeedTrackers(DeviceVelocityPtr s, int dx, int dy, int cur_t) FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
{ {
int n; int n;
for(n = 0; n < s->num_tracker; n++){ for(n = 0; n < vel->num_tracker; n++){
s->tracker[n].dx += dx; vel->tracker[n].dx += dx;
s->tracker[n].dy += dy; vel->tracker[n].dy += dy;
} }
n = (s->cur_tracker + 1) % s->num_tracker; n = (vel->cur_tracker + 1) % vel->num_tracker;
s->tracker[n].dx = 0; vel->tracker[n].dx = 0;
s->tracker[n].dy = 0; vel->tracker[n].dy = 0;
s->tracker[n].time = cur_t; vel->tracker[n].time = cur_t;
s->tracker[n].dir = GetDirection(dx, dy); vel->tracker[n].dir = GetDirection(dx, dy);
DebugAccelF("(dix prtacc) motion [dx: %i dy: %i dir:%i diff: %i]\n", DebugAccelF("(dix prtacc) motion [dx: %i dy: %i dir:%i diff: %i]\n",
dx, dy, s->tracker[n].dir, dx, dy, vel->tracker[n].dir,
cur_t - s->tracker[s->cur_tracker].time); cur_t - vel->tracker[vel->cur_tracker].time);
s->cur_tracker = n; vel->cur_tracker = n;
} }
/** /**
@ -461,11 +461,11 @@ FeedTrackers(DeviceVelocityPtr s, int dx, int dy, int cur_t)
* This assumes linear motion. * This assumes linear motion.
*/ */
static float static float
CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){ CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){
int index = TRACKER_INDEX(s, offset); int index = TRACKER_INDEX(vel, offset);
float dist = sqrt( s->tracker[index].dx * s->tracker[index].dx float dist = sqrt( vel->tracker[index].dx * vel->tracker[index].dx
+ s->tracker[index].dy * s->tracker[index].dy); + vel->tracker[index].dy * vel->tracker[index].dy);
int dtime = cur_t - s->tracker[index].time; int dtime = cur_t - vel->tracker[index].time;
if(dtime > 0) if(dtime > 0)
return (dist / dtime); return (dist / dtime);
else else
@ -479,19 +479,19 @@ CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){
* May return 0. * May return 0.
*/ */
static float static float
QueryTrackers(DeviceVelocityPtr s, int cur_t){ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
int n, offset, dir = 255, i = -1, age_ms; int n, offset, dir = 255, i = -1, age_ms;
/* initial velocity: a low-offset, valid velocity */ /* initial velocity: a low-offset, valid velocity */
float iveloc = 0, res = 0, tmp, vdiff; float iveloc = 0, res = 0, tmp, vdiff;
float vfac = s->corr_mul * s->const_acceleration; /* premultiply */ float vfac = vel->corr_mul * vel->const_acceleration; /* premultiply */
/* loop from current to older data */ /* loop from current to older data */
for(offset = 1; offset < s->num_tracker; offset++){ for(offset = 1; offset < vel->num_tracker; offset++){
n = TRACKER_INDEX(s, offset); n = TRACKER_INDEX(vel, offset);
age_ms = cur_t - s->tracker[n].time; age_ms = cur_t - vel->tracker[n].time;
/* bail out if data is too old and protect from overrun */ /* bail out if data is too old and protect from overrun */
if (age_ms >= s->reset_time || age_ms < 0) { if (age_ms >= vel->reset_time || age_ms < 0) {
DebugAccelF("(dix prtacc) query: tracker too old\n"); DebugAccelF("(dix prtacc) query: tracker too old\n");
break; break;
} }
@ -502,7 +502,7 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
* even more precision we could subdivide as a final step, so possible * even more precision we could subdivide as a final step, so possible
* non-linearities are accounted for. * non-linearities are accounted for.
*/ */
dir &= s->tracker[n].dir; dir &= vel->tracker[n].dir;
if(dir == 0){ if(dir == 0){
DebugAccelF("(dix prtacc) query: no longer linear\n"); DebugAccelF("(dix prtacc) query: no longer linear\n");
/* instead of breaking it we might also inspect the partition after, /* instead of breaking it we might also inspect the partition after,
@ -510,16 +510,16 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
break; break;
} }
tmp = CalcTracker(s, offset, cur_t) * vfac; tmp = CalcTracker(vel, offset, cur_t) * vfac;
if ((iveloc == 0 || offset <= s->initial_range) && tmp != 0) { if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) {
/* set initial velocity and result */ /* set initial velocity and result */
res = iveloc = tmp; res = iveloc = tmp;
i = offset; i = offset;
} else if (iveloc != 0 && tmp != 0) { } else if (iveloc != 0 && tmp != 0) {
vdiff = fabs(iveloc - tmp); vdiff = fabs(iveloc - tmp);
if (vdiff <= s->max_diff || if (vdiff <= vel->max_diff ||
vdiff/(iveloc + tmp) < s->max_rel_diff) { vdiff/(iveloc + tmp) < vel->max_rel_diff) {
/* we're in range with the initial velocity, /* we're in range with the initial velocity,
* so this result is likely better * so this result is likely better
* (it contains more information). */ * (it contains more information). */
@ -534,17 +534,17 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
} }
} }
} }
if(offset == s->num_tracker){ if(offset == vel->num_tracker){
DebugAccelF("(dix prtacc) query: last tracker in effect\n"); DebugAccelF("(dix prtacc) query: last tracker in effect\n");
i = s->num_tracker-1; i = vel->num_tracker-1;
} }
if(i>=0){ if(i>=0){
n = TRACKER_INDEX(s, i); n = TRACKER_INDEX(vel, i);
DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n",
i, i,
s->tracker[n].dx, vel->tracker[n].dx,
s->tracker[n].dy, vel->tracker[n].dy,
cur_t - s->tracker[n].time); cur_t - vel->tracker[n].time);
} }
return res; return res;
} }
@ -557,20 +557,20 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
*/ */
short short
ProcessVelocityData2D( ProcessVelocityData2D(
DeviceVelocityPtr s, DeviceVelocityPtr vel,
int dx, int dx,
int dy, int dy,
int time) int time)
{ {
float velocity; float velocity;
s->last_velocity = s->velocity; vel->last_velocity = vel->velocity;
FeedTrackers(s, dx, dy, time); FeedTrackers(vel, dx, dy, time);
velocity = QueryTrackers(s, time); velocity = QueryTrackers(vel, time);
s->velocity = velocity; vel->velocity = velocity;
return velocity == 0; return velocity == 0;
} }
@ -594,23 +594,23 @@ ApplySimpleSoftening(int od, int d)
static void static void
ApplySofteningAndConstantDeceleration( ApplySofteningAndConstantDeceleration(
DeviceVelocityPtr s, DeviceVelocityPtr vel,
int dx, int dx,
int dy, int dy,
float* fdx, float* fdx,
float* fdy, float* fdy,
short do_soften) short do_soften)
{ {
if (do_soften && s->use_softening) { if (do_soften && vel->use_softening) {
*fdx = ApplySimpleSoftening(s->last_dx, dx); *fdx = ApplySimpleSoftening(vel->last_dx, dx);
*fdy = ApplySimpleSoftening(s->last_dy, dy); *fdy = ApplySimpleSoftening(vel->last_dy, dy);
} else { } else {
*fdx = dx; *fdx = dx;
*fdy = dy; *fdy = dy;
} }
*fdx *= s->const_acceleration; *fdx *= vel->const_acceleration;
*fdy *= s->const_acceleration; *fdy *= vel->const_acceleration;
} }
/* /*
@ -853,14 +853,14 @@ NoProfile(
static PointerAccelerationProfileFunc static PointerAccelerationProfileFunc
GetAccelerationProfile( GetAccelerationProfile(
DeviceVelocityPtr s, DeviceVelocityPtr vel,
int profile_num) int profile_num)
{ {
switch(profile_num){ switch(profile_num){
case AccelProfileClassic: case AccelProfileClassic:
return ClassicProfile; return ClassicProfile;
case AccelProfileDeviceSpecific: case AccelProfileDeviceSpecific:
return s->deviceSpecificProfile; return vel->deviceSpecificProfile;
case AccelProfilePolynomial: case AccelProfilePolynomial:
return PolynomialAccelerationProfile; return PolynomialAccelerationProfile;
case AccelProfileSmoothLinear: case AccelProfileSmoothLinear:
@ -890,23 +890,23 @@ GetAccelerationProfile(
*/ */
int int
SetAccelerationProfile( SetAccelerationProfile(
DeviceVelocityPtr s, DeviceVelocityPtr vel,
int profile_num) int profile_num)
{ {
PointerAccelerationProfileFunc profile; PointerAccelerationProfileFunc profile;
profile = GetAccelerationProfile(s, profile_num); profile = GetAccelerationProfile(vel, profile_num);
if(profile == NULL && profile_num != PROFILE_UNINITIALIZE) if(profile == NULL && profile_num != PROFILE_UNINITIALIZE)
return FALSE; return FALSE;
if(s->profile_private != NULL){ if(vel->profile_private != NULL){
/* Here one could free old profile-private data */ /* Here one could free old profile-private data */
xfree(s->profile_private); xfree(vel->profile_private);
s->profile_private = NULL; vel->profile_private = NULL;
} }
/* Here one could init profile-private data */ /* Here one could init profile-private data */
s->Profile = profile; vel->Profile = profile;
s->statistics.profile_number = profile_num; vel->statistics.profile_number = profile_num;
return TRUE; return TRUE;
} }
@ -926,11 +926,11 @@ SetAccelerationProfile(
*/ */
void void
SetDeviceSpecificAccelerationProfile( SetDeviceSpecificAccelerationProfile(
DeviceVelocityPtr s, DeviceVelocityPtr vel,
PointerAccelerationProfileFunc profile) PointerAccelerationProfileFunc profile)
{ {
if(s) if(vel)
s->deviceSpecificProfile = profile; vel->deviceSpecificProfile = profile;
} }
/** /**
@ -939,19 +939,19 @@ SetDeviceSpecificAccelerationProfile(
*/ */
DeviceVelocityPtr DeviceVelocityPtr
GetDevicePredictableAccelData( GetDevicePredictableAccelData(
DeviceIntPtr pDev) DeviceIntPtr dev)
{ {
/*sanity check*/ /*sanity check*/
if(!pDev){ if(!dev){
ErrorF("[dix] accel: DeviceIntPtr was NULL"); ErrorF("[dix] accel: DeviceIntPtr was NULL");
return NULL; return NULL;
} }
if( pDev->valuator && if( dev->valuator &&
pDev->valuator->accelScheme.AccelSchemeProc == dev->valuator->accelScheme.AccelSchemeProc ==
acceleratePointerPredictable && acceleratePointerPredictable &&
pDev->valuator->accelScheme.accelData != NULL){ dev->valuator->accelScheme.accelData != NULL){
return (DeviceVelocityPtr)pDev->valuator->accelScheme.accelData; return (DeviceVelocityPtr)dev->valuator->accelScheme.accelData;
} }
return NULL; return NULL;
} }
@ -967,7 +967,7 @@ GetDevicePredictableAccelData(
*/ */
void void
acceleratePointerPredictable( acceleratePointerPredictable(
DeviceIntPtr pDev, DeviceIntPtr dev,
int first_valuator, int first_valuator,
int num_valuators, int num_valuators,
int *valuators, int *valuators,
@ -977,7 +977,7 @@ acceleratePointerPredictable(
int dx = 0, dy = 0; int dx = 0, dy = 0;
int *px = NULL, *py = NULL; int *px = NULL, *py = NULL;
DeviceVelocityPtr velocitydata = DeviceVelocityPtr velocitydata =
(DeviceVelocityPtr) pDev->valuator->accelScheme.accelData; (DeviceVelocityPtr) dev->valuator->accelScheme.accelData;
float fdx, fdy, tmp; /* no need to init */ float fdx, fdy, tmp; /* no need to init */
Bool soften = TRUE; Bool soften = TRUE;
@ -1004,12 +1004,12 @@ acceleratePointerPredictable(
soften = FALSE; soften = FALSE;
} }
if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) { if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
/* invoke acceleration profile to determine acceleration */ /* invoke acceleration profile to determine acceleration */
mult = ComputeAcceleration (pDev, velocitydata, mult = ComputeAcceleration (dev, velocitydata,
pDev->ptrfeed->ctrl.threshold, dev->ptrfeed->ctrl.threshold,
(float)pDev->ptrfeed->ctrl.num / (float)dev->ptrfeed->ctrl.num /
(float)pDev->ptrfeed->ctrl.den); (float)dev->ptrfeed->ctrl.den);
if(mult != 1.0 || velocitydata->const_acceleration != 1.0) { if(mult != 1.0 || velocitydata->const_acceleration != 1.0) {
ApplySofteningAndConstantDeceleration( velocitydata, ApplySofteningAndConstantDeceleration( velocitydata,
@ -1018,21 +1018,22 @@ acceleratePointerPredictable(
(mult > 1.0) && soften); (mult > 1.0) && soften);
if (dx) { if (dx) {
tmp = mult * fdx + pDev->last.remainder[0]; tmp = mult * fdx + dev->last.remainder[0];
/* Since it may not be apparent: lrintf() does not offer /* Since it may not be apparent: lrintf() does not offer
* strong statements about rounding; however because we * strong statements about rounding; however because we
* 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); *px = lrintf(tmp);
pDev->last.remainder[0] = tmp - (float)*px; dev->last.remainder[0] = tmp - (float)*px;
} }
if (dy) { if (dy) {
tmp = mult * fdy + pDev->last.remainder[1]; tmp = mult * fdy + dev->last.remainder[1];
*py = lrintf(tmp); *py = lrintf(tmp);
pDev->last.remainder[1] = tmp - (float)*py; dev->last.remainder[1] = tmp - (float)*py;
} }
DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n", *px, *py, pDev->last.remainder[0], pDev->last.remainder[1], fdx, fdy); 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);
} }
} }
} }
@ -1049,7 +1050,7 @@ acceleratePointerPredictable(
*/ */
void void
acceleratePointerLightweight( acceleratePointerLightweight(
DeviceIntPtr pDev, DeviceIntPtr dev,
int first_valuator, int first_valuator,
int num_valuators, int num_valuators,
int *valuators, int *valuators,
@ -1074,48 +1075,48 @@ acceleratePointerLightweight(
if (!dx && !dy) if (!dx && !dy)
return; return;
if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) { if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
/* modeled from xf86Events.c */ /* modeled from xf86Events.c */
if (pDev->ptrfeed->ctrl.threshold) { if (dev->ptrfeed->ctrl.threshold) {
if ((abs(dx) + abs(dy)) >= pDev->ptrfeed->ctrl.threshold) { if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) {
pDev->last.remainder[0] = ((float)dx * dev->last.remainder[0] = ((float)dx *
(float)(pDev->ptrfeed->ctrl.num)) / (float)(dev->ptrfeed->ctrl.num)) /
(float)(pDev->ptrfeed->ctrl.den) + (float)(dev->ptrfeed->ctrl.den) +
pDev->last.remainder[0]; dev->last.remainder[0];
if (px) { if (px) {
*px = (int)pDev->last.remainder[0]; *px = (int)dev->last.remainder[0];
pDev->last.remainder[0] = pDev->last.remainder[0] - dev->last.remainder[0] = dev->last.remainder[0] -
(float)(*px); (float)(*px);
} }
pDev->last.remainder[1] = ((float)dy * dev->last.remainder[1] = ((float)dy *
(float)(pDev->ptrfeed->ctrl.num)) / (float)(dev->ptrfeed->ctrl.num)) /
(float)(pDev->ptrfeed->ctrl.den) + (float)(dev->ptrfeed->ctrl.den) +
pDev->last.remainder[1]; dev->last.remainder[1];
if (py) { if (py) {
*py = (int)pDev->last.remainder[1]; *py = (int)dev->last.remainder[1];
pDev->last.remainder[1] = pDev->last.remainder[1] - dev->last.remainder[1] = dev->last.remainder[1] -
(float)(*py); (float)(*py);
} }
} }
} }
else { else {
mult = pow((float)dx * (float)dx + (float)dy * (float)dy, mult = pow((float)dx * (float)dx + (float)dy * (float)dy,
((float)(pDev->ptrfeed->ctrl.num) / ((float)(dev->ptrfeed->ctrl.num) /
(float)(pDev->ptrfeed->ctrl.den) - 1.0) / (float)(dev->ptrfeed->ctrl.den) - 1.0) /
2.0) / 2.0; 2.0) / 2.0;
if (dx) { if (dx) {
pDev->last.remainder[0] = mult * (float)dx + dev->last.remainder[0] = mult * (float)dx +
pDev->last.remainder[0]; dev->last.remainder[0];
*px = (int)pDev->last.remainder[0]; *px = (int)dev->last.remainder[0];
pDev->last.remainder[0] = pDev->last.remainder[0] - dev->last.remainder[0] = dev->last.remainder[0] -
(float)(*px); (float)(*px);
} }
if (dy) { if (dy) {
pDev->last.remainder[1] = mult * (float)dy + dev->last.remainder[1] = mult * (float)dy +
pDev->last.remainder[1]; dev->last.remainder[1];
*py = (int)pDev->last.remainder[1]; *py = (int)dev->last.remainder[1];
pDev->last.remainder[1] = pDev->last.remainder[1] - dev->last.remainder[1] = dev->last.remainder[1] -
(float)(*py); (float)(*py);
} }
} }

View File

@ -91,10 +91,10 @@ typedef struct _DeviceVelocityRec {
extern _X_EXPORT void extern _X_EXPORT void
InitVelocityData(DeviceVelocityPtr s); InitVelocityData(DeviceVelocityPtr vel);
extern _X_EXPORT void extern _X_EXPORT void
InitTrackers(DeviceVelocityPtr s, int ntracker); InitTrackers(DeviceVelocityPtr vel, int ntracker);
extern _X_EXPORT short extern _X_EXPORT short
ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time); ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
@ -110,24 +110,24 @@ extern _X_EXPORT BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr dev); InitializePredictableAccelerationProperties(DeviceIntPtr dev);
extern _X_EXPORT int extern _X_EXPORT int
SetAccelerationProfile(DeviceVelocityPtr s, int profile_num); SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
extern _X_EXPORT DeviceVelocityPtr extern _X_EXPORT DeviceVelocityPtr
GetDevicePredictableAccelData(DeviceIntPtr pDev); GetDevicePredictableAccelData(DeviceIntPtr dev);
extern _X_EXPORT void extern _X_EXPORT void
SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr s, SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
PointerAccelerationProfileFunc profile); PointerAccelerationProfileFunc profile);
extern _X_EXPORT void extern _X_EXPORT void
AccelerationDefaultCleanup(DeviceIntPtr pDev); AccelerationDefaultCleanup(DeviceIntPtr dev);
extern _X_EXPORT void extern _X_EXPORT void
acceleratePointerPredictable(DeviceIntPtr pDev, int first_valuator, acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
int num_valuators, int *valuators, int evtime); int num_valuators, int *valuators, int evtime);
extern _X_EXPORT void extern _X_EXPORT void
acceleratePointerLightweight(DeviceIntPtr pDev, int first_valuator, acceleratePointerLightweight(DeviceIntPtr dev, int first_valuator,
int num_valuators, int *valuators, int ignore); int num_valuators, int *valuators, int ignored);
#endif /* POINTERVELOCITY_H */ #endif /* POINTERVELOCITY_H */