Peter Hutterer wrote:
On Sat, Jun 06, 2009 at 03:45:13PM +0200, Simon Thum wrote:
I would like to see the first of the attached patches in the server
before 1.7 is branched. This is to have the accel API be sensible enough
to finally solve the synaptics-and-acceleration problem hiding in its
corner since the jura, approximately. The synaptics accel code (or the
driver as a whole) could be depending on 1.7 then, so this has my
priority.
can you give an example of how this would be used in the driver? Will the
driver provide it's custom acceleration function or just rely on the server?
If the former, why not the latter? :)
See attached synaptics patch (POC code only!). The driver provides its
own function to implement the pressure-related acceleration feature,
which I think is worth the sweat.
Without the API change, it would be hard to do this properly because
it's hard to infer the device from a DeviceVelocityPtr alone. (Ok, I'm
yet to see a 2-synaptics-pads-box, but you get the point.)
Also, now a driver can create own accel contexts, e.g. to accelerate
scrolling or other independent axes. (I could have before but it would
be unnecessarily verbose).
right now, the server provides a couple of options to configure pointer
acceleration on a per-device basis. Why can't we set these options in the
driver to something resembling sensible defaults (IIRC synaptics requires
constant deceleration of at least 3 or so, it'd be a single line to add this
to the driver).
That's what the patch also does. Or, does try to, at least.
I wish we could get rid of the pDev and pVel and pSomething and just use
dev, vel, and something instead. (I know, I'm guilty of that myself)
same goes for the rest of the patch.
I was merely aligning to what I found; I'm not a great supporter of that
hungarian notation thingy either. Anyway, your wishes have come true
(for ptrveloc, at least :)
Cheers,
Simon
>From aa117b1023023cfdd7748536266dd7004efe388b Mon Sep 17 00:00:00 2001
From: Simon Thum <[email protected]>
Date: Sat, 20 Jun 2009 16:07:43 +0200
Subject: [PATCH] Setup dix pointer acceleration from synaptics
Tries to setup dix accel so configured synaptics devices
behave alike while benefiting from dix velocity approximation.
Pressure-dependent acceleration is performed in a device-specific
profile.
---
src/synaptics.c | 124 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 89 insertions(+), 35 deletions(-)
diff --git a/src/synaptics.c b/src/synaptics.c
index 6b902e9..94eed2f 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -77,6 +77,10 @@
#include "synapticsstr.h"
#include "synaptics-properties.h"
+#include <ptrveloc.h>
+#include <xserver-properties.h>
+#include <X11/Xatom.h> /* for XA_INTEGER */
+
typedef enum {
BOTTOM_EDGE = 1,
TOP_EDGE = 2,
@@ -515,6 +519,46 @@ static void set_default_parameters(LocalDevicePtr local)
}
}
+static float SynapticsAccelerationProfile
+ (DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
+ float velocity,
+ float thr,
+ float acc) {
+ LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
+ SynapticsPrivate *priv = (SynapticsPrivate *) (local->private);
+ SynapticsParameters* para = &priv->synpara;
+
+ double accelfct;
+
+ /* speed up linear with finger velocity */
+ accelfct = velocity * para->accl;
+
+ if (accelfct > para->max_speed) { /* clip speed factor */
+ accelfct = para->max_speed;
+ } else if (accelfct < para->min_speed) {
+ /* this may be bogus since dix also enforces a min accel */
+ accelfct = para->min_speed;
+ }
+
+ /* modify speed according to pressure */
+ if (priv->moving_state == MS_TOUCHPAD_RELATIVE) {
+ int minZ = para->press_motion_min_z;
+ int maxZ = para->press_motion_max_z;
+ double minFctr = para->press_motion_min_factor;
+ double maxFctr = para->press_motion_max_factor;
+ if (priv->hwState.z <= minZ) {
+ accelfct *= minFctr;
+ } else if (priv->hwState.z >= maxZ) {
+ accelfct *= maxFctr;
+ } else {
+ accelfct *= minFctr + (priv->hwState.z - minZ) * (maxFctr -
minFctr) / (maxZ - minZ);
+ }
+ }
+
+ return accelfct;
+}
+
/*
* called by the module loader for initialization
*/
@@ -793,6 +837,8 @@ DeviceInit(DeviceIntPtr dev)
{
LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
SynapticsPrivate *priv = (SynapticsPrivate *) (local->private);
+ Atom float_type, prop;
+ float tmpf;
unsigned char map[SYN_MAX_BUTTONS + 1];
int i;
int min, max;
@@ -818,6 +864,45 @@ DeviceInit(DeviceIntPtr dev)
GetMotionHistorySize(), 2
#endif
);
+
+ /*
+ * setup dix acceleration to match legacy synaptics settings, and
+ * etablish a device-specific profile to do stuff like pressure-related
+ * acceleration.
+ */
+ DeviceVelocityPtr pVel = GetDevicePredictableAccelData(dev);
+ if(pVel){
+ SetDeviceSpecificAccelerationProfile(pVel,
SynapticsAccelerationProfile);
+
+ /* float property type */
+ float_type = XIGetKnownProperty(XATOM_FLOAT);
+
+ /* translate MinAcc to constant deceleration.
+ * May be overridden in xf86IVD */
+ tmpf = 1.0 / priv->synpara.min_speed;
+
+ xf86Msg(X_CONFIG, "%s: (accel) MinSpeed is now constant deceleration
%.1f\n",
+ dev->name, tmpf);
+ prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
+ XIChangeDeviceProperty(dev, prop, float_type, 32,
+ PropModeReplace, 1, &tmpf, FALSE);
+
+ /* adjust accordingly */
+ priv->synpara.max_speed /= priv->synpara.min_speed;
+ /* leave priv->synpara.accl alone since velocity includes const decel */
+ priv->synpara.min_speed = 1.0;
+
+ xf86Msg(X_CONFIG, "%s: MaxSpeed is now %.1f\n",
+ dev->name, priv->synpara.max_speed);
+ xf86Msg(X_CONFIG, "%s: AccelFactor is now %.1f\n",
+ dev->name, priv->synpara.accl);
+
+ prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
+ i = AccelProfileDeviceSpecific;
+ XIChangeDeviceProperty(dev, prop, XA_INTEGER, 32,
+ PropModeReplace, 1, &i, FALSE);
+ }
+
/* X valuator */
if (priv->minx < priv->maxx)
{
@@ -861,11 +946,6 @@ DeviceInit(DeviceIntPtr dev)
return Success;
}
-static int
-move_distance(int dx, int dy)
-{
- return sqrt(SQR(dx) + SQR(dy));
-}
/*
* Convert from absolute X/Y coordinates to a coordinate system where
@@ -1474,9 +1554,8 @@ ComputeDeltas(SynapticsPrivate *priv, struct
SynapticsHwState *hw,
{
SynapticsParameters *para = &priv->synpara;
enum MovingState moving_state;
- int dist;
double dx, dy;
- double speed, integral;
+ double integral;
int delay = 1000000000;
dx = dy = 0;
@@ -1556,36 +1635,11 @@ ComputeDeltas(SynapticsPrivate *priv, struct
SynapticsHwState *hw,
}
}
- /* speed depending on distance/packet */
- dist = move_distance(dx, dy);
- speed = dist * para->accl;
- if (speed > para->max_speed) { /* set max speed factor */
- speed = para->max_speed;
- } else if (speed < para->min_speed) { /* set min speed factor */
- speed = para->min_speed;
- }
-
- /* modify speed according to pressure */
- if (priv->moving_state == MS_TOUCHPAD_RELATIVE) {
- int minZ = para->press_motion_min_z;
- int maxZ = para->press_motion_max_z;
- double minFctr = para->press_motion_min_factor;
- double maxFctr = para->press_motion_max_factor;
-
- if (hw->z <= minZ) {
- speed *= minFctr;
- } else if (hw->z >= maxZ) {
- speed *= maxFctr;
- } else {
- speed *= minFctr + (hw->z - minZ) * (maxFctr - minFctr) /
(maxZ - minZ);
- }
- }
-
- /* save the fraction, report the integer part */
- tmpf = dx * speed + x_edge_speed * dtime + priv->frac_x;
+ /* report edge speed as synthetic motion */
+ tmpf = dx + x_edge_speed * dtime + priv->frac_x;
priv->frac_x = modf(tmpf, &integral);
dx = integral;
- tmpf = dy * speed + y_edge_speed * dtime + priv->frac_y;
+ tmpf = dy + y_edge_speed * dtime + priv->frac_y;
priv->frac_y = modf(tmpf, &integral);
dy = integral;
}
--
1.6.0.6
>From bf0dc3f31c6eae5bcf8b4de0eba631d20e1b659d Mon Sep 17 00:00:00 2001
From: Simon Thum <[email protected]>
Date: Sat, 6 Jun 2009 14:49:43 +0200
Subject: [PATCH] dix: improve pointer acceleration API
This makes the ptr accel api actually sensible from a driver
perspective, since the device is now a parameter of the
device-specific accel callback. Also, make independent accel
contexts possible and align argument naming.
---
dix/ptrveloc.c | 391 +++++++++++++++++++++++++++-------------------------
include/ptrveloc.h | 36 +++--
2 files changed, 226 insertions(+), 201 deletions(-)
diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index dd26477..50bfba7 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -61,12 +61,12 @@
/* fwds */
int
-SetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
+SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
static float
-SimpleSmoothProfile(DeviceVelocityPtr pVel, float velocity,
+SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity,
float threshold, float acc);
static PointerAccelerationProfileFunc
-GetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
+GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
/*#define PTRACCEL_DEBUGGING*/
@@ -87,31 +87,31 @@ GetAccelerationProfile(DeviceVelocityPtr s, int
profile_num);
* Init struct so it should match the average case
*/
void
-InitVelocityData(DeviceVelocityPtr s)
+InitVelocityData(DeviceVelocityPtr vel)
{
- memset(s, 0, sizeof(DeviceVelocityRec));
-
- s->corr_mul = 10.0; /* dots per 10 milisecond should be usable */
- s->const_acceleration = 1.0; /* no acceleration/deceleration */
- s->reset_time = 300;
- s->use_softening = 1;
- s->min_acceleration = 1.0; /* don't decelerate */
- s->max_rel_diff = 0.2;
- s->max_diff = 1.0;
- s->initial_range = 2;
- s->average_accel = TRUE;
- SetAccelerationProfile(s, AccelProfileClassic);
- InitTrackers(s, 16);
+ memset(vel, 0, sizeof(DeviceVelocityRec));
+
+ vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */
+ vel->const_acceleration = 1.0; /* no acceleration/deceleration */
+ vel->reset_time = 300;
+ vel->use_softening = 1;
+ vel->min_acceleration = 1.0; /* don't decelerate */
+ vel->max_rel_diff = 0.2;
+ vel->max_diff = 1.0;
+ vel->initial_range = 2;
+ vel->average_accel = TRUE;
+ SetAccelerationProfile(vel, AccelProfileClassic);
+ InitTrackers(vel, 16);
}
/**
* Clean up
*/
-static void
-FreeVelocityData(DeviceVelocityPtr s){
- xfree(s->tracker);
- SetAccelerationProfile(s, PROFILE_UNINITIALIZE);
+void
+FreeVelocityData(DeviceVelocityPtr vel){
+ xfree(vel->tracker);
+ SetAccelerationProfile(vel, PROFILE_UNINITIALIZE);
}
@@ -119,15 +119,15 @@ FreeVelocityData(DeviceVelocityPtr s){
* dix uninit helper, called through scheme
*/
void
-AccelerationDefaultCleanup(DeviceIntPtr pDev)
+AccelerationDefaultCleanup(DeviceIntPtr dev)
{
/*sanity check*/
- if( pDev->valuator->accelScheme.AccelSchemeProc ==
acceleratePointerPredictable
- && pDev->valuator->accelScheme.accelData != NULL){
- pDev->valuator->accelScheme.AccelSchemeProc = NULL;
- FreeVelocityData(pDev->valuator->accelScheme.accelData);
- xfree(pDev->valuator->accelScheme.accelData);
- pDev->valuator->accelScheme.accelData = NULL;
+ if( dev->valuator->accelScheme.AccelSchemeProc ==
acceleratePointerPredictable
+ && dev->valuator->accelScheme.accelData != NULL){
+ dev->valuator->accelScheme.AccelSchemeProc = NULL;
+ FreeVelocityData(dev->valuator->accelScheme.accelData);
+ xfree(dev->valuator->accelScheme.accelData);
+ dev->valuator->accelScheme.accelData = NULL;
}
}
@@ -143,7 +143,7 @@ static int
AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly)
{
- DeviceVelocityPtr pVel;
+ DeviceVelocityPtr vel;
int profile, *ptr = &profile;
int rc;
int nelem = 1;
@@ -151,8 +151,8 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER))
return Success;
- pVel = GetDevicePredictableAccelData(dev);
- if (!pVel)
+ vel = GetDevicePredictableAccelData(dev);
+ if (!vel)
return BadValue;
rc = XIPropToInt(val, &nelem, &ptr);
@@ -161,18 +161,18 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
if (rc)
return rc;
- if (GetAccelerationProfile(pVel, profile) == NULL)
+ if (GetAccelerationProfile(vel, profile) == NULL)
return BadValue;
} else
- SetAccelerationProfile(pVel, profile);
+ SetAccelerationProfile(vel, profile);
return Success;
}
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);
XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32,
@@ -188,7 +188,7 @@ static int
AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly)
{
- DeviceVelocityPtr pVel;
+ DeviceVelocityPtr vel;
float v, *ptr = &v;
int rc;
int nelem = 1;
@@ -196,8 +196,8 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION))
return Success;
- pVel = GetDevicePredictableAccelData(dev);
- if (!pVel)
+ vel = GetDevicePredictableAccelData(dev);
+ if (!vel)
return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr);
@@ -209,15 +209,15 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
}
if(v >= 1.0f)
- pVel->const_acceleration = 1/v;
+ vel->const_acceleration = 1/v;
return Success;
}
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);
XIChangeDeviceProperty(dev, prop_const_decel,
XIGetKnownProperty(XATOM_FLOAT), 32,
@@ -234,7 +234,7 @@ static int
AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly)
{
- DeviceVelocityPtr pVel;
+ DeviceVelocityPtr veloc;
float v, *ptr = &v;
int rc;
int nelem = 1;
@@ -242,8 +242,8 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION))
return Success;
- pVel = GetDevicePredictableAccelData(dev);
- if (!pVel)
+ veloc = GetDevicePredictableAccelData(dev);
+ if (!veloc)
return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr);
@@ -255,15 +255,15 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
}
if(v >= 1.0f)
- pVel->min_acceleration = 1/v;
+ veloc->min_acceleration = 1/v;
return Success;
}
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);
XIChangeDeviceProperty(dev, prop_adapt_decel,
XIGetKnownProperty(XATOM_FLOAT), 32,
@@ -280,7 +280,7 @@ static int
AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkOnly)
{
- DeviceVelocityPtr pVel;
+ DeviceVelocityPtr vel;
float v, *ptr = &v;
int rc;
int nelem = 1;
@@ -288,8 +288,8 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING))
return Success;
- pVel = GetDevicePredictableAccelData(dev);
- if (!pVel)
+ vel = GetDevicePredictableAccelData(dev);
+ if (!vel)
return BadValue;
rc = XIPropToFloat(val, &nelem, &ptr);
@@ -302,15 +302,15 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
}
if(v > 0)
- pVel->corr_mul = v;
+ vel->corr_mul = v;
return Success;
}
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);
XIChangeDeviceProperty(dev, prop_velo_scale,
XIGetKnownProperty(XATOM_FLOAT), 32,
@@ -322,15 +322,15 @@ AccelInitScaleProperty(DeviceIntPtr dev,
DeviceVelocityPtr pVel)
BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr device)
{
- DeviceVelocityPtr pVel = GetDevicePredictableAccelData(device);
+ DeviceVelocityPtr vel = GetDevicePredictableAccelData(device);
- if(!pVel)
+ if(!vel)
return FALSE;
- AccelInitProfileProperty(device, pVel);
- AccelInitDecelProperty(device, pVel);
- AccelInitAdaptDecelProperty(device, pVel);
- AccelInitScaleProperty(device, pVel);
+ AccelInitProfileProperty(device, vel);
+ AccelInitDecelProperty(device, vel);
+ AccelInitAdaptDecelProperty(device, vel);
+ AccelInitScaleProperty(device, vel);
return TRUE;
}
@@ -339,16 +339,16 @@ InitializePredictableAccelerationProperties(DeviceIntPtr
device)
********************/
void
-InitTrackers(DeviceVelocityPtr s, int ntracker)
+InitTrackers(DeviceVelocityPtr vel, int ntracker)
{
if(ntracker < 1){
ErrorF("(dix ptracc) invalid number of trackers\n");
return;
}
- xfree(s->tracker);
- s->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker));
- memset(s->tracker, 0, ntracker * sizeof(MotionTracker));
- s->num_tracker = ntracker;
+ xfree(vel->tracker);
+ vel->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker));
+ memset(vel->tracker, 0, ntracker * sizeof(MotionTracker));
+ 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)
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;
- for(n = 0; n < s->num_tracker; n++){
- s->tracker[n].dx += dx;
- s->tracker[n].dy += dy;
+ for(n = 0; n < vel->num_tracker; n++){
+ vel->tracker[n].dx += dx;
+ vel->tracker[n].dy += dy;
}
- n = (s->cur_tracker + 1) % s->num_tracker;
- s->tracker[n].dx = 0;
- s->tracker[n].dy = 0;
- s->tracker[n].time = cur_t;
- s->tracker[n].dir = GetDirection(dx, dy);
+ n = (vel->cur_tracker + 1) % vel->num_tracker;
+ vel->tracker[n].dx = 0;
+ vel->tracker[n].dy = 0;
+ vel->tracker[n].time = cur_t;
+ vel->tracker[n].dir = GetDirection(dx, dy);
DebugAccelF("(dix prtacc) motion [dx: %i dy: %i dir:%i diff: %i]\n",
- dx, dy, s->tracker[n].dir,
- cur_t - s->tracker[s->cur_tracker].time);
- s->cur_tracker = n;
+ dx, dy, vel->tracker[n].dir,
+ cur_t - vel->tracker[vel->cur_tracker].time);
+ vel->cur_tracker = n;
}
/**
@@ -461,11 +461,11 @@ FeedTrackers(DeviceVelocityPtr s, int dx, int dy, int
cur_t)
* This assumes linear motion.
*/
static float
-CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){
- int index = TRACKER_INDEX(s, offset);
- float dist = sqrt( s->tracker[index].dx * s->tracker[index].dx
- + s->tracker[index].dy * s->tracker[index].dy);
- int dtime = cur_t - s->tracker[index].time;
+CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){
+ int index = TRACKER_INDEX(vel, offset);
+ float dist = sqrt( vel->tracker[index].dx * vel->tracker[index].dx
+ + vel->tracker[index].dy * vel->tracker[index].dy);
+ int dtime = cur_t - vel->tracker[index].time;
if(dtime > 0)
return (dist / dtime);
else
@@ -479,19 +479,19 @@ CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){
* May return 0.
*/
static float
-QueryTrackers(DeviceVelocityPtr s, int cur_t){
+QueryTrackers(DeviceVelocityPtr vel, int cur_t){
int n, offset, dir = 255, i = -1, age_ms;
/* initial velocity: a low-offset, valid velocity */
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 */
- for(offset = 1; offset < s->num_tracker; offset++){
- n = TRACKER_INDEX(s, offset);
+ for(offset = 1; offset < vel->num_tracker; 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 */
- 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");
break;
}
@@ -502,7 +502,7 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
* even more precision we could subdivide as a final step, so possible
* non-linearities are accounted for.
*/
- dir &= s->tracker[n].dir;
+ dir &= vel->tracker[n].dir;
if(dir == 0){
DebugAccelF("(dix prtacc) query: no longer linear\n");
/* instead of breaking it we might also inspect the partition after,
@@ -510,16 +510,16 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
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 */
res = iveloc = tmp;
i = offset;
} else if (iveloc != 0 && tmp != 0) {
vdiff = fabs(iveloc - tmp);
- if (vdiff <= s->max_diff ||
- vdiff/(iveloc + tmp) < s->max_rel_diff) {
+ if (vdiff <= vel->max_diff ||
+ vdiff/(iveloc + tmp) < vel->max_rel_diff) {
/* we're in range with the initial velocity,
* so this result is likely better
* (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");
- i = s->num_tracker-1;
+ i = vel->num_tracker-1;
}
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",
i,
- s->tracker[n].dx,
- s->tracker[n].dy,
- cur_t - s->tracker[n].time);
+ vel->tracker[n].dx,
+ vel->tracker[n].dy,
+ cur_t - vel->tracker[n].time);
}
return res;
}
@@ -555,22 +555,22 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
* Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
* return true if non-visible state reset is suggested
*/
-static short
+short
ProcessVelocityData2D(
- DeviceVelocityPtr s,
+ DeviceVelocityPtr vel,
int dx,
int dy,
int time)
{
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;
}
@@ -594,41 +594,42 @@ ApplySimpleSoftening(int od, int d)
static void
ApplySofteningAndConstantDeceleration(
- DeviceVelocityPtr s,
+ DeviceVelocityPtr vel,
int dx,
int dy,
float* fdx,
float* fdy,
short do_soften)
{
- if (do_soften && s->use_softening) {
- *fdx = ApplySimpleSoftening(s->last_dx, dx);
- *fdy = ApplySimpleSoftening(s->last_dy, dy);
+ if (do_soften && vel->use_softening) {
+ *fdx = ApplySimpleSoftening(vel->last_dx, dx);
+ *fdy = ApplySimpleSoftening(vel->last_dy, dy);
} else {
*fdx = dx;
*fdy = dy;
}
- *fdx *= s->const_acceleration;
- *fdy *= s->const_acceleration;
+ *fdx *= vel->const_acceleration;
+ *fdy *= vel->const_acceleration;
}
/*
* compute the acceleration for given velocity and enforce min_acceleartion
*/
-static float
+float
BasicComputeAcceleration(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc){
float result;
- result = pVel->Profile(pVel, velocity, threshold, acc);
+ result = vel->Profile(dev, vel, velocity, threshold, acc);
/* enforce min_acceleration */
- if (result < pVel->min_acceleration)
- result = pVel->min_acceleration;
+ if (result < vel->min_acceleration)
+ result = vel->min_acceleration;
return result;
}
@@ -637,6 +638,7 @@ BasicComputeAcceleration(
*/
static float
ComputeAcceleration(
+ DeviceIntPtr dev,
DeviceVelocityPtr vel,
float threshold,
float acc){
@@ -655,9 +657,11 @@ ComputeAcceleration(
* current and previous velocity.
* Though being the more natural choice, it causes a minor delay
* in comparison, so it can be disabled. */
- res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc);
- res += BasicComputeAcceleration(vel, vel->last_velocity, threshold,
acc);
- res += 4.0f * BasicComputeAcceleration(vel,
+ res = BasicComputeAcceleration(
+ dev, vel, vel->velocity, threshold, acc);
+ res += BasicComputeAcceleration(
+ dev, vel, vel->last_velocity, threshold, acc);
+ res += 4.0f * BasicComputeAcceleration(dev, vel,
(vel->last_velocity + vel->velocity) / 2,
threshold, acc);
res /= 6.0f;
@@ -665,7 +669,8 @@ ComputeAcceleration(
vel->velocity, vel->last_velocity, res);
return res;
}else{
- res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc);
+ res = BasicComputeAcceleration(dev, vel,
+ vel->velocity, threshold, acc);
DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
vel->velocity, res);
return res;
@@ -682,7 +687,8 @@ ComputeAcceleration(
*/
static float
PolynomialAccelerationProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float ignored,
float acc)
@@ -697,18 +703,21 @@ PolynomialAccelerationProfile(
*/
static float
ClassicProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
{
- if (threshold) {
- return SimpleSmoothProfile (pVel,
+ if (threshold > 0) {
+ return SimpleSmoothProfile (dev,
+ vel,
velocity,
threshold,
acc);
} else {
- return PolynomialAccelerationProfile (pVel,
+ return PolynomialAccelerationProfile (dev,
+ vel,
velocity,
0,
acc);
@@ -726,7 +735,8 @@ ClassicProfile(
*/
static float
PowerProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
@@ -736,9 +746,9 @@ PowerProfile(
acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */
if (velocity <= threshold)
- return pVel->min_acceleration;
+ return vel->min_acceleration;
vel_dist = velocity - threshold;
- return (pow(acc, vel_dist)) * pVel->min_acceleration;
+ return (pow(acc, vel_dist)) * vel->min_acceleration;
}
@@ -763,7 +773,8 @@ CalcPenumbralGradient(float x){
*/
static float
SimpleSmoothProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
@@ -788,7 +799,8 @@ SimpleSmoothProfile(
*/
static float
SmoothLinearProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
@@ -811,14 +823,15 @@ SmoothLinearProfile(
res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */
+ 1.0f; /* gradient crosses 2|1 */
}
- res += pVel->min_acceleration;
+ res += vel->min_acceleration;
return res;
}
static float
LinearProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
@@ -829,7 +842,8 @@ LinearProfile(
static float
NoProfile(
- DeviceVelocityPtr pVel,
+ DeviceIntPtr dev,
+ DeviceVelocityPtr vel,
float velocity,
float threshold,
float acc)
@@ -839,14 +853,14 @@ NoProfile(
static PointerAccelerationProfileFunc
GetAccelerationProfile(
- DeviceVelocityPtr s,
+ DeviceVelocityPtr vel,
int profile_num)
{
switch(profile_num){
case AccelProfileClassic:
return ClassicProfile;
case AccelProfileDeviceSpecific:
- return s->deviceSpecificProfile;
+ return vel->deviceSpecificProfile;
case AccelProfilePolynomial:
return PolynomialAccelerationProfile;
case AccelProfileSmoothLinear:
@@ -876,23 +890,23 @@ GetAccelerationProfile(
*/
int
SetAccelerationProfile(
- DeviceVelocityPtr s,
+ DeviceVelocityPtr vel,
int profile_num)
{
PointerAccelerationProfileFunc profile;
- profile = GetAccelerationProfile(s, profile_num);
+ profile = GetAccelerationProfile(vel, profile_num);
if(profile == NULL && profile_num != PROFILE_UNINITIALIZE)
return FALSE;
- if(s->profile_private != NULL){
+ if(vel->profile_private != NULL){
/* Here one could free old profile-private data */
- xfree(s->profile_private);
- s->profile_private = NULL;
+ xfree(vel->profile_private);
+ vel->profile_private = NULL;
}
/* Here one could init profile-private data */
- s->Profile = profile;
- s->statistics.profile_number = profile_num;
+ vel->Profile = profile;
+ vel->statistics.profile_number = profile_num;
return TRUE;
}
@@ -912,11 +926,11 @@ SetAccelerationProfile(
*/
void
SetDeviceSpecificAccelerationProfile(
- DeviceVelocityPtr s,
+ DeviceVelocityPtr vel,
PointerAccelerationProfileFunc profile)
{
- if(s)
- s->deviceSpecificProfile = profile;
+ if(vel)
+ vel->deviceSpecificProfile = profile;
}
/**
@@ -925,19 +939,19 @@ SetDeviceSpecificAccelerationProfile(
*/
DeviceVelocityPtr
GetDevicePredictableAccelData(
- DeviceIntPtr pDev)
+ DeviceIntPtr dev)
{
/*sanity check*/
- if(!pDev){
+ if(!dev){
ErrorF("[dix] accel: DeviceIntPtr was NULL");
return NULL;
}
- if( pDev->valuator &&
- pDev->valuator->accelScheme.AccelSchemeProc ==
+ if( dev->valuator &&
+ dev->valuator->accelScheme.AccelSchemeProc ==
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;
}
@@ -953,7 +967,7 @@ GetDevicePredictableAccelData(
*/
void
acceleratePointerPredictable(
- DeviceIntPtr pDev,
+ DeviceIntPtr dev,
int first_valuator,
int num_valuators,
int *valuators,
@@ -963,7 +977,7 @@ acceleratePointerPredictable(
int dx = 0, dy = 0;
int *px = NULL, *py = NULL;
DeviceVelocityPtr velocitydata =
- (DeviceVelocityPtr) pDev->valuator->accelScheme.accelData;
+ (DeviceVelocityPtr) dev->valuator->accelScheme.accelData;
float fdx, fdy, tmp; /* no need to init */
Bool soften = TRUE;
@@ -990,12 +1004,12 @@ acceleratePointerPredictable(
soften = FALSE;
}
- if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) {
+ if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
/* invoke acceleration profile to determine acceleration */
- mult = ComputeAcceleration (velocitydata,
- pDev->ptrfeed->ctrl.threshold,
- (float)pDev->ptrfeed->ctrl.num /
- (float)pDev->ptrfeed->ctrl.den);
+ mult = ComputeAcceleration (dev, velocitydata,
+ dev->ptrfeed->ctrl.threshold,
+ (float)dev->ptrfeed->ctrl.num /
+ (float)dev->ptrfeed->ctrl.den);
if(mult != 1.0 || velocitydata->const_acceleration != 1.0) {
ApplySofteningAndConstantDeceleration( velocitydata,
@@ -1004,21 +1018,22 @@ acceleratePointerPredictable(
(mult > 1.0) && soften);
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
* strong statements about rounding; however because we
* 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);
- pDev->last.remainder[0] = tmp - (float)*px;
+ dev->last.remainder[0] = tmp - (float)*px;
}
if (dy) {
- tmp = mult * fdy + pDev->last.remainder[1];
+ tmp = mult * fdy + dev->last.remainder[1];
*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);
}
}
}
@@ -1035,7 +1050,7 @@ acceleratePointerPredictable(
*/
void
acceleratePointerLightweight(
- DeviceIntPtr pDev,
+ DeviceIntPtr dev,
int first_valuator,
int num_valuators,
int *valuators,
@@ -1060,48 +1075,48 @@ acceleratePointerLightweight(
if (!dx && !dy)
return;
- if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) {
+ if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
/* modeled from xf86Events.c */
- if (pDev->ptrfeed->ctrl.threshold) {
- if ((abs(dx) + abs(dy)) >= pDev->ptrfeed->ctrl.threshold) {
- pDev->last.remainder[0] = ((float)dx *
- (float)(pDev->ptrfeed->ctrl.num))
/
- (float)(pDev->ptrfeed->ctrl.den) +
- pDev->last.remainder[0];
+ 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)pDev->last.remainder[0];
- pDev->last.remainder[0] = pDev->last.remainder[0] -
+ *px = (int)dev->last.remainder[0];
+ dev->last.remainder[0] = dev->last.remainder[0] -
(float)(*px);
}
- pDev->last.remainder[1] = ((float)dy *
- (float)(pDev->ptrfeed->ctrl.num))
/
- (float)(pDev->ptrfeed->ctrl.den) +
- pDev->last.remainder[1];
+ dev->last.remainder[1] = ((float)dy *
+ (float)(dev->ptrfeed->ctrl.num)) /
+ (float)(dev->ptrfeed->ctrl.den) +
+ dev->last.remainder[1];
if (py) {
- *py = (int)pDev->last.remainder[1];
- pDev->last.remainder[1] = pDev->last.remainder[1] -
+ *py = (int)dev->last.remainder[1];
+ dev->last.remainder[1] = dev->last.remainder[1] -
(float)(*py);
}
}
}
else {
mult = pow((float)dx * (float)dx + (float)dy * (float)dy,
- ((float)(pDev->ptrfeed->ctrl.num) /
- (float)(pDev->ptrfeed->ctrl.den) - 1.0) /
+ ((float)(dev->ptrfeed->ctrl.num) /
+ (float)(dev->ptrfeed->ctrl.den) - 1.0) /
2.0) / 2.0;
if (dx) {
- pDev->last.remainder[0] = mult * (float)dx +
- pDev->last.remainder[0];
- *px = (int)pDev->last.remainder[0];
- pDev->last.remainder[0] = pDev->last.remainder[0] -
+ 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);
}
if (dy) {
- pDev->last.remainder[1] = mult * (float)dy +
- pDev->last.remainder[1];
- *py = (int)pDev->last.remainder[1];
- pDev->last.remainder[1] = pDev->last.remainder[1] -
+ 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);
}
}
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index 83d188c..317bc26 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright © 2006-2008 Simon Thum simon dot thum at gmx dot de
+ * Copyright © 2006-2009 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"),
@@ -47,8 +47,8 @@ struct _DeviceVelocityRec;
* returns actual acceleration depending on velocity, acceleration control,...
*/
typedef float (*PointerAccelerationProfileFunc)
- (struct _DeviceVelocityRec* /*pVel*/,
- float /*velocity*/, float /*threshold*/, float /*acc*/);
+ (DeviceIntPtr dev, struct _DeviceVelocityRec* vel,
+ float velocity, float threshold, float accelCoeff);
/**
* a motion history, with just enough information to
@@ -91,33 +91,43 @@ typedef struct _DeviceVelocityRec {
extern _X_EXPORT void
-InitVelocityData(DeviceVelocityPtr s);
+InitVelocityData(DeviceVelocityPtr vel);
extern _X_EXPORT void
-InitTrackers(DeviceVelocityPtr s, int ntracker);
+InitTrackers(DeviceVelocityPtr vel, int ntracker);
+
+extern _X_EXPORT short
+ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
+
+extern _X_EXPORT float
+BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
+ float velocity, float threshold, float acc);
+
+extern _X_EXPORT void
+FreeVelocityData(DeviceVelocityPtr vel);
extern _X_EXPORT BOOL
-InitializePredictableAccelerationProperties(DeviceIntPtr pDev);
+InitializePredictableAccelerationProperties(DeviceIntPtr dev);
extern _X_EXPORT int
-SetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
+SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
extern _X_EXPORT DeviceVelocityPtr
-GetDevicePredictableAccelData(DeviceIntPtr pDev);
+GetDevicePredictableAccelData(DeviceIntPtr dev);
extern _X_EXPORT void
-SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr s,
+SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
PointerAccelerationProfileFunc profile);
extern _X_EXPORT void
-AccelerationDefaultCleanup(DeviceIntPtr pDev);
+AccelerationDefaultCleanup(DeviceIntPtr dev);
extern _X_EXPORT void
-acceleratePointerPredictable(DeviceIntPtr pDev, int first_valuator,
+acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
int num_valuators, int *valuators, int evtime);
extern _X_EXPORT void
-acceleratePointerLightweight(DeviceIntPtr pDev, int first_valuator,
- int num_valuators, int *valuators, int ignore);
+acceleratePointerLightweight(DeviceIntPtr dev, int first_valuator,
+ int num_valuators, int *valuators, int ignored);
#endif /* POINTERVELOCITY_H */
--
1.6.0.6
>From 68c18962c80df28224f1716c129b30402e92d7ea Mon Sep 17 00:00:00 2001
From: Simon Thum <[email protected]>
Date: Sat, 20 Jun 2009 18:57:22 +0200
Subject: [PATCH] dix: make part of ptrveloc.h internal
Though this is a SDK header, some functions are intended solely
for the server.
---
include/ptrveloc.h | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index 317bc26..fa2156b 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -106,7 +106,7 @@ BasicComputeAcceleration(DeviceIntPtr dev,
DeviceVelocityPtr vel,
extern _X_EXPORT void
FreeVelocityData(DeviceVelocityPtr vel);
-extern _X_EXPORT BOOL
+extern _X_INTERNAL BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr dev);
extern _X_EXPORT int
@@ -119,14 +119,14 @@ extern _X_EXPORT void
SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
PointerAccelerationProfileFunc profile);
-extern _X_EXPORT void
+extern _X_INTERNAL void
AccelerationDefaultCleanup(DeviceIntPtr dev);
-extern _X_EXPORT void
+extern _X_INTERNAL void
acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
int num_valuators, int *valuators, int evtime);
-extern _X_EXPORT void
+extern _X_INTERNAL void
acceleratePointerLightweight(DeviceIntPtr dev, int first_valuator,
int num_valuators, int *valuators, int ignored);
--
1.6.0.6
_______________________________________________
xorg-devel mailing list
[email protected]
http://lists.x.org/mailman/listinfo/xorg-devel