Am 09.09.2010 00:41, schrieb Albert Zeyer: > Simon Thum: >>> 2. The pointer acceleration code was highly pointer specific. It heavily >>> used those valuators. >> Yes again - but only in the scheme function. That's just wiring it up >> with the pointer - as said, the acceleration context is pretty agnostic >> (I'm cooking up a patch to get rid of the last field ATM) > Can you leave me a message when you have cleaned that up? I'll try to > rewrite my patch then. I'm attaching the patches in my queue. They're not tested yet, but look fine to me. (The first one is actually tested and your queue Peter, please ignore the others for now)
The cleanup is simply I shifted init fully into ptrveloc.c and could remove some header stuff and move the prop_handlers into the scheme data directly. It won't affect you much, I more or less wanted to prove that accel isn't tied to pointers or valuators. > >>> When will pscroll be adopted? Or will it? When/how is such a decision >>> made? Will it be soon? If not, what are the problems with pscroll? If >> Mostly technical problems AFAIK - it doesn't apply to master and it >> seems to collect dust (I may be wrong ITR). > Can anyone else comment on this? The applying itself shouldn't really be > a problem. I'm CC'ing Peter to increase the chance he'll enlighten us. (http://github.com/x-quadraht/pscroll) Cheers, Simon
>From 11627ab8845cb77079176a99afb66844e28a2977 Mon Sep 17 00:00:00 2001 From: Simon Thum <[email protected]> Date: Sun, 18 Jul 2010 12:31:26 +0200 Subject: [PATCH 1/3] fix xf86 backend-specific input initialization Instead of shoving it in rather unrelated places, move acceleration init into xf86NewInputDevice. Caveat: It's not clear atm how relevant other callers of ActivteDevice (like OpenDevice) actually are. --- hw/xfree86/common/xf86Xinput.c | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index bd77fe6..5279e28 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -108,6 +108,9 @@ EventListPtr xf86Events = NULL; +static int +xf86InputDeviceAfterDriverInit(DeviceIntPtr dev); + /** * Eval config and modify DeviceVelocityRec accordingly */ @@ -730,6 +733,19 @@ IgnoreInputClass(const IDevPtr idev, const InputAttributes *attrs) return ignore; } +/* + * Apply backend-specific initialization. Invoked after ActiveteDevice(), + * i.e. after the driver successfully completed DEVICE_INIT and the device + * is advertised. + * @param dev the device + * @return Success or an error code + */ +static int +xf86InputDeviceAfterDriverInit(DeviceIntPtr dev) { + ApplyAccelerationSettings(dev); + return Success; +} + /** * Create a new input device, activate and enable it. * @@ -804,6 +820,14 @@ xf86NewInputDevice(IDevPtr idev, DeviceIntPtr *pdev, BOOL enable) goto unwind; } + rval = xf86InputDeviceAfterDriverInit(dev); + if (rval != Success) + { + xf86Msg(X_ERROR, "Couldn't post-init device \"%s\"\n", idev->identifier); + RemoveDevice(dev, TRUE); + goto unwind; + } + /* Enable it if it's properly initialised and we're currently in the VT */ if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema) { @@ -1320,9 +1344,6 @@ xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum) dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2; dev->last.valuators[1] = dev->valuator->axisVal[1]; } - - if(axnum == 0) /* to prevent double invocation */ - ApplyAccelerationSettings(dev); } -- 1.7.1
>From 6ea0871b865a365c1e754b62ac40fe0f5c687074 Mon Sep 17 00:00:00 2001 From: Simon Thum <[email protected]> Date: Sat, 4 Sep 2010 16:31:24 +0200 Subject: [PATCH 2/3] refactor scheme init Signed-off-by: Simon Thum <[email protected]> --- dix/devices.c | 54 ++++++++++++++++----------------------------------- dix/ptrveloc.c | 32 +++++++++++++++++++++++------- include/input.h | 4 +++ include/inputstr.h | 1 + include/ptrveloc.h | 3 ++ 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index 2e65a04..acde30c 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1286,10 +1286,11 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, /* global list of acceleration schemes */ ValuatorAccelerationRec pointerAccelerationScheme[] = { - {PtrAccelNoOp, NULL, NULL, NULL}, - {PtrAccelPredictable, acceleratePointerPredictable, NULL, AccelerationDefaultCleanup}, - {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL}, - {-1, NULL, NULL, NULL} /* terminator */ + {PtrAccelNoOp, NULL, NULL, NULL, NULL}, + {PtrAccelPredictable, acceleratePointerPredictable, NULL, + InitPredictableAccelerationScheme, AccelerationDefaultCleanup}, + {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL}, + {-1, NULL, NULL, NULL, NULL} /* terminator */ }; /** @@ -1301,59 +1302,38 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, int scheme) { int x, i = -1; - void* data = NULL; ValuatorClassPtr val; + ValuatorAccelerationPtr schemeRec; val = dev->valuator; - if(!val) + if (!val) return FALSE; - if(IsMaster(dev) && scheme != PtrAccelNoOp) + if (IsMaster(dev) && scheme != PtrAccelNoOp) return FALSE; - for(x = 0; pointerAccelerationScheme[x].number >= 0; x++) { + for (x = 0; pointerAccelerationScheme[x].number >= 0; x++) { if(pointerAccelerationScheme[x].number == scheme){ i = x; break; } } - if(-1 == i) + if (-1 == i) return FALSE; if (val->accelScheme.AccelCleanupProc) val->accelScheme.AccelCleanupProc(dev); - /* init scheme-specific data */ - switch(scheme){ - case PtrAccelPredictable: - { - DeviceVelocityPtr s; - s = malloc(sizeof(DeviceVelocityRec)); - if(!s) - return FALSE; - InitVelocityData(s); - data = s; - break; - } - default: - break; + if (pointerAccelerationScheme[i].AccelInitProc) { + schemeRec = pointerAccelerationScheme[i].AccelInitProc(dev); + if (!schemeRec) + return FALSE; + val->accelScheme = *schemeRec; + } else { + val->accelScheme = pointerAccelerationScheme[i]; } - - val->accelScheme = pointerAccelerationScheme[i]; - val->accelScheme.accelData = data; - - /* post-init scheme */ - switch(scheme){ - case PtrAccelPredictable: - InitializePredictableAccelerationProperties(dev); - break; - - default: - break; - } - return TRUE; } diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c index 30e14b1..990bfe9 100644 --- a/dix/ptrveloc.c +++ b/dix/ptrveloc.c @@ -85,7 +85,7 @@ GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); /** - * Init struct so it should match the average case + * Init DeviceVelocity struct so it should match the average case */ void InitVelocityData(DeviceVelocityPtr vel) @@ -107,7 +107,7 @@ InitVelocityData(DeviceVelocityPtr vel) /** - * Clean up + * Clean up DeviceVelocityRec */ void FreeVelocityData(DeviceVelocityPtr vel){ @@ -116,8 +116,26 @@ FreeVelocityData(DeviceVelocityPtr vel){ } -/* - * dix uninit helper, called through scheme +/** + * Init predictable scheme + */ +ValuatorAccelerationPtr +InitPredictableAccelerationScheme(DeviceIntPtr dev) { + DeviceVelocityPtr vel; + ValuatorAccelerationPtr scheme; + scheme = calloc(1, sizeof(ValuatorAccelerationRec)); + vel = calloc(1, sizeof(DeviceVelocityRec)); + if (!vel || !scheme) + return NULL; + InitVelocityData(vel); + scheme->accelData = vel; + InitializePredictableAccelerationProperties(dev); + return scheme; +} + + +/** + * Uninit scheme */ void AccelerationDefaultCleanup(DeviceIntPtr dev) @@ -1026,12 +1044,10 @@ acceleratePointerPredictable( int *valuators, int evtime) { - float mult = 0.0; + float fdx, fdy, tmp, mult; /* no need to init */ int dx = 0, dy = 0; int *px = NULL, *py = NULL; - DeviceVelocityPtr velocitydata = - (DeviceVelocityPtr) dev->valuator->accelScheme.accelData; - float fdx, fdy, tmp; /* no need to init */ + DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev); Bool soften = TRUE; if (!num_valuators || !valuators || !velocitydata) diff --git a/include/input.h b/include/input.h index ffb1c33..a3967be 100644 --- a/include/input.h +++ b/include/input.h @@ -149,6 +149,10 @@ typedef void (*PointerAccelSchemeProc)( typedef void (*DeviceCallbackProc)( DeviceIntPtr /*pDev*/); +struct _ValuatorAccelerationRec; +typedef struct _ValuatorAccelerationRec* (*PointerAccelSchemeInitProc)( + DeviceIntPtr /*dev*/); + typedef struct _DeviceRec { pointer devicePrivate; ProcessInputProc processInputProc; /* current */ diff --git a/include/inputstr.h b/include/inputstr.h index 1b504e9..0e29b97 100644 --- a/include/inputstr.h +++ b/include/inputstr.h @@ -223,6 +223,7 @@ typedef struct _ValuatorAccelerationRec { int number; PointerAccelSchemeProc AccelSchemeProc; void *accelData; /* at disposal of AccelScheme */ + PointerAccelSchemeInitProc AccelInitProc; DeviceCallbackProc AccelCleanupProc; } ValuatorAccelerationRec, *ValuatorAccelerationPtr; diff --git a/include/ptrveloc.h b/include/ptrveloc.h index 6f999a8..db511be 100644 --- a/include/ptrveloc.h +++ b/include/ptrveloc.h @@ -129,6 +129,9 @@ SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel, extern _X_INTERNAL void AccelerationDefaultCleanup(DeviceIntPtr dev); +extern _X_INTERNAL struct _ValuatorAccelerationRec* +InitPredictableAccelerationScheme(DeviceIntPtr dev); + extern _X_INTERNAL void acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator, int num_valuators, int *valuators, int evtime); -- 1.7.1
>From 10bfde60ce68c4141b0ba42e3764491883fb9c64 Mon Sep 17 00:00:00 2001 From: Simon Thum <[email protected]> Date: Sun, 5 Sep 2010 18:10:42 +0200 Subject: [PATCH 3/3] refactor predictable scheme initialization This intends to clean up the accel struct and streamline initialization. Signed-off-by: Simon Thum <[email protected]> --- dix/devices.c | 14 +++++----- dix/ptrveloc.c | 68 +++++++++++++++++++++++++++++++++++---------------- include/ptrveloc.h | 22 +++++++++------- 3 files changed, 65 insertions(+), 39 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index acde30c..37e3b79 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1288,7 +1288,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, ValuatorAccelerationRec pointerAccelerationScheme[] = { {PtrAccelNoOp, NULL, NULL, NULL, NULL}, {PtrAccelPredictable, acceleratePointerPredictable, NULL, - InitPredictableAccelerationScheme, AccelerationDefaultCleanup}, + InitPredictableAccelerationScheme, AccelerationDefaultCleanup}, {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL}, {-1, NULL, NULL, NULL, NULL} /* terminator */ }; @@ -1308,7 +1308,7 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, val = dev->valuator; if (!val) - return FALSE; + return FALSE; if (IsMaster(dev) && scheme != PtrAccelNoOp) return FALSE; @@ -1327,12 +1327,12 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, val->accelScheme.AccelCleanupProc(dev); if (pointerAccelerationScheme[i].AccelInitProc) { - schemeRec = pointerAccelerationScheme[i].AccelInitProc(dev); - if (!schemeRec) - return FALSE; - val->accelScheme = *schemeRec; + schemeRec = pointerAccelerationScheme[i].AccelInitProc(dev); + if (!schemeRec) + return FALSE; + val->accelScheme = *schemeRec; } else { - val->accelScheme = pointerAccelerationScheme[i]; + val->accelScheme = pointerAccelerationScheme[i]; } return TRUE; } diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c index 990bfe9..b0da768 100644 --- a/dix/ptrveloc.c +++ b/dix/ptrveloc.c @@ -30,6 +30,7 @@ #include <ptrveloc.h> #include <exevents.h> #include <X11/Xatom.h> +#include <os.h> #include <xserver-properties.h> @@ -67,6 +68,10 @@ SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity, float threshold, float acc); static PointerAccelerationProfileFunc GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); +static BOOL +InitializePredictableAccelerationProperties(DeviceIntPtr, long*); +static BOOL +DeletePredictableAccelerationProperties(DeviceIntPtr, long*); /*#define PTRACCEL_DEBUGGING*/ @@ -123,13 +128,18 @@ ValuatorAccelerationPtr InitPredictableAccelerationScheme(DeviceIntPtr dev) { DeviceVelocityPtr vel; ValuatorAccelerationPtr scheme; + PredictableAccelSchemePtr schemeData; scheme = calloc(1, sizeof(ValuatorAccelerationRec)); vel = calloc(1, sizeof(DeviceVelocityRec)); - if (!vel || !scheme) - return NULL; + schemeData = calloc(1, sizeof(PredictableAccelSchemeRec)); + if (!vel || !scheme || !schemeData) + return NULL; InitVelocityData(vel); - scheme->accelData = vel; - InitializePredictableAccelerationProperties(dev); + schemeData->vel = vel; + schemeData->prop_handlers = calloc(NPROPS_PREDICTABLE_ACCEL, + sizeof(long)); + InitializePredictableAccelerationProperties(dev, schemeData->prop_handlers); + scheme->accelData = schemeData; return scheme; } @@ -140,14 +150,24 @@ InitPredictableAccelerationScheme(DeviceIntPtr dev) { void AccelerationDefaultCleanup(DeviceIntPtr dev) { - /*sanity check*/ - if( dev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable - && dev->valuator->accelScheme.accelData != NULL){ + DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev); + long* prop_handlers; + if (vel) { + /* the proper guarantee would be that we're not inside of + * AccelSchemeProc(), but that seems impossible. Schemes don't get + * schwitched often anyway. + */ + OsBlockSignals(); dev->valuator->accelScheme.AccelSchemeProc = NULL; - FreeVelocityData(dev->valuator->accelScheme.accelData); + FreeVelocityData(vel); + free(vel); + prop_handlers = ((PredictableAccelSchemePtr) + dev->valuator->accelScheme.accelData)->prop_handlers; + DeletePredictableAccelerationProperties(dev, prop_handlers); + free(prop_handlers); free(dev->valuator->accelScheme.accelData); dev->valuator->accelScheme.accelData = NULL; - DeletePredictableAccelerationProperties(dev); + OsReleaseSignals(); } } @@ -339,26 +359,30 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL); } -BOOL -InitializePredictableAccelerationProperties(DeviceIntPtr dev) +static BOOL +InitializePredictableAccelerationProperties( + DeviceIntPtr dev, + long* prop_handlers) { DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev); if(!vel) return FALSE; - vel->prop_handlers[0] = AccelInitProfileProperty(dev, vel); - vel->prop_handlers[1] = AccelInitDecelProperty(dev, vel); - vel->prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel); - vel->prop_handlers[3] = AccelInitScaleProperty(dev, vel); + prop_handlers[0] = AccelInitProfileProperty(dev, vel); + prop_handlers[1] = AccelInitDecelProperty(dev, vel); + prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel); + prop_handlers[3] = AccelInitScaleProperty(dev, vel); return TRUE; } BOOL -DeletePredictableAccelerationProperties(DeviceIntPtr dev) +DeletePredictableAccelerationProperties( + DeviceIntPtr dev, + long* prop_handlers) { - DeviceVelocityPtr vel; + DeviceVelocityPtr vel; Atom prop; int i; @@ -373,8 +397,8 @@ DeletePredictableAccelerationProperties(DeviceIntPtr dev) vel = GetDevicePredictableAccelData(dev); for (i = 0; vel && i < NPROPS_PREDICTABLE_ACCEL; i++) - if (vel->prop_handlers[i]) - XIUnregisterPropertyHandler(dev, vel->prop_handlers[i]); + if (prop_handlers[i]) + XIUnregisterPropertyHandler(dev, prop_handlers[i]); return TRUE; } @@ -391,8 +415,7 @@ InitTrackers(DeviceVelocityPtr vel, int ntracker) return; } free(vel->tracker); - vel->tracker = (MotionTrackerPtr)malloc(ntracker * sizeof(MotionTracker)); - memset(vel->tracker, 0, ntracker * sizeof(MotionTracker)); + vel->tracker = (MotionTrackerPtr)calloc(ntracker, sizeof(MotionTracker)); vel->num_tracker = ntracker; } @@ -1022,7 +1045,8 @@ GetDevicePredictableAccelData( acceleratePointerPredictable && dev->valuator->accelScheme.accelData != NULL){ - return (DeviceVelocityPtr)dev->valuator->accelScheme.accelData; + return ((PredictableAccelSchemePtr) + dev->valuator->accelScheme.accelData)->vel; } return NULL; } diff --git a/include/ptrveloc.h b/include/ptrveloc.h index db511be..07258eb 100644 --- a/include/ptrveloc.h +++ b/include/ptrveloc.h @@ -62,9 +62,6 @@ typedef struct _MotionTracker { int dir; /* initial direction bitfield */ } MotionTracker, *MotionTrackerPtr; -/* number of properties for predictable acceleration */ -#define NPROPS_PREDICTABLE_ACCEL 4 - /** * Contains all data needed to implement mouse ballistics */ @@ -91,9 +88,20 @@ typedef struct _DeviceVelocityRec { struct { /* to be able to query this information */ int profile_number; } statistics; - long prop_handlers[NPROPS_PREDICTABLE_ACCEL]; } 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. + */ +typedef struct _PredictableAccelSchemeRec { + DeviceVelocityPtr vel; + long* prop_handlers; +} PredictableAccelSchemeRec, *PredictableAccelSchemePtr; + extern _X_EXPORT void InitVelocityData(DeviceVelocityPtr vel); @@ -110,12 +118,6 @@ BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel, extern _X_EXPORT void FreeVelocityData(DeviceVelocityPtr vel); -extern _X_INTERNAL BOOL -InitializePredictableAccelerationProperties(DeviceIntPtr dev); - -extern _X_INTERNAL BOOL -DeletePredictableAccelerationProperties(DeviceIntPtr dev); - extern _X_EXPORT int SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); -- 1.7.1
_______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
