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