ptrveloc.h revision 6747b715
14642e01fSmrg/*
24642e01fSmrg *
36747b715Smrg * Copyright © 2006-2009 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
284642e01fSmrg#include <input.h> /* DeviceIntPtr */
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 */
504642e01fSmrgtypedef float (*PointerAccelerationProfileFunc)
516747b715Smrg              (DeviceIntPtr dev, struct _DeviceVelocityRec* vel,
526747b715Smrg               float velocity, float threshold, float 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 {
606747b715Smrg    int dx, dy;     /* accumulated delta for each axis */
616747b715Smrg    int time;         /* time of creation */
626747b715Smrg    int dir;        /* initial direction bitfield */
636747b715Smrg} MotionTracker, *MotionTrackerPtr;
646747b715Smrg
656747b715Smrg/* number of properties for predictable acceleration */
666747b715Smrg#define NPROPS_PREDICTABLE_ACCEL 4
674642e01fSmrg
684642e01fSmrg/**
694642e01fSmrg * Contains all data needed to implement mouse ballistics
704642e01fSmrg */
714642e01fSmrgtypedef struct _DeviceVelocityRec {
726747b715Smrg    MotionTrackerPtr tracker;
736747b715Smrg    int num_tracker;
746747b715Smrg    int cur_tracker;        /* current index */
754642e01fSmrg    float   velocity;       /* velocity as guessed by algorithm */
764642e01fSmrg    float   last_velocity;  /* previous velocity estimate */
776747b715Smrg    int     last_dx;      /* last time-difference */
786747b715Smrg    int     last_dy ;     /* phase of last/current estimate */
794642e01fSmrg    float   corr_mul;       /* config: multiply this into velocity */
804642e01fSmrg    float   const_acceleration;  /* config: (recipr.) const deceleration */
814642e01fSmrg    float   min_acceleration;    /* config: minimum acceleration */
824642e01fSmrg    short   reset_time;     /* config: reset non-visible state after # ms */
834642e01fSmrg    short   use_softening;  /* config: use softening of mouse values */
846747b715Smrg    float   max_rel_diff;   /* config: max. relative difference */
856747b715Smrg    float   max_diff;       /* config: max. difference */
866747b715Smrg    int     initial_range;  /* config: max. offset used as initial velocity */
874642e01fSmrg    Bool    average_accel;  /* config: average acceleration over velocity */
884642e01fSmrg    PointerAccelerationProfileFunc Profile;
894642e01fSmrg    PointerAccelerationProfileFunc deviceSpecificProfile;
904642e01fSmrg    void*   profile_private;/* extended data, see  SetAccelerationProfile() */
914642e01fSmrg    struct {   /* to be able to query this information */
924642e01fSmrg        int     profile_number;
934642e01fSmrg    } statistics;
946747b715Smrg    long    prop_handlers[NPROPS_PREDICTABLE_ACCEL];
954642e01fSmrg} DeviceVelocityRec, *DeviceVelocityPtr;
964642e01fSmrg
976747b715Smrgextern _X_EXPORT void
986747b715SmrgInitVelocityData(DeviceVelocityPtr vel);
996747b715Smrg
1006747b715Smrgextern _X_EXPORT void
1016747b715SmrgInitTrackers(DeviceVelocityPtr vel, int ntracker);
1026747b715Smrg
1036747b715Smrgextern _X_EXPORT short
1046747b715SmrgProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
1056747b715Smrg
1066747b715Smrgextern _X_EXPORT float
1076747b715SmrgBasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
1086747b715Smrg    float velocity, float threshold, float acc);
1096747b715Smrg
1106747b715Smrgextern _X_EXPORT void
1116747b715SmrgFreeVelocityData(DeviceVelocityPtr vel);
1124642e01fSmrg
1136747b715Smrgextern _X_INTERNAL BOOL
1146747b715SmrgInitializePredictableAccelerationProperties(DeviceIntPtr dev);
1154642e01fSmrg
1166747b715Smrgextern _X_INTERNAL BOOL
1176747b715SmrgDeletePredictableAccelerationProperties(DeviceIntPtr dev);
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
1326747b715Smrgextern _X_INTERNAL void
1336747b715SmrgacceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
1344642e01fSmrg                             int num_valuators, int *valuators, int evtime);
1354642e01fSmrg
1366747b715Smrgextern _X_INTERNAL void
1376747b715SmrgacceleratePointerLightweight(DeviceIntPtr dev, int first_valuator,
1386747b715Smrg                             int num_valuators, int *valuators, int ignored);
1394642e01fSmrg
1404642e01fSmrg#endif  /* POINTERVELOCITY_H */
141