2009-09-06 13:44:18 -06:00
|
|
|
/*
|
|
|
|
*
|
2010-07-27 13:02:24 -06:00
|
|
|
* Copyright © 2006-2009 Simon Thum simon dot thum at gmx dot de
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <ptrveloc.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <exevents.h>
|
|
|
|
#include <X11/Xatom.h>
|
2011-11-05 07:32:40 -06:00
|
|
|
#include <os.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#include <xserver-properties.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Predictable pointer acceleration
|
|
|
|
*
|
2010-07-27 13:02:24 -06:00
|
|
|
* 2006-2009 by Simon Thum (simon [dot] thum [at] gmx de)
|
2009-09-06 13:44:18 -06:00
|
|
|
*
|
|
|
|
* Serves 3 complementary functions:
|
|
|
|
* 1) provide a sophisticated ballistic velocity estimate to improve
|
|
|
|
* the relation between velocity (of the device) and acceleration
|
|
|
|
* 2) make arbitrary acceleration profiles possible
|
|
|
|
* 3) decelerate by two means (constant and adaptive) if enabled
|
|
|
|
*
|
|
|
|
* Important concepts are the
|
|
|
|
*
|
|
|
|
* - Scheme
|
|
|
|
* which selects the basic algorithm
|
|
|
|
* (see devices.c/InitPointerAccelerationScheme)
|
|
|
|
* - Profile
|
|
|
|
* which returns an acceleration
|
|
|
|
* for a given velocity
|
|
|
|
*
|
2010-07-27 13:02:24 -06:00
|
|
|
* The profile can be selected by the user at runtime.
|
|
|
|
* The classic profile is intended to cleanly perform old-style
|
2009-09-06 13:44:18 -06:00
|
|
|
* function selection (threshold =/!= 0)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* fwds */
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
|
|
|
static double
|
|
|
|
|
|
|
|
SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, double velocity,
|
|
|
|
double threshold, double acc);
|
2010-07-27 13:02:24 -06:00
|
|
|
static PointerAccelerationProfileFunc
|
|
|
|
GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
2011-11-05 07:32:40 -06:00
|
|
|
static BOOL
|
|
|
|
InitializePredictableAccelerationProperties(DeviceIntPtr,
|
|
|
|
DeviceVelocityPtr,
|
|
|
|
PredictableAccelSchemePtr);
|
|
|
|
static BOOL
|
|
|
|
DeletePredictableAccelerationProperties(DeviceIntPtr,
|
|
|
|
PredictableAccelSchemePtr);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/*#define PTRACCEL_DEBUGGING*/
|
|
|
|
|
|
|
|
#ifdef PTRACCEL_DEBUGGING
|
|
|
|
#define DebugAccelF ErrorF
|
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
#define DebugAccelF(...) /* */
|
2009-09-06 13:44:18 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/********************************
|
2010-07-27 13:02:24 -06:00
|
|
|
* Init/Uninit
|
2009-09-06 13:44:18 -06:00
|
|
|
*******************************/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* some int which is not a profile number */
|
|
|
|
#define PROFILE_UNINITIALIZE (-100)
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/**
|
2011-11-05 07:32:40 -06:00
|
|
|
* Init DeviceVelocity struct so it should match the average case
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
void
|
2010-07-27 13:02:24 -06:00
|
|
|
InitVelocityData(DeviceVelocityPtr vel)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(vel, 0, sizeof(DeviceVelocityRec));
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */
|
|
|
|
vel->const_acceleration = 1.0; /* no acceleration/deceleration */
|
2010-07-27 13:02:24 -06:00
|
|
|
vel->reset_time = 300;
|
|
|
|
vel->use_softening = 1;
|
2012-06-10 07:21:05 -06:00
|
|
|
vel->min_acceleration = 1.0; /* don't decelerate */
|
2010-07-27 13:02:24 -06:00
|
|
|
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);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-05 07:32:40 -06:00
|
|
|
* Clean up DeviceVelocityRec
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeVelocityData(DeviceVelocityPtr vel)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(vel->tracker);
|
2010-07-27 13:02:24 -06:00
|
|
|
SetAccelerationProfile(vel, PROFILE_UNINITIALIZE);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Init predictable scheme
|
|
|
|
*/
|
|
|
|
Bool
|
|
|
|
InitPredictableAccelerationScheme(DeviceIntPtr dev,
|
2012-06-10 07:21:05 -06:00
|
|
|
ValuatorAccelerationPtr protoScheme)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
DeviceVelocityPtr vel;
|
|
|
|
ValuatorAccelerationRec scheme;
|
|
|
|
PredictableAccelSchemePtr schemeData;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
scheme = *protoScheme;
|
|
|
|
vel = calloc(1, sizeof(DeviceVelocityRec));
|
|
|
|
schemeData = calloc(1, sizeof(PredictableAccelSchemeRec));
|
|
|
|
if (!vel || !schemeData)
|
|
|
|
return FALSE;
|
|
|
|
InitVelocityData(vel);
|
|
|
|
schemeData->vel = vel;
|
|
|
|
scheme.accelData = schemeData;
|
|
|
|
if (!InitializePredictableAccelerationProperties(dev, vel, schemeData))
|
|
|
|
return FALSE;
|
|
|
|
/* all fine, assign scheme to device */
|
|
|
|
dev->valuator->accelScheme = scheme;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninit scheme
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
void
|
2010-07-27 13:02:24 -06:00
|
|
|
AccelerationDefaultCleanup(DeviceIntPtr dev)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (vel) {
|
|
|
|
/* the proper guarantee would be that we're not inside of
|
|
|
|
* AccelSchemeProc(), but that seems impossible. Schemes don't get
|
|
|
|
* switched often anyway.
|
|
|
|
*/
|
|
|
|
OsBlockSignals();
|
2010-07-27 13:02:24 -06:00
|
|
|
dev->valuator->accelScheme.AccelSchemeProc = NULL;
|
2011-11-05 07:32:40 -06:00
|
|
|
FreeVelocityData(vel);
|
|
|
|
free(vel);
|
|
|
|
DeletePredictableAccelerationProperties(dev,
|
2012-06-10 07:21:05 -06:00
|
|
|
(PredictableAccelSchemePtr)
|
|
|
|
dev->valuator->accelScheme.
|
|
|
|
accelData);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(dev->valuator->accelScheme.accelData);
|
2010-07-27 13:02:24 -06:00
|
|
|
dev->valuator->accelScheme.accelData = NULL;
|
2011-11-05 07:32:40 -06:00
|
|
|
OsReleaseSignals();
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/*************************
|
|
|
|
* Input property support
|
|
|
|
************************/
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/**
|
2010-07-27 13:02:24 -06:00
|
|
|
* choose profile
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
|
|
|
|
XIPropertyValuePtr val, BOOL checkOnly)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceVelocityPtr vel;
|
|
|
|
int profile, *ptr = &profile;
|
|
|
|
int rc;
|
|
|
|
int nelem = 1;
|
|
|
|
|
|
|
|
if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER))
|
|
|
|
return Success;
|
|
|
|
|
|
|
|
vel = GetDevicePredictableAccelData(dev);
|
|
|
|
if (!vel)
|
|
|
|
return BadValue;
|
|
|
|
rc = XIPropToInt(val, &nelem, &ptr);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (checkOnly) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (GetAccelerationProfile(vel, profile) == NULL)
|
|
|
|
return BadValue;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
SetAccelerationProfile(vel, profile);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static long
|
|
|
|
AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
int profile = vel->statistics.profile_number;
|
|
|
|
Atom prop_profile_number = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32,
|
|
|
|
PropModeReplace, 1, &profile, FALSE);
|
|
|
|
XISetDevicePropertyDeletable(dev, prop_profile_number, FALSE);
|
|
|
|
return XIRegisterPropertyHandler(dev, AccelSetProfileProperty, NULL, NULL);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* constant deceleration
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
|
|
|
|
XIPropertyValuePtr val, BOOL checkOnly)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceVelocityPtr vel;
|
|
|
|
float v, *ptr = &v;
|
|
|
|
int rc;
|
|
|
|
int nelem = 1;
|
|
|
|
|
|
|
|
if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION))
|
|
|
|
return Success;
|
|
|
|
|
|
|
|
vel = GetDevicePredictableAccelData(dev);
|
|
|
|
if (!vel)
|
|
|
|
return BadValue;
|
|
|
|
rc = XIPropToFloat(val, &nelem, &ptr);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (checkOnly) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2012-06-10 07:21:05 -06:00
|
|
|
return (v >= 1.0f) ? Success : BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (v >= 1.0f)
|
|
|
|
vel->const_acceleration = 1 / v;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
|
|
|
AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
float fval = 1.0 / vel->const_acceleration;
|
|
|
|
Atom prop_const_decel =
|
|
|
|
XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
|
2010-07-27 13:02:24 -06:00
|
|
|
XIChangeDeviceProperty(dev, prop_const_decel,
|
2012-06-10 07:21:05 -06:00
|
|
|
XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace,
|
|
|
|
1, &fval, FALSE);
|
2010-07-27 13:02:24 -06:00
|
|
|
XISetDevicePropertyDeletable(dev, prop_const_decel, FALSE);
|
|
|
|
return XIRegisterPropertyHandler(dev, AccelSetDecelProperty, NULL, NULL);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-27 13:02:24 -06:00
|
|
|
* adaptive deceleration
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
static int
|
|
|
|
AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
|
|
|
|
XIPropertyValuePtr val, BOOL checkOnly)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceVelocityPtr veloc;
|
|
|
|
float v, *ptr = &v;
|
|
|
|
int rc;
|
|
|
|
int nelem = 1;
|
|
|
|
|
|
|
|
if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION))
|
|
|
|
return Success;
|
|
|
|
|
|
|
|
veloc = GetDevicePredictableAccelData(dev);
|
|
|
|
if (!veloc)
|
|
|
|
return BadValue;
|
|
|
|
rc = XIPropToFloat(val, &nelem, &ptr);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (checkOnly) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2012-06-10 07:21:05 -06:00
|
|
|
return (v >= 1.0f) ? Success : BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (v >= 1.0f)
|
|
|
|
veloc->min_acceleration = 1 / v;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static long
|
|
|
|
AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
float fval = 1.0 / vel->min_acceleration;
|
|
|
|
Atom prop_adapt_decel =
|
|
|
|
XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
XIChangeDeviceProperty(dev, prop_adapt_decel,
|
|
|
|
XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace,
|
|
|
|
1, &fval, FALSE);
|
2010-07-27 13:02:24 -06:00
|
|
|
XISetDevicePropertyDeletable(dev, prop_adapt_decel, FALSE);
|
2012-06-10 07:21:05 -06:00
|
|
|
return XIRegisterPropertyHandler(dev, AccelSetAdaptDecelProperty, NULL,
|
|
|
|
NULL);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* velocity scaling
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
|
|
|
|
XIPropertyValuePtr val, BOOL checkOnly)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceVelocityPtr vel;
|
|
|
|
float v, *ptr = &v;
|
|
|
|
int rc;
|
|
|
|
int nelem = 1;
|
|
|
|
|
|
|
|
if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING))
|
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
vel = GetDevicePredictableAccelData(dev);
|
|
|
|
if (!vel)
|
|
|
|
return BadValue;
|
|
|
|
rc = XIPropToFloat(val, &nelem, &ptr);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (checkOnly) {
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return (v > 0) ? Success : BadValue;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (v > 0)
|
|
|
|
vel->corr_mul = v;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static long
|
|
|
|
AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel)
|
|
|
|
{
|
|
|
|
float fval = vel->corr_mul;
|
|
|
|
Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
XIChangeDeviceProperty(dev, prop_velo_scale,
|
|
|
|
XIGetKnownProperty(XATOM_FLOAT), 32, PropModeReplace,
|
|
|
|
1, &fval, FALSE);
|
2010-07-27 13:02:24 -06:00
|
|
|
XISetDevicePropertyDeletable(dev, prop_velo_scale, FALSE);
|
|
|
|
return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static BOOL
|
2012-06-10 07:21:05 -06:00
|
|
|
InitializePredictableAccelerationProperties(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
PredictableAccelSchemePtr
|
|
|
|
schemeData)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
int num_handlers = 4;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (!vel)
|
2011-11-05 07:32:40 -06:00
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
schemeData->prop_handlers = calloc(num_handlers, sizeof(long));
|
|
|
|
if (!schemeData->prop_handlers)
|
|
|
|
return FALSE;
|
|
|
|
schemeData->num_prop_handlers = num_handlers;
|
|
|
|
schemeData->prop_handlers[0] = AccelInitProfileProperty(dev, vel);
|
|
|
|
schemeData->prop_handlers[1] = AccelInitDecelProperty(dev, vel);
|
|
|
|
schemeData->prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel);
|
|
|
|
schemeData->prop_handlers[3] = AccelInitScaleProperty(dev, vel);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
BOOL
|
2012-06-10 07:21:05 -06:00
|
|
|
DeletePredictableAccelerationProperties(DeviceIntPtr dev,
|
|
|
|
PredictableAccelSchemePtr scheme)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
DeviceVelocityPtr vel;
|
2010-07-27 13:02:24 -06:00
|
|
|
Atom prop;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
|
|
|
|
XIDeleteDeviceProperty(dev, prop, FALSE);
|
|
|
|
prop = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
|
|
|
|
XIDeleteDeviceProperty(dev, prop, FALSE);
|
|
|
|
prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
|
|
|
|
XIDeleteDeviceProperty(dev, prop, FALSE);
|
|
|
|
prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
|
|
|
|
XIDeleteDeviceProperty(dev, prop, FALSE);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
vel = GetDevicePredictableAccelData(dev);
|
2011-11-05 07:32:40 -06:00
|
|
|
if (vel) {
|
|
|
|
for (i = 0; i < scheme->num_prop_handlers; i++)
|
|
|
|
if (scheme->prop_handlers[i])
|
|
|
|
XIUnregisterPropertyHandler(dev, scheme->prop_handlers[i]);
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
free(scheme->prop_handlers);
|
|
|
|
scheme->prop_handlers = NULL;
|
|
|
|
scheme->num_prop_handlers = 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
return TRUE;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/*********************
|
|
|
|
* Tracking logic
|
|
|
|
********************/
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
|
|
|
InitTrackers(DeviceVelocityPtr vel, int ntracker)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ntracker < 1) {
|
|
|
|
ErrorF("(dix ptracc) invalid number of trackers\n");
|
|
|
|
return;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(vel->tracker);
|
2012-06-10 07:21:05 -06:00
|
|
|
vel->tracker = (MotionTrackerPtr) calloc(ntracker, sizeof(MotionTracker));
|
2010-07-27 13:02:24 -06:00
|
|
|
vel->num_tracker = ntracker;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
enum directions {
|
2012-06-10 07:21:05 -06:00
|
|
|
N = (1 << 0),
|
|
|
|
NE = (1 << 1),
|
|
|
|
E = (1 << 2),
|
|
|
|
SE = (1 << 3),
|
|
|
|
S = (1 << 4),
|
|
|
|
SW = (1 << 5),
|
|
|
|
W = (1 << 6),
|
|
|
|
NW = (1 << 7),
|
2011-11-05 07:32:40 -06:00
|
|
|
UNDEFINED = 0xFF
|
|
|
|
};
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/**
|
2010-07-27 13:02:24 -06:00
|
|
|
* return a bit field of possible directions.
|
|
|
|
* There's no reason against widening to more precise directions (<45 degrees),
|
|
|
|
* should it not perform well. All this is needed for is sort out non-linear
|
|
|
|
* motion, so precision isn't paramount. However, one should not flag direction
|
|
|
|
* too narrow, since it would then cut the linear segment to zero size way too
|
|
|
|
* often.
|
2011-11-05 07:32:40 -06:00
|
|
|
*
|
|
|
|
* @return A bitmask for N, NE, S, SE, etc. indicating the directions for
|
|
|
|
* this movement.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
DoGetDirection(int dx, int dy)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
int dir = 0;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* on insignificant mickeys, flag 135 degrees */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (abs(dx) < 2 && abs(dy) < 2) {
|
2011-11-05 07:32:40 -06:00
|
|
|
/* first check diagonal cases */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dx > 0 && dy > 0)
|
2011-11-05 07:32:40 -06:00
|
|
|
dir = E | SE | S;
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (dx > 0 && dy < 0)
|
|
|
|
dir = N | NE | E;
|
|
|
|
else if (dx < 0 && dy < 0)
|
|
|
|
dir = W | NW | N;
|
|
|
|
else if (dx < 0 && dy > 0)
|
|
|
|
dir = W | SW | S;
|
2010-07-27 13:02:24 -06:00
|
|
|
/* check axis-aligned directions */
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (dx > 0)
|
|
|
|
dir = NE | E | SE;
|
|
|
|
else if (dx < 0)
|
|
|
|
dir = NW | W | SW;
|
|
|
|
else if (dy > 0)
|
|
|
|
dir = SE | S | SW;
|
|
|
|
else if (dy < 0)
|
|
|
|
dir = NE | N | NW;
|
2011-11-05 07:32:40 -06:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
dir = UNDEFINED; /* shouldn't happen */
|
|
|
|
}
|
|
|
|
else { /* compute angle and set appropriate flags */
|
|
|
|
double r;
|
2011-11-05 07:32:40 -06:00
|
|
|
int i1, i2;
|
|
|
|
|
|
|
|
r = atan2(dy, dx);
|
|
|
|
/* find direction.
|
|
|
|
*
|
|
|
|
* Add 360° to avoid r become negative since C has no well-defined
|
|
|
|
* modulo for such cases. Then divide by 45° to get the octant
|
|
|
|
* number, e.g.
|
|
|
|
* 0 <= r <= 1 is [0-45]°
|
|
|
|
* 1 <= r <= 2 is [45-90]°
|
|
|
|
* etc.
|
|
|
|
* But we add extra 90° to match up with our N, S, etc. defines up
|
|
|
|
* there, rest stays the same.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
r = (r + (M_PI * 2.5)) / (M_PI / 4);
|
2011-11-05 07:32:40 -06:00
|
|
|
/* this intends to flag 2 directions (45 degrees),
|
|
|
|
* except on very well-aligned mickeys. */
|
2012-06-10 07:21:05 -06:00
|
|
|
i1 = (int) (r + 0.1) % 8;
|
|
|
|
i2 = (int) (r + 0.9) % 8;
|
|
|
|
if (i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
|
|
|
|
dir = UNDEFINED; /* shouldn't happen */
|
2011-11-05 07:32:40 -06:00
|
|
|
else
|
|
|
|
dir = (1 << i1 | 1 << i2);
|
|
|
|
}
|
|
|
|
return dir;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#define DIRECTION_CACHE_RANGE 5
|
|
|
|
#define DIRECTION_CACHE_SIZE (DIRECTION_CACHE_RANGE*2+1)
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/* cache DoGetDirection().
|
|
|
|
* To avoid excessive use of direction calculation, cache the values for
|
|
|
|
* [-5..5] for both x/y. Anything outside of that is calcualted on the fly.
|
|
|
|
*
|
|
|
|
* @return A bitmask for N, NE, S, SE, etc. indicating the directions for
|
|
|
|
* this movement.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
GetDirection(int dx, int dy)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE];
|
2011-11-05 07:32:40 -06:00
|
|
|
int dir;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (abs(dx) <= DIRECTION_CACHE_RANGE && abs(dy) <= DIRECTION_CACHE_RANGE) {
|
|
|
|
/* cacheable */
|
|
|
|
dir = cache[DIRECTION_CACHE_RANGE + dx][DIRECTION_CACHE_RANGE + dy];
|
|
|
|
if (dir == 0) {
|
|
|
|
dir = DoGetDirection(dx, dy);
|
|
|
|
cache[DIRECTION_CACHE_RANGE + dx][DIRECTION_CACHE_RANGE + dy] = dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* non-cacheable */
|
|
|
|
dir = DoGetDirection(dx, dy);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
return dir;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#undef DIRECTION_CACHE_RANGE
|
|
|
|
#undef DIRECTION_CACHE_SIZE
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* convert offset (age) to array index */
|
|
|
|
#define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker)
|
2011-11-05 07:32:40 -06:00
|
|
|
#define TRACKER(s, d) &(s)->tracker[TRACKER_INDEX(s,d)]
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Add the delta motion to each tracker, then reset the latest tracker to
|
|
|
|
* 0/0 and set it as the current one.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
static inline void
|
2012-06-10 07:21:05 -06:00
|
|
|
FeedTrackers(DeviceVelocityPtr vel, double dx, double dy, int cur_t)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int n;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (n = 0; n < vel->num_tracker; n++) {
|
|
|
|
vel->tracker[n].dx += dx;
|
|
|
|
vel->tracker[n].dy += dy;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
n = (vel->cur_tracker + 1) % vel->num_tracker;
|
2012-06-10 07:21:05 -06:00
|
|
|
vel->tracker[n].dx = 0.0;
|
|
|
|
vel->tracker[n].dy = 0.0;
|
2010-07-27 13:02:24 -06:00
|
|
|
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, vel->tracker[n].dir,
|
|
|
|
cur_t - vel->tracker[vel->cur_tracker].time);
|
|
|
|
vel->cur_tracker = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calc velocity for given tracker, with
|
|
|
|
* velocity scaling.
|
|
|
|
* This assumes linear motion.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
CalcTracker(const MotionTracker * tracker, int cur_t)
|
|
|
|
{
|
|
|
|
double dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy);
|
2011-11-05 07:32:40 -06:00
|
|
|
int dtime = cur_t - tracker->time;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (dtime > 0)
|
|
|
|
return dist / dtime;
|
2010-07-27 13:02:24 -06:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0; /* synonymous for NaN, since we're not C99 */
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the most plausible velocity. That is, the most distant
|
2011-11-05 07:32:40 -06:00
|
|
|
* (in time) tracker which isn't too old, the movement vector was
|
|
|
|
* in the same octant, and where the velocity is within an
|
|
|
|
* acceptable range to the inital velocity.
|
2010-07-27 13:02:24 -06:00
|
|
|
*
|
2011-11-05 07:32:40 -06:00
|
|
|
* @return The tracker's velocity or 0 if the above conditions are unmet
|
2010-07-27 13:02:24 -06:00
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
QueryTrackers(DeviceVelocityPtr vel, int cur_t)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
int offset, dir = UNDEFINED, used_offset = -1, age_ms;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* initial velocity: a low-offset, valid velocity */
|
2012-06-10 07:21:05 -06:00
|
|
|
double initial_velocity = 0, result = 0, velocity_diff;
|
|
|
|
double velocity_factor = vel->corr_mul * vel->const_acceleration; /* premultiply */
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* loop from current to older data */
|
2012-06-10 07:21:05 -06:00
|
|
|
for (offset = 1; offset < vel->num_tracker; offset++) {
|
|
|
|
MotionTracker *tracker = TRACKER(vel, offset);
|
|
|
|
double tracker_velocity;
|
|
|
|
|
|
|
|
age_ms = cur_t - tracker->time;
|
|
|
|
|
|
|
|
/* bail out if data is too old and protect from overrun */
|
|
|
|
if (age_ms >= vel->reset_time || age_ms < 0) {
|
|
|
|
DebugAccelF("(dix prtacc) query: tracker too old\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this heuristic avoids using the linear-motion velocity formula
|
|
|
|
* in CalcTracker() on motion that isn't exactly linear. So to get
|
|
|
|
* even more precision we could subdivide as a final step, so possible
|
|
|
|
* non-linearities are accounted for.
|
|
|
|
*/
|
|
|
|
dir &= tracker->dir;
|
|
|
|
if (dir == 0) { /* we've changed octant of movement (e.g. NE → NW) */
|
|
|
|
DebugAccelF("(dix prtacc) query: no longer linear\n");
|
|
|
|
/* instead of breaking it we might also inspect the partition after,
|
|
|
|
* but actual improvement with this is probably rare. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tracker_velocity = CalcTracker(tracker, cur_t) * velocity_factor;
|
|
|
|
|
|
|
|
if ((initial_velocity == 0 || offset <= vel->initial_range) &&
|
|
|
|
tracker_velocity != 0) {
|
|
|
|
/* set initial velocity and result */
|
|
|
|
result = initial_velocity = tracker_velocity;
|
|
|
|
used_offset = offset;
|
|
|
|
}
|
|
|
|
else if (initial_velocity != 0 && tracker_velocity != 0) {
|
|
|
|
velocity_diff = fabs(initial_velocity - tracker_velocity);
|
|
|
|
|
|
|
|
if (velocity_diff > vel->max_diff &&
|
|
|
|
velocity_diff / (initial_velocity + tracker_velocity) >=
|
|
|
|
vel->max_rel_diff) {
|
|
|
|
/* we're not in range, quit - it won't get better. */
|
|
|
|
DebugAccelF("(dix prtacc) query: tracker too different:"
|
|
|
|
" old %2.2f initial %2.2f diff: %2.2f\n",
|
|
|
|
tracker_velocity, initial_velocity, velocity_diff);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* we're in range with the initial velocity,
|
|
|
|
* so this result is likely better
|
|
|
|
* (it contains more information). */
|
|
|
|
result = tracker_velocity;
|
|
|
|
used_offset = offset;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (offset == vel->num_tracker) {
|
|
|
|
DebugAccelF("(dix prtacc) query: last tracker in effect\n");
|
|
|
|
used_offset = vel->num_tracker - 1;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (used_offset >= 0) {
|
2011-11-05 07:32:40 -06:00
|
|
|
#ifdef PTRACCEL_DEBUGGING
|
2012-06-10 07:21:05 -06:00
|
|
|
MotionTracker *tracker = TRACKER(vel, used_offset);
|
|
|
|
|
|
|
|
DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n",
|
|
|
|
used_offset, tracker->dx, tracker->dy,
|
|
|
|
cur_t - tracker->time);
|
2011-11-05 07:32:40 -06:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
return result;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef TRACKER_INDEX
|
2011-11-05 07:32:40 -06:00
|
|
|
#undef TRACKER
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
|
|
|
|
* return true if non-visible state reset is suggested
|
|
|
|
*/
|
2011-11-05 07:32:40 -06:00
|
|
|
BOOL
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcessVelocityData2D(DeviceVelocityPtr vel, double dx, double dy, int time)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double velocity;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
vel->last_velocity = vel->velocity;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
FeedTrackers(vel, dx, dy, time);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
velocity = QueryTrackers(vel, time);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
vel->velocity = velocity;
|
|
|
|
return velocity == 0;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this flattens significant ( > 1) mickeys a little bit for more steady
|
|
|
|
* constant-velocity response
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static inline double
|
|
|
|
ApplySimpleSoftening(double prev_delta, double delta)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double result = delta;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (delta < -1.0 || delta > 1.0) {
|
|
|
|
if (delta > prev_delta)
|
|
|
|
result -= 0.5;
|
|
|
|
else if (delta < prev_delta)
|
|
|
|
result += 0.5;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
|
|
|
return result;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Soften the delta based on previous deltas stored in vel.
|
|
|
|
*
|
|
|
|
* @param[in,out] fdx Delta X, modified in-place.
|
|
|
|
* @param[in,out] fdx Delta Y, modified in-place.
|
|
|
|
*/
|
2009-09-06 13:44:18 -06:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
ApplySoftening(DeviceVelocityPtr vel, double *fdx, double *fdy)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
if (vel->use_softening) {
|
|
|
|
*fdx = ApplySimpleSoftening(vel->last_dx, *fdx);
|
|
|
|
*fdy = ApplySimpleSoftening(vel->last_dy, *fdy);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
ApplyConstantDeceleration(DeviceVelocityPtr vel, double *fdx, double *fdy)
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
*fdx *= vel->const_acceleration;
|
|
|
|
*fdy *= vel->const_acceleration;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compute the acceleration for given velocity and enforce min_acceleartion
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
double
|
|
|
|
BasicComputeAcceleration(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
|
|
|
{
|
|
|
|
|
|
|
|
double result;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
result = vel->Profile(dev, vel, velocity, threshold, acc);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* enforce min_acceleration */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (result < vel->min_acceleration)
|
2012-06-10 07:21:05 -06:00
|
|
|
result = vel->min_acceleration;
|
2009-09-06 13:44:18 -06:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute acceleration. Takes into account averaging, nv-reset, etc.
|
2011-11-05 07:32:40 -06:00
|
|
|
* If the velocity has changed, an average is taken of 6 velocity factors:
|
|
|
|
* current velocity, last velocity and 4 times the average between the two.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
ComputeAcceleration(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel, double threshold, double acc)
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
|
|
|
|
if (vel->velocity <= 0) {
|
|
|
|
DebugAccelF("(dix ptracc) profile skipped\n");
|
2009-09-06 13:44:18 -06:00
|
|
|
/*
|
2010-07-27 13:02:24 -06:00
|
|
|
* If we have no idea about device velocity, don't pretend it.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
return 1;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (vel->average_accel && vel->velocity != vel->last_velocity) {
|
|
|
|
/* use simpson's rule to average acceleration between
|
|
|
|
* current and previous velocity.
|
|
|
|
* Though being the more natural choice, it causes a minor delay
|
|
|
|
* in comparison, so it can be disabled. */
|
|
|
|
result =
|
|
|
|
BasicComputeAcceleration(dev, vel, vel->velocity, threshold, acc);
|
|
|
|
result +=
|
|
|
|
BasicComputeAcceleration(dev, vel, vel->last_velocity, threshold,
|
|
|
|
acc);
|
|
|
|
result +=
|
|
|
|
4.0f * BasicComputeAcceleration(dev, vel,
|
|
|
|
(vel->last_velocity +
|
|
|
|
vel->velocity) / 2, threshold,
|
|
|
|
acc);
|
|
|
|
result /= 6.0f;
|
|
|
|
DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n",
|
|
|
|
vel->velocity, vel->last_velocity, result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = BasicComputeAcceleration(dev, vel,
|
|
|
|
vel->velocity, threshold, acc);
|
|
|
|
DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
|
|
|
|
vel->velocity, res);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
return result;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************
|
|
|
|
* Acceleration functions and profiles
|
|
|
|
****************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Polynomial function similar previous one, but with f(1) = 1
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
PolynomialAccelerationProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double ignored, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
return pow(velocity, (acc - 1.0) * 0.5);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns acceleration for velocity.
|
|
|
|
* This profile selects the two functions like the old scheme did
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
ClassicProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
if (threshold > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return SimpleSmoothProfile(dev, vel, velocity, threshold, acc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PolynomialAccelerationProfile(dev, vel, velocity, 0, acc);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Power profile
|
|
|
|
* This has a completely smooth transition curve, i.e. no jumps in the
|
|
|
|
* derivatives.
|
|
|
|
*
|
|
|
|
* This has the expense of overall response dependency on min-acceleration.
|
|
|
|
* In effect, min_acceleration mimics const_acceleration in this profile.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
PowerProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double vel_dist;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
acc = (acc - 1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (velocity <= threshold)
|
2010-07-27 13:02:24 -06:00
|
|
|
return vel->min_acceleration;
|
2009-09-06 13:44:18 -06:00
|
|
|
vel_dist = velocity - threshold;
|
2010-07-27 13:02:24 -06:00
|
|
|
return (pow(acc, vel_dist)) * vel->min_acceleration;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* just a smooth function in [0..1] -> [0..1]
|
|
|
|
* - point symmetry at 0.5
|
|
|
|
* - f'(0) = f'(1) = 0
|
|
|
|
* - starts faster than a sinoid
|
|
|
|
* - smoothness C1 (Cinf if you dare to ignore endpoints)
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static inline double
|
|
|
|
CalcPenumbralGradient(double x)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
x *= 2.0f;
|
|
|
|
x -= 1.0f;
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0.5f + (x * sqrt(1.0 - x * x) + asin(x)) / M_PI;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acceleration function similar to classic accelerated/unaccelerated,
|
|
|
|
* but with smooth transition in between (and towards zero for adaptive dec.).
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
SimpleSmoothProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (velocity < 1.0f)
|
|
|
|
return CalcPenumbralGradient(0.5 + velocity * 0.5) * 2.0f - 1.0f;
|
|
|
|
if (threshold < 1.0f)
|
2009-09-06 13:44:18 -06:00
|
|
|
threshold = 1.0f;
|
|
|
|
if (velocity <= threshold)
|
|
|
|
return 1;
|
|
|
|
velocity /= threshold;
|
|
|
|
if (velocity >= acc)
|
|
|
|
return acc;
|
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
return 1.0f + (CalcPenumbralGradient(velocity / acc) * (acc - 1.0f));
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This profile uses the first half of the penumbral gradient as a start
|
|
|
|
* and then scales linearly.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
SmoothLinearProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double res, nv;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (acc > 1.0f)
|
|
|
|
acc -= 1.0f; /*this is so acc = 1 is no acceleration */
|
2009-09-06 13:44:18 -06:00
|
|
|
else
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
nv = (velocity - threshold) * acc * 0.5f;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (nv < 0) {
|
2009-09-06 13:44:18 -06:00
|
|
|
res = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (nv < 2) {
|
|
|
|
res = CalcPenumbralGradient(nv * 0.25f) * 2.0f;
|
|
|
|
}
|
|
|
|
else {
|
2009-09-06 13:44:18 -06:00
|
|
|
nv -= 2.0f;
|
|
|
|
res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */
|
2012-06-10 07:21:05 -06:00
|
|
|
+ 1.0f; /* gradient crosses 2|1 */
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
res += vel->min_acceleration;
|
2009-09-06 13:44:18 -06:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* From 0 to threshold, the response graduates smoothly from min_accel to
|
|
|
|
* acceleration. Beyond threshold it is exactly the specified acceleration.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
SmoothLimitedProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double res;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (velocity >= threshold || threshold == 0.0f)
|
|
|
|
return acc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
velocity /= threshold; /* should be [0..1[ now */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
res = CalcPenumbralGradient(velocity) * (acc - vel->min_acceleration);
|
|
|
|
|
|
|
|
return vel->min_acceleration + res;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
LinearProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel,
|
|
|
|
double velocity, double threshold, double acc)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
return acc * velocity;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static double
|
|
|
|
NoProfile(DeviceIntPtr dev,
|
|
|
|
DeviceVelocityPtr vel, double velocity, double threshold, double acc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
return 1.0f;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static PointerAccelerationProfileFunc
|
2012-06-10 07:21:05 -06:00
|
|
|
GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (profile_num) {
|
|
|
|
case AccelProfileClassic:
|
|
|
|
return ClassicProfile;
|
|
|
|
case AccelProfileDeviceSpecific:
|
|
|
|
return vel->deviceSpecificProfile;
|
|
|
|
case AccelProfilePolynomial:
|
|
|
|
return PolynomialAccelerationProfile;
|
|
|
|
case AccelProfileSmoothLinear:
|
|
|
|
return SmoothLinearProfile;
|
|
|
|
case AccelProfileSimple:
|
|
|
|
return SimpleSmoothProfile;
|
|
|
|
case AccelProfilePower:
|
|
|
|
return PowerProfile;
|
|
|
|
case AccelProfileLinear:
|
|
|
|
return LinearProfile;
|
|
|
|
case AccelProfileSmoothLimited:
|
|
|
|
return SmoothLimitedProfile;
|
|
|
|
case AccelProfileNone:
|
|
|
|
return NoProfile;
|
|
|
|
default:
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the profile by number.
|
|
|
|
* Intended to make profiles exchangeable at runtime.
|
|
|
|
* If you created a profile, give it a number here and in the header to
|
|
|
|
* make it selectable. In case some profile-specific init is needed, here
|
|
|
|
* would be a good place, since FreeVelocityData() also calls this with
|
|
|
|
* PROFILE_UNINITIALIZE.
|
|
|
|
*
|
|
|
|
* returns FALSE if profile number is unavailable, TRUE otherwise.
|
|
|
|
*/
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
PointerAccelerationProfileFunc profile;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
profile = GetAccelerationProfile(vel, profile_num);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (profile == NULL && profile_num != PROFILE_UNINITIALIZE)
|
|
|
|
return FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/* Here one could free old profile-private data */
|
|
|
|
free(vel->profile_private);
|
|
|
|
vel->profile_private = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Here one could init profile-private data */
|
2010-07-27 13:02:24 -06:00
|
|
|
vel->Profile = profile;
|
|
|
|
vel->statistics.profile_number = profile_num;
|
2009-09-06 13:44:18 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************
|
|
|
|
* driver interaction
|
|
|
|
**********************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* device-specific profile
|
|
|
|
*
|
|
|
|
* The device-specific profile is intended as a hook for a driver
|
|
|
|
* which may want to provide an own acceleration profile.
|
|
|
|
* It should not rely on profile-private data, instead
|
|
|
|
* it should do init/uninit in the driver (ie. with DEVICE_INIT and friends).
|
|
|
|
* Users may override or choose it.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
|
|
|
|
PointerAccelerationProfileFunc profile)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (vel)
|
|
|
|
vel->deviceSpecificProfile = profile;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this function to obtain a DeviceVelocityPtr for a device. Will return NULL if
|
|
|
|
* the predictable acceleration scheme is not in effect.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceVelocityPtr
|
2012-06-10 07:21:05 -06:00
|
|
|
GetDevicePredictableAccelData(DeviceIntPtr dev)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
/*sanity check */
|
|
|
|
if (!dev) {
|
|
|
|
ErrorF("[dix] accel: DeviceIntPtr was NULL");
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dev->valuator &&
|
|
|
|
dev->valuator->accelScheme.AccelSchemeProc ==
|
|
|
|
acceleratePointerPredictable &&
|
|
|
|
dev->valuator->accelScheme.accelData != NULL) {
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return ((PredictableAccelSchemePtr)
|
|
|
|
dev->valuator->accelScheme.accelData)->vel;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************
|
|
|
|
* acceleration schemes
|
|
|
|
*******************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifies valuators in-place.
|
|
|
|
* This version employs a velocity approximation algorithm to
|
|
|
|
* enable fine-grained predictable acceleration profiles.
|
|
|
|
*/
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
acceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask *val, CARD32 evtime)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double dx = 0, dy = 0;
|
2011-11-05 07:32:40 -06:00
|
|
|
DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool soften = TRUE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (valuator_mask_num_valuators(val) == 0 || !velocitydata)
|
2009-09-06 13:44:18 -06:00
|
|
|
return;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (velocitydata->statistics.profile_number == AccelProfileNone &&
|
2011-11-05 07:32:40 -06:00
|
|
|
velocitydata->const_acceleration == 1.0f) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return; /*we're inactive anyway, so skip the whole thing. */
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (valuator_mask_isset(val, 0)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
dx = valuator_mask_get_double(val, 0);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
if (valuator_mask_isset(val, 1)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
dy = valuator_mask_get_double(val, 1);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dx != 0.0 || dy != 0.0) {
|
2010-07-27 13:02:24 -06:00
|
|
|
/* reset non-visible state? */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ProcessVelocityData2D(velocitydata, dx, dy, evtime)) {
|
2010-07-27 13:02:24 -06:00
|
|
|
soften = FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
|
2012-06-10 07:21:05 -06:00
|
|
|
double mult;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* invoke acceleration profile to determine acceleration */
|
2012-06-10 07:21:05 -06:00
|
|
|
mult = ComputeAcceleration(dev, velocitydata,
|
|
|
|
dev->ptrfeed->ctrl.threshold,
|
|
|
|
(double) dev->ptrfeed->ctrl.num /
|
|
|
|
(double) dev->ptrfeed->ctrl.den);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if (mult > 1.0f && soften)
|
2012-06-10 07:21:05 -06:00
|
|
|
ApplySoftening(velocitydata, &dx, &dy);
|
|
|
|
ApplyConstantDeceleration(velocitydata, &dx, &dy);
|
|
|
|
|
|
|
|
if (dx != 0.0)
|
|
|
|
valuator_mask_set_double(val, 0, mult * dx);
|
|
|
|
if (dy != 0.0)
|
|
|
|
valuator_mask_set_double(val, 1, mult * dy);
|
|
|
|
DebugAccelF("pos (%i | %i) delta x:%.3f y:%.3f\n", mult * dx,
|
|
|
|
mult * dy);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* remember last motion delta (for softening/slow movement treatment) */
|
|
|
|
velocitydata->last_dx = dx;
|
|
|
|
velocitydata->last_dy = dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Originally a part of xf86PostMotionEvent; modifies valuators
|
|
|
|
* in-place. Retained mostly for embedded scenarios.
|
|
|
|
*/
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
acceleratePointerLightweight(DeviceIntPtr dev,
|
|
|
|
ValuatorMask *val, CARD32 ignored)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
double mult = 0.0, tmpf;
|
|
|
|
double dx = 0.0, dy = 0.0;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (valuator_mask_isset(val, 0)) {
|
|
|
|
dx = valuator_mask_get(val, 0);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
if (valuator_mask_isset(val, 1)) {
|
|
|
|
dy = valuator_mask_get(val, 1);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (valuator_mask_num_valuators(val) == 0)
|
2009-09-06 13:44:18 -06:00
|
|
|
return;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
|
2009-09-06 13:44:18 -06:00
|
|
|
/* modeled from xf86Events.c */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (dev->ptrfeed->ctrl.threshold) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((fabs(dx) + fabs(dy)) >= dev->ptrfeed->ctrl.threshold) {
|
|
|
|
if (dx != 0.0) {
|
|
|
|
tmpf = (dx * (double) (dev->ptrfeed->ctrl.num)) /
|
|
|
|
(double) (dev->ptrfeed->ctrl.den);
|
|
|
|
valuator_mask_set_double(val, 0, tmpf);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dy != 0.0) {
|
|
|
|
tmpf = (dy * (double) (dev->ptrfeed->ctrl.num)) /
|
|
|
|
(double) (dev->ptrfeed->ctrl.den);
|
|
|
|
valuator_mask_set_double(val, 1, tmpf);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
mult = pow(dx * dx + dy * dy,
|
|
|
|
((double) (dev->ptrfeed->ctrl.num) /
|
|
|
|
(double) (dev->ptrfeed->ctrl.den) - 1.0) / 2.0) / 2.0;
|
|
|
|
if (dx != 0.0)
|
|
|
|
valuator_mask_set_double(val, 0, mult * dx);
|
|
|
|
if (dy != 0.0)
|
|
|
|
valuator_mask_set_double(val, 1, mult * dy);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|