From 6d541530bef8d0676cfe57d52689d133c9748de0 Mon Sep 17 00:00:00 2001 From: Simon Thum Date: Thu, 3 Feb 2011 21:52:24 +0100 Subject: [PATCH 4/4] dix: update pointer acceleration code to use ValuatorMask Signed-off-by: Simon Thum --- dix/getevents.c | 24 ++--------- dix/ptrveloc.c | 114 ++++++++++++++++++++++++--------------------------- include/input.h | 10 ++--- include/ptrveloc.h | 15 +++---- 4 files changed, 68 insertions(+), 95 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index 794df42..1ccddfa 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -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. * * @param dev The device which's pointer is to be moved. - * @param first The first valuator in @valuators - * @param num Total number of valuators in @valuators. - * @param valuators Valuator data for each axis between @first and - * @first+@num. + * @param valuators Valuator mask * @param ms Current time. */ 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) - dev->valuator->accelScheme.AccelSchemeProc(dev, first, num, valuators, ms); + dev->valuator->accelScheme.AccelSchemeProc(dev, valuators, ms); } /** @@ -1169,20 +1166,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, moveAbsolute(pDev, &x, &y, &mask); } else { if (flags & POINTER_ACCELERATE) { - /* FIXME: Pointer acceleration only requires X and Y values. This - * 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]); - + accelPointer(pDev, &mask, ms); /* The pointer acceleration code modifies the fractional part * in-place, so we need to extract this information first */ x_frac = pDev->last.remainder[0]; diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c index 4fb6ef1..ceae72b 100644 --- a/dix/ptrveloc.c +++ b/dix/ptrveloc.c @@ -81,6 +81,9 @@ DeletePredictableAccelerationProperties(DeviceIntPtr, long*); #define DebugAccelF(...) /* */ #endif +/* number of input properties for predictable acceleration */ +#define NPROPS_PREDICTABLE_ACCEL 4 + /******************************** * Init/Uninit *******************************/ @@ -1065,18 +1068,15 @@ GetDevicePredictableAccelData( void acceleratePointerPredictable( DeviceIntPtr dev, - int first_valuator, - int num_valuators, - int *valuators, - int evtime) + ValuatorMask* val, + CARD32 evtime) { float fdx, fdy, tmp, mult; /* no need to init */ - int dx = 0, dy = 0; - int *px = NULL, *py = NULL; + int dx = 0, dy = 0, tmpi; DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev); Bool soften = TRUE; - if (!num_valuators || !valuators || !velocitydata) + if (!velocitydata) return; if (velocitydata->statistics.profile_number == AccelProfileNone && @@ -1084,13 +1084,12 @@ acceleratePointerPredictable( return; /*we're inactive anyway, so skip the whole thing.*/ } - if (first_valuator == 0) { - dx = valuators[0]; - px = &valuators[0]; + if (valuator_mask_isset(val, 0)) { + dx = valuator_mask_get(val, 0); } - if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) { - dy = valuators[1 - first_valuator]; - py = &valuators[1 - first_valuator]; + + if (valuator_mask_isset(val, 1)) { + dy = valuator_mask_get(val, 1); } if (dx || dy){ @@ -1104,7 +1103,7 @@ acceleratePointerPredictable( mult = ComputeAcceleration (dev, velocitydata, dev->ptrfeed->ctrl.threshold, (float)dev->ptrfeed->ctrl.num / - (float)dev->ptrfeed->ctrl.den); + (float)dev->ptrfeed->ctrl.den); if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) { ApplySofteningAndConstantDeceleration( velocitydata, @@ -1119,13 +1118,15 @@ acceleratePointerPredictable( * process each axis conditionally, there's no danger * of a toggling remainder. Its lack of guarantees likely * makes it faster on the average target. */ - *px = lrintf(tmp); - dev->last.remainder[0] = tmp - (float)*px; + tmpi = lrintf(tmp); + valuator_mask_set(val, 0, tmpi); + dev->last.remainder[0] = tmp - (float)tmpi; } if (dy) { tmp = mult * fdy + dev->last.remainder[1]; - *py = lrintf(tmp); - dev->last.remainder[1] = tmp - (float)*py; + tmpi = lrintf(tmp); + 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", *px, *py, dev->last.remainder[0], dev->last.remainder[1], fdx, fdy); @@ -1146,25 +1147,18 @@ acceleratePointerPredictable( void acceleratePointerLightweight( DeviceIntPtr dev, - int first_valuator, - int num_valuators, - int *valuators, - int ignored) + ValuatorMask* val, + CARD32 ignored) { - float mult = 0.0; - int dx = 0, dy = 0; - int *px = NULL, *py = NULL; - - if (!num_valuators || !valuators) - return; + float mult = 0.0, tmpf; + int dx = 0, dy = 0, tmpi; - if (first_valuator == 0) { - dx = valuators[0]; - px = &valuators[0]; + if (valuator_mask_isset(val, 0)) { + dx = valuator_mask_get(val, 0); } - if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) { - dy = valuators[1 - first_valuator]; - py = &valuators[1 - first_valuator]; + + if (valuator_mask_isset(val, 1)) { + dy = valuator_mask_get(val, 1); } if (!dx && !dy) @@ -1174,24 +1168,24 @@ acceleratePointerLightweight( /* modeled from xf86Events.c */ if (dev->ptrfeed->ctrl.threshold) { if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) { - dev->last.remainder[0] = ((float)dx * - (float)(dev->ptrfeed->ctrl.num)) / - (float)(dev->ptrfeed->ctrl.den) + - dev->last.remainder[0]; - if (px) { - *px = (int)dev->last.remainder[0]; - dev->last.remainder[0] = dev->last.remainder[0] - - (float)(*px); + tmpf = ((float)dx * + (float)(dev->ptrfeed->ctrl.num)) / + (float)(dev->ptrfeed->ctrl.den) + + dev->last.remainder[0]; + if (dx) { + tmpi = (int) tmpf; + valuator_mask_set(val, 0, tmpi); + dev->last.remainder[0] = tmpf - (float)tmpi; } - dev->last.remainder[1] = ((float)dy * - (float)(dev->ptrfeed->ctrl.num)) / - (float)(dev->ptrfeed->ctrl.den) + - dev->last.remainder[1]; - if (py) { - *py = (int)dev->last.remainder[1]; - dev->last.remainder[1] = dev->last.remainder[1] - - (float)(*py); + tmpf = ((float)dy * + (float)(dev->ptrfeed->ctrl.num)) / + (float)(dev->ptrfeed->ctrl.den) + + dev->last.remainder[1]; + if (dy) { + tmpi = (int) tmpf; + valuator_mask_set(val, 1, tmpi); + dev->last.remainder[1] = tmpf - (float)tmpi; } } } @@ -1201,18 +1195,18 @@ acceleratePointerLightweight( (float)(dev->ptrfeed->ctrl.den) - 1.0) / 2.0) / 2.0; if (dx) { - dev->last.remainder[0] = mult * (float)dx + - dev->last.remainder[0]; - *px = (int)dev->last.remainder[0]; - dev->last.remainder[0] = dev->last.remainder[0] - - (float)(*px); + tmpf = mult * (float)dx + + dev->last.remainder[0]; + tmpi = (int) tmpf; + valuator_mask_set(val, 0, tmpi); + dev->last.remainder[0] = tmpf - (float)tmpi; } if (dy) { - dev->last.remainder[1] = mult * (float)dy + - dev->last.remainder[1]; - *py = (int)dev->last.remainder[1]; - dev->last.remainder[1] = dev->last.remainder[1] - - (float)(*py); + tmpf = mult * (float)dy + + dev->last.remainder[1]; + tmpi = (int)tmpf; + valuator_mask_set(val, 1, tmpi); + dev->last.remainder[1] = tmpf - (float)tmpi; } } } diff --git a/include/input.h b/include/input.h index ab58a15..3b2652c 100644 --- a/include/input.h +++ b/include/input.h @@ -106,6 +106,8 @@ typedef struct _ClassesRec *ClassesPtr; typedef struct _SpriteRec *SpritePtr; typedef union _GrabMask GrabMask; +typedef struct _ValuatorMask ValuatorMask; + typedef struct _EventList { xEvent* event; int evlen; /* length of allocated memory for event in bytes. This is not @@ -142,10 +144,8 @@ typedef void (*DeviceUnwrapProc)( /* pointer acceleration handling */ typedef void (*PointerAccelSchemeProc)( DeviceIntPtr /*pDev*/, - int /*first_valuator*/, - int /*num_valuators*/, - int* /*valuators*/, - int /*evtime*/); + ValuatorMask* /*first_valuator*/, + CARD32 /*evtime*/); typedef void (*DeviceCallbackProc)( DeviceIntPtr /*pDev*/); @@ -163,8 +163,6 @@ typedef struct _DeviceRec { Bool on; /* used by DDX to keep state */ } DeviceRec, *DevicePtr; -typedef struct _ValuatorMask ValuatorMask; - typedef struct { int click, bell, bell_pitch, bell_duration; Bool autoRepeat; diff --git a/include/ptrveloc.h b/include/ptrveloc.h index 3cc3d97..6411a2c 100644 --- a/include/ptrveloc.h +++ b/include/ptrveloc.h @@ -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 * copy of this software and associated documentation files (the "Software"), @@ -25,7 +25,7 @@ #ifndef POINTERVELOCITY_H #define POINTERVELOCITY_H -#include /* DeviceIntPtr */ +#include /* constants for acceleration profiles */ @@ -90,9 +90,6 @@ typedef struct _DeviceVelocityRec { } statistics; } DeviceVelocityRec, *DeviceVelocityPtr; -/* number of properties for predictable acceleration */ -#define NPROPS_PREDICTABLE_ACCEL 4 - /** * contains the run-time data for the predictable scheme, that is, a * DeviceVelocityPtr and the property handlers. @@ -136,11 +133,11 @@ InitPredictableAccelerationScheme(DeviceIntPtr dev, struct _ValuatorAccelerationRec* protoScheme); extern _X_INTERNAL void -acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator, - int num_valuators, int *valuators, int evtime); +acceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask* val, + CARD32 evtime); extern _X_INTERNAL void -acceleratePointerLightweight(DeviceIntPtr dev, int first_valuator, - int num_valuators, int *valuators, int ignored); +acceleratePointerLightweight(DeviceIntPtr dev, ValuatorMask* val, + CARD32 evtime); #endif /* POINTERVELOCITY_H */ -- 1.7.3.4