X.org mouse acceleration proposal Author: Simon Thum (simon [dot] thum [at] gmx de) Date: 09/2006 Intent - improve heavy-load behaviour (no jumping) - enable accuracy with every device - provide a better 'feel' for X pointing devices Postulate or How to provide a better mouse feeling for the user? It is presumed that the most critical part is doing a sophisticated guess on the velocity of the device in a user's hand, as this is the reference the user's brain has to build its own knowledge about the applied translation from mouse to screen. Because this is an intuitive process, easing it just 'feels better'. Velocity is a physical quantity usually measured in m/s. This is what is accessible to our nerves and brains, delivering the data for intuition. Acceleration therefore needs to depend on velocity, which we try to deduct from the measurements the device provides us. Current problems adressed 1) Current acceleration code devises velocity (and thus acceleration) directly from device data at any given instant. This makes it vunerable to precision problems, such as a 'jumpy' mouse. 2) If a system is under load, a device may accumulate its movement delta while the system does not query the device, causing irrational high cursor movement in case of polynomial acceleration (threshold = 0, acc > 1) because velocity is guessed in an oversimplified fashion, resulting in exaggerated acceleration. 3) Some people have overly responsive devices, creating a need to reduce speed on precise tasks or in general. Current implementation will discard precision if pushed there (threshold = 1, acc < 1, fixed in git). This workaround also makes pointer acceleration impossible. These problems result in a reduced ability for our intuition to predict a correct hand movement for desired screen movement, causing more correctional moves than neccessary. Put simply, the mouse 'feels bad'. Method First, a better guess on velocity is done. Given available data, we calc dots per millisecond. This is quite intractable in integers, so we multiply by a configurable factor to arrive at values the usual X controls, treshold and acceleration, can be applied with some sense. This velocity is then weighted with an exponentially dropping profile, i.e. the longer a movement signal is back in time, the less influence it has on the current guess (This is actually much cheaper in CPU terms than it sounds). Typically during begin and end of a mouse stroke, weighting is not approriate. Therefore, a coupling is employed to use current velocity if weighting is inapproriate. After some short inactivity time, such background data is reset (called non-visible state (reset) in the patch). Second, the velocity guess is fed into an acceleration profile. The profiles are made steady (over velocity) to enhance intuitivity furter. Third, reported values are slightly flattened (just below mouse precision and only if acceleration is actually performed) to improve evolving-speed movements such as painting w/mouse typically requires. This can be independently turned off (Softening). Fourth, for too responsive devices, two methods are available (together if desired): 1) a constant deceleration can be applied 2) acceleration profile(s) can be allowed to decelerate on slow movements (adaptive deceleration) Benefits Mostly, the polynomial acceleration becomes more usable. It can be used with higher acceleration coefficients (x > 2), still providing enough control. But also the classic acceleration should become less jumpy since it now graduates (rather) soft towards accelerated motion. Users with too precise devices can slow them without loosing precision, independent of hw driver support. Even more important, an acceleration profile may decelerate on slow movements, giving (sub)pixel precision without sacrificing on pointer speed. The code is more robust towards different devices: One could imagine a mouse reporting very often, but only 1 dot per event. Old code would not accelerate such a device at all. While this is a theoretical case, there is robustness against jitter in device event frequency, as could be caused by system load. By introducing a coefficient in xorg.conf you can make two attached devices feel similar, as is often the case on laptops. (untested) Users disliking all this can switch it off, retaining constant deceleration if desired. Configuration The defaults should suffice if you had no problems before, and feel quite similar. The settings discussed here are the coarse and the very subtle settings, not the usual xset or GUI panel controls you might know. However, setting treshold to 0 is strongly recommended, to use the more intuitive polynomial acceleration. Acceleration should be about 1.5 to 2.5 then. The settings described below are device-specific and need to be set in the approriate "InputDevice" section in xorg.conf (or what your X reads). Usually it looks like: Section "InputDevice" Identifier "Mouse0" Driver "mouse" [...] EndSection For example to enable the adaptive deceleration feature, put in a line reading Option "AdaptiveDeceleration" "2" or similar. A few tips If you have a feeling your mouse moves far too fast, ConstantDeceleration is your friend. Set to 2 or higher to divide speed accordingly. This will not discard precision (at least only on nv-reset, see Method or below). If you like the speed but need some more control at pixel-level, you should set AdaptiveDeceleration to 2 or more. This allows to decelerate slow movements down to the given factor. You might want to keep nv-resets away by setting VelocityReset to e.g. 300 ms, and maybe tweak VelocityScalePerCent to give good results. If you are picky about a smooth kick-in of acceleration, for example to ease doing art, I suggest tweaking VelocityScalePerCent and using adaptive deceleration. Maybe increasing velocity coupling to 30-50% also helps it. Settings AdaptiveDeceleration [integer] Allows acceleration profile to actually decelerate the pointer, resulting in enhanced precision on slow moves. Default is 1, which deactivates adaptive deceleration. Setting 2 or higher allows for respective deceleration. Adaptive deceleration should not affect your normal mouse useage; if it does, VelocityScalePerCent is probably too low. ConstantDeceleration [integer] Constantly decelerates the mouse by given factor. Default is 1 (no deceleration). VelocityScalePerCent [integer] In short, this controls sensitivity of acceleration. It is designed to be device-dependent, i.e. you set it once to match your device, then modify behaviour using the classical controls. It is important to note there is no 'right' factor, only one that bears the nice property of matching to X controls as if velocity guessing was disabled. This factor is given in Percent, so multiply by 100 first. Rationale: Device deltas are being divided by delta milliseconds before being weighted, so they are about 10 times too small compared to a device reporting every 10 ms. Because the reporting rate is usually unknown in advance, this is the only way to scale up to 'normal' values as well as identify slow movement. Default is 1000, or 10x, which is suitable for devices reporting at 100hz maximum. If your mouse reports x times per second, set to (100000/x). WeightingDecay [integer] Default 15 milliseconds. Tweaks the weighting applied to approximate velocity. Higher values exhibit more integrating behaviour, introducing some lag but also may feel smoother. Lesser is more responsive, but less smooth. However, any lag will only show up if velocity coupling is disabled or too weak. VelocityReset [integer] Specifies after how many milliseconds of inactivity non-visible state (i.e. background info not reflected by pointer position) is discarded. This affects two issues: 1) Velocity guesing remains correct within this time if the pointer/X is stuck for a short moment, not querying the pointer device. 2) slow movements are guessed correctly if all device movement events are inside this time from each other. An increment might be neccessary to fully take advantage of adaptive deceleration. Default 200 ms. VelocityCouplingPerCent [integer] Specifies coupling, a feature ensuring responsivity by determining if the weighted guess is a valid one. Weighted guess is deemed valid if it differs from current either below 1.0 (hardcoded) or below this percentage. 0 disables, so only weighted velocity is used. This may exhibit some lag, depending on WeightingDecay. Higher setting means it is more likely that weighted velocity is taken into account. Default is 25%. Softening [boolean] Tweaks motion deltas from device before applying acceleration a bit to smooth rather constant moves. Tweaking is always below device precision to make sure it doesn't get in the way. Also, when ConstantDeceleration is used, Softening is not enabled by default because this already provides some subpixel precision. However you can set this "off" or "false" if you don't like it. VelocityGuessing [boolean] Setting this to "off" retains the simpler, old-fashioned algorithm for determining velocity. It doesn't behave exactly like the old algorithm but similar enough most people wouldn't note a difference. Acceleration profiles The simple acceleration profile (threshold > 0) is now steady, and the polynomial has f(1) = 1. They are designed to mimic previous behaviour. Simply copying old functions would not provide much benefit: The patch would simply make the point when acceleration is performed be more predictable, but not cause the pointer to cease jumping around that point. If you like to play with the profiles, a few nice properties: 1) f(1) = 1 a fixed point, to enable exchanging profiles 2) continuous nice-to-have since we would otherwise throw away our data (probably causing jumps) 3) continuous over derivative(s) nice to have for smoothness 4) f'(min_acceleration) = 0 Ensures a soft kick-in of acceleration 5) f( < 1) < 1 enables adaptive deceleration Although it is possible to hold all of them, included profiles only hold 1, 2, and 5. Profiles are not meant to enforce constant deceleration or adaptive deceleration. Problems / Todo I am not an experienced X dev, so some points are left. More complex algorithms have more knobs, and currently they can only be set in the server config. If you have suitable values however, change should only be needed when the device changes. Better would be access via xset and/or API. However, even removing the PerCent in VelocityScalePerCent would be an improvement [by reading a float from cfg]. Or simply to make the code cease reading those options into your keyboard. If adaptive deceleration is used, the first motion event after some time will lead to (probalby) underestimated velocity, making it subject to maximum slowdown, so it might appear to be skipped. Hard to note anyway. Some mice could push the limit and report so often that milliseconds don't provide reliable timing; in that case, some precision is lost. A mouse velocity monitor would be nice-to-have for tweaking. Any tracing in X? Reference http://lists.freedesktop.org/archives/xorg/2005-September/010211.html https://bugs.freedesktop.org/show_bug.cgi?id=138 https://bugs.freedesktop.org/show_bug.cgi?id=2927