14642e01fSmrg/* 24642e01fSmrg * 335c4bbdfSmrg * Copyright © 2006-2011 Simon Thum simon dot thum at gmx dot de 44642e01fSmrg * 54642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 64642e01fSmrg * copy of this software and associated documentation files (the "Software"), 74642e01fSmrg * to deal in the Software without restriction, including without limitation 84642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 94642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the 104642e01fSmrg * Software is furnished to do so, subject to the following conditions: 114642e01fSmrg * 124642e01fSmrg * The above copyright notice and this permission notice (including the next 134642e01fSmrg * paragraph) shall be included in all copies or substantial portions of the 144642e01fSmrg * Software. 154642e01fSmrg * 164642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 174642e01fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 184642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 194642e01fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 204642e01fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 214642e01fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 224642e01fSmrg * DEALINGS IN THE SOFTWARE. 234642e01fSmrg */ 244642e01fSmrg 254642e01fSmrg#ifndef POINTERVELOCITY_H 264642e01fSmrg#define POINTERVELOCITY_H 274642e01fSmrg 2835c4bbdfSmrg#include <input.h> 294642e01fSmrg 306747b715Smrg/* constants for acceleration profiles */ 314642e01fSmrg 326747b715Smrg#define AccelProfileNone -1 334642e01fSmrg#define AccelProfileClassic 0 344642e01fSmrg#define AccelProfileDeviceSpecific 1 354642e01fSmrg#define AccelProfilePolynomial 2 364642e01fSmrg#define AccelProfileSmoothLinear 3 374642e01fSmrg#define AccelProfileSimple 4 384642e01fSmrg#define AccelProfilePower 5 394642e01fSmrg#define AccelProfileLinear 6 406747b715Smrg#define AccelProfileSmoothLimited 7 416747b715Smrg#define AccelProfileLAST AccelProfileSmoothLimited 424642e01fSmrg 434642e01fSmrg/* fwd */ 444642e01fSmrgstruct _DeviceVelocityRec; 454642e01fSmrg 464642e01fSmrg/** 474642e01fSmrg * profile 484642e01fSmrg * returns actual acceleration depending on velocity, acceleration control,... 494642e01fSmrg */ 5035c4bbdfSmrgtypedef double (*PointerAccelerationProfileFunc) 5135c4bbdfSmrg (DeviceIntPtr dev, struct _DeviceVelocityRec * vel, 5235c4bbdfSmrg double velocity, double threshold, double accelCoeff); 534642e01fSmrg 544642e01fSmrg/** 556747b715Smrg * a motion history, with just enough information to 566747b715Smrg * calc mean velocity and decide which motion was along 576747b715Smrg * a more or less straight line 584642e01fSmrg */ 596747b715Smrgtypedef struct _MotionTracker { 6035c4bbdfSmrg double dx, dy; /* accumulated delta for each axis */ 6135c4bbdfSmrg int time; /* time of creation */ 6235c4bbdfSmrg int dir; /* initial direction bitfield */ 636747b715Smrg} MotionTracker, *MotionTrackerPtr; 646747b715Smrg 654642e01fSmrg/** 664642e01fSmrg * Contains all data needed to implement mouse ballistics 674642e01fSmrg */ 684642e01fSmrgtypedef struct _DeviceVelocityRec { 696747b715Smrg MotionTrackerPtr tracker; 706747b715Smrg int num_tracker; 7135c4bbdfSmrg int cur_tracker; /* current index */ 7235c4bbdfSmrg double velocity; /* velocity as guessed by algorithm */ 7335c4bbdfSmrg double last_velocity; /* previous velocity estimate */ 7435c4bbdfSmrg double last_dx; /* last time-difference */ 7535c4bbdfSmrg double last_dy; /* phase of last/current estimate */ 7635c4bbdfSmrg double corr_mul; /* config: multiply this into velocity */ 7735c4bbdfSmrg double const_acceleration; /* config: (recipr.) const deceleration */ 7835c4bbdfSmrg double min_acceleration; /* config: minimum acceleration */ 7935c4bbdfSmrg short reset_time; /* config: reset non-visible state after # ms */ 8035c4bbdfSmrg short use_softening; /* config: use softening of mouse values */ 8135c4bbdfSmrg double max_rel_diff; /* config: max. relative difference */ 8235c4bbdfSmrg double max_diff; /* config: max. difference */ 8335c4bbdfSmrg int initial_range; /* config: max. offset used as initial velocity */ 8435c4bbdfSmrg Bool average_accel; /* config: average acceleration over velocity */ 854642e01fSmrg PointerAccelerationProfileFunc Profile; 864642e01fSmrg PointerAccelerationProfileFunc deviceSpecificProfile; 8735c4bbdfSmrg void *profile_private; /* extended data, see SetAccelerationProfile() */ 8835c4bbdfSmrg struct { /* to be able to query this information */ 8935c4bbdfSmrg int profile_number; 904642e01fSmrg } statistics; 914642e01fSmrg} DeviceVelocityRec, *DeviceVelocityPtr; 924642e01fSmrg 9335c4bbdfSmrg/** 9435c4bbdfSmrg * contains the run-time data for the predictable scheme, that is, a 9535c4bbdfSmrg * DeviceVelocityPtr and the property handlers. 9635c4bbdfSmrg */ 9735c4bbdfSmrgtypedef struct _PredictableAccelSchemeRec { 9835c4bbdfSmrg DeviceVelocityPtr vel; 9935c4bbdfSmrg long *prop_handlers; 10035c4bbdfSmrg int num_prop_handlers; 10135c4bbdfSmrg} PredictableAccelSchemeRec, *PredictableAccelSchemePtr; 10235c4bbdfSmrg 1036747b715Smrgextern _X_EXPORT void 1046747b715SmrgInitVelocityData(DeviceVelocityPtr vel); 1056747b715Smrg 1066747b715Smrgextern _X_EXPORT void 1076747b715SmrgInitTrackers(DeviceVelocityPtr vel, int ntracker); 1086747b715Smrg 10935c4bbdfSmrgextern _X_EXPORT BOOL 11035c4bbdfSmrgProcessVelocityData2D(DeviceVelocityPtr vel, double dx, double dy, int time); 1116747b715Smrg 11235c4bbdfSmrgextern _X_EXPORT double 1136747b715SmrgBasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel, 11435c4bbdfSmrg double velocity, double threshold, double acc); 1156747b715Smrg 1166747b715Smrgextern _X_EXPORT void 1176747b715SmrgFreeVelocityData(DeviceVelocityPtr vel); 1184642e01fSmrg 1196747b715Smrgextern _X_EXPORT int 1206747b715SmrgSetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); 1214642e01fSmrg 1226747b715Smrgextern _X_EXPORT DeviceVelocityPtr 1236747b715SmrgGetDevicePredictableAccelData(DeviceIntPtr dev); 1244642e01fSmrg 1256747b715Smrgextern _X_EXPORT void 1266747b715SmrgSetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel, 1274642e01fSmrg PointerAccelerationProfileFunc profile); 1284642e01fSmrg 1296747b715Smrgextern _X_INTERNAL void 1306747b715SmrgAccelerationDefaultCleanup(DeviceIntPtr dev); 1314642e01fSmrg 13235c4bbdfSmrgextern _X_INTERNAL Bool 13335c4bbdfSmrgInitPredictableAccelerationScheme(DeviceIntPtr dev, 13435c4bbdfSmrg struct _ValuatorAccelerationRec *protoScheme); 13535c4bbdfSmrg 1366747b715Smrgextern _X_INTERNAL void 13735c4bbdfSmrgacceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask *val, 13835c4bbdfSmrg CARD32 evtime); 1394642e01fSmrg 1406747b715Smrgextern _X_INTERNAL void 14135c4bbdfSmrgacceleratePointerLightweight(DeviceIntPtr dev, ValuatorMask *val, 14235c4bbdfSmrg CARD32 evtime); 1434642e01fSmrg 14435c4bbdfSmrg#endif /* POINTERVELOCITY_H */ 145