xref: /OK3568_Linux_fs/external/xserver/include/ptrveloc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright © 2006-2011 Simon Thum             simon dot thum at gmx dot de
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
10*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
13*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
14*4882a593Smuzhiyun  * Software.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19*4882a593Smuzhiyun  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*4882a593Smuzhiyun  * DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #ifndef POINTERVELOCITY_H
26*4882a593Smuzhiyun #define POINTERVELOCITY_H
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include <input.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* constants for acceleration profiles */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #define AccelProfileNone -1
33*4882a593Smuzhiyun #define AccelProfileClassic  0
34*4882a593Smuzhiyun #define AccelProfileDeviceSpecific 1
35*4882a593Smuzhiyun #define AccelProfilePolynomial 2
36*4882a593Smuzhiyun #define AccelProfileSmoothLinear 3
37*4882a593Smuzhiyun #define AccelProfileSimple 4
38*4882a593Smuzhiyun #define AccelProfilePower 5
39*4882a593Smuzhiyun #define AccelProfileLinear 6
40*4882a593Smuzhiyun #define AccelProfileSmoothLimited 7
41*4882a593Smuzhiyun #define AccelProfileLAST AccelProfileSmoothLimited
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* fwd */
44*4882a593Smuzhiyun struct _DeviceVelocityRec;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun  * profile
48*4882a593Smuzhiyun  * returns actual acceleration depending on velocity, acceleration control,...
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun typedef double (*PointerAccelerationProfileFunc)
51*4882a593Smuzhiyun  (DeviceIntPtr dev, struct _DeviceVelocityRec * vel,
52*4882a593Smuzhiyun   double velocity, double threshold, double accelCoeff);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /**
55*4882a593Smuzhiyun  * a motion history, with just enough information to
56*4882a593Smuzhiyun  * calc mean velocity and decide which motion was along
57*4882a593Smuzhiyun  * a more or less straight line
58*4882a593Smuzhiyun  */
59*4882a593Smuzhiyun typedef struct _MotionTracker {
60*4882a593Smuzhiyun     double dx, dy;              /* accumulated delta for each axis */
61*4882a593Smuzhiyun     int time;                   /* time of creation */
62*4882a593Smuzhiyun     int dir;                    /* initial direction bitfield */
63*4882a593Smuzhiyun } MotionTracker, *MotionTrackerPtr;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /**
66*4882a593Smuzhiyun  * Contains all data needed to implement mouse ballistics
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun typedef struct _DeviceVelocityRec {
69*4882a593Smuzhiyun     MotionTrackerPtr tracker;
70*4882a593Smuzhiyun     int num_tracker;
71*4882a593Smuzhiyun     int cur_tracker;            /* current index */
72*4882a593Smuzhiyun     double velocity;            /* velocity as guessed by algorithm */
73*4882a593Smuzhiyun     double last_velocity;       /* previous velocity estimate */
74*4882a593Smuzhiyun     double last_dx;             /* last time-difference */
75*4882a593Smuzhiyun     double last_dy;             /* phase of last/current estimate */
76*4882a593Smuzhiyun     double corr_mul;            /* config: multiply this into velocity */
77*4882a593Smuzhiyun     double const_acceleration;  /* config: (recipr.) const deceleration */
78*4882a593Smuzhiyun     double min_acceleration;    /* config: minimum acceleration */
79*4882a593Smuzhiyun     short reset_time;           /* config: reset non-visible state after # ms */
80*4882a593Smuzhiyun     short use_softening;        /* config: use softening of mouse values */
81*4882a593Smuzhiyun     double max_rel_diff;        /* config: max. relative difference */
82*4882a593Smuzhiyun     double max_diff;            /* config: max. difference */
83*4882a593Smuzhiyun     int initial_range;          /* config: max. offset used as initial velocity */
84*4882a593Smuzhiyun     Bool average_accel;         /* config: average acceleration over velocity */
85*4882a593Smuzhiyun     PointerAccelerationProfileFunc Profile;
86*4882a593Smuzhiyun     PointerAccelerationProfileFunc deviceSpecificProfile;
87*4882a593Smuzhiyun     void *profile_private;      /* extended data, see  SetAccelerationProfile() */
88*4882a593Smuzhiyun     struct {                    /* to be able to query this information */
89*4882a593Smuzhiyun         int profile_number;
90*4882a593Smuzhiyun     } statistics;
91*4882a593Smuzhiyun } DeviceVelocityRec, *DeviceVelocityPtr;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun  * contains the run-time data for the predictable scheme, that is, a
95*4882a593Smuzhiyun  * DeviceVelocityPtr and the property handlers.
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun typedef struct _PredictableAccelSchemeRec {
98*4882a593Smuzhiyun     DeviceVelocityPtr vel;
99*4882a593Smuzhiyun     long *prop_handlers;
100*4882a593Smuzhiyun     int num_prop_handlers;
101*4882a593Smuzhiyun } PredictableAccelSchemeRec, *PredictableAccelSchemePtr;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun extern _X_EXPORT void
104*4882a593Smuzhiyun InitVelocityData(DeviceVelocityPtr vel);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun extern _X_EXPORT void
107*4882a593Smuzhiyun InitTrackers(DeviceVelocityPtr vel, int ntracker);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun extern _X_EXPORT BOOL
110*4882a593Smuzhiyun ProcessVelocityData2D(DeviceVelocityPtr vel, double dx, double dy, int time);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun extern _X_EXPORT double
113*4882a593Smuzhiyun BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
114*4882a593Smuzhiyun                          double velocity, double threshold, double acc);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun extern _X_EXPORT void
117*4882a593Smuzhiyun FreeVelocityData(DeviceVelocityPtr vel);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun extern _X_EXPORT int
120*4882a593Smuzhiyun SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun extern _X_EXPORT DeviceVelocityPtr
123*4882a593Smuzhiyun GetDevicePredictableAccelData(DeviceIntPtr dev);
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun extern _X_EXPORT void
126*4882a593Smuzhiyun SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
127*4882a593Smuzhiyun                                      PointerAccelerationProfileFunc profile);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun extern _X_INTERNAL void
130*4882a593Smuzhiyun AccelerationDefaultCleanup(DeviceIntPtr dev);
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun extern _X_INTERNAL Bool
133*4882a593Smuzhiyun InitPredictableAccelerationScheme(DeviceIntPtr dev,
134*4882a593Smuzhiyun                                   struct _ValuatorAccelerationRec *protoScheme);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun extern _X_INTERNAL void
137*4882a593Smuzhiyun acceleratePointerPredictable(DeviceIntPtr dev, ValuatorMask *val,
138*4882a593Smuzhiyun                              CARD32 evtime);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun extern _X_INTERNAL void
141*4882a593Smuzhiyun acceleratePointerLightweight(DeviceIntPtr dev, ValuatorMask *val,
142*4882a593Smuzhiyun                              CARD32 evtime);
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #endif                          /* POINTERVELOCITY_H */
145