ptrveloc.h 4.17 KB
Newer Older
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * Copyright © 2006-2008 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"),
 * 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.
 */
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

#ifndef POINTERVELOCITY_H
#define POINTERVELOCITY_H

#include <input.h> /* DeviceIntPtr */

#define MAX_VELOCITY_FILTERS 8

struct _DeviceVelocityRec;

/**
 * profile
 * returns actual acceleration depending on velocity, acceleration control,...
 */
typedef float (*PointerAccelerationProfileFunc)
              (struct _DeviceVelocityRec* /*pVel*/,
               float /*threshold*/, float /*acc*/);

/**
 * a filter stage contains the data for the adaptive IIR filtering.
 * To improve results, one may run several parallel filters
 * which have different decays. Since more integration means more
 * delay, a given filter only does good matches in a specific phase of
 * a stroke.
 *
 * Basically, the coupling feature makes one filter fairly enough,
 * so that is the default.
 */
typedef struct _FilterStage {
    float*  fading_lut;     /* lookup for adaptive IIR filter */
    int     fading_lut_size; /* size of lookup table */
    float   rdecay;     /* reciprocal weighting halflife in ms */
    float   current;
} FilterStage, *FilterStagePtr;

/**
 * Contains all data needed to implement mouse ballistics
 */
typedef struct _DeviceVelocityRec {
    FilterStage filters[MAX_VELOCITY_FILTERS];
    float   velocity;       /* velocity as guessed by algorithm */
    int     lrm_time;       /* time the last motion event was processed  */
    int     last_dx, last_dy; /* last motion delta */
    int     last_diff;      /* last time-diff */
    float   corr_mul;       /* config: multiply this into velocity */
    float   const_acceleration;  /* config: (recipr.) const deceleration */
    float   min_acceleration;    /* config: minimum acceleration */
    short   reset_time;     /* config: reset non-visible state after # ms */
    short   use_softening;  /* config: use softening of mouse values */
    float   coupling;       /* config: max. divergence before coupling */
    PointerAccelerationProfileFunc Profile;
    PointerAccelerationProfileFunc deviceSpecificProfile;
    void*   profile_private;/* extended data, see  SetAccelerationProfile() */
    struct {   /* to be able to query this information */
        int     profile_number;
        int     filter_usecount[MAX_VELOCITY_FILTERS];
    } statistics;
} DeviceVelocityRec, *DeviceVelocityPtr;


extern void
InitVelocityData(DeviceVelocityPtr s);

extern void
InitFilterChain(DeviceVelocityPtr s, float rdecay, float degression,
                int lutsize, int stages);

extern int
SetAccelerationProfile(DeviceVelocityPtr s, int profile_num);

extern void
SetDeviceSpecificAccelerationProfile(DeviceIntPtr s,
                                     PointerAccelerationProfileFunc profile);

extern void
AccelerationDefaultCleanup(DeviceIntPtr pDev);

extern void
acceleratePointerPredictable(DeviceIntPtr pDev, int first_valuator,
                             int num_valuators, int *valuators, int evtime);

extern void
acceleratePointerClassic(DeviceIntPtr pDev, int first_valuator,
                         int num_valuators, int *valuators, int ignore);

#endif  /* POINTERVELOCITY_H */