Commit graph

119 commits

Author SHA1 Message Date
Kim Lindberger
99334e11bf
Add quirk to control velocity averaging, disable it by default
libinput applies averaging to the velocity of most pointer devices. Averaging
the velocity makes the motion look smooth and may be of benefit to bad input
devices. For good devices, however, it comes at the unfortunate price of
decreased accuaracy.

This change turns velocity averaging off by default (sets ntrackers to 2 instead
of 16) and allows for it to be turned back on via a quirk, for bad devices which
require it.
2018-08-22 12:12:55 +02:00
Peter Hutterer
33162632cb Revert "Expose a custom acceleration profile"
This looked good on paper but clearly no-one (including myself) ever tested this
in a real-life situation or they would've noticed that the constant factor is
missing, causing a segfault on the first two-finger scroll event, touchpad
gesture or button scrolling.

Adding the constant factor makes the API much worse and the benefit is
unclear, so out of the window it goes. We can revisit this for libinput 1.12
but this isn't going to make the next release.

This reverts commit d8bd650540.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-21 12:15:25 +10:00
Peter Hutterer
d8bd650540 Expose a custom acceleration profile
This adds a third profile to the available profiles to map device-specific
speed to an acceleration factor, fully defined by the caller.

There has been a consistent call for different acceleration profiles in
libinput, but very little specifics in what actually needs to be changed.
"faster horses" and whatnot (some notable exceptions in e.g. bug 101139).
Attempts to change the actual acceleration function will likely break things
for others.

This approach opens up the profile itself to a user-specific acceleration
curve. A caller can set an acceleration curve by defining a number of points
on that curve to map input speed to an output factor. That factor is applied
to the input delta.

libinput does relatively little besides mapping the deltas to the
device-specific speed, querying the curve for that speed and applying that
factor. The curve is device-specific, the input speed is in device units/ms.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-26 14:48:37 +10:00
Peter Hutterer
7d06ccc061 filter: always average the velocity of the first two events
Don't apply any velocity diff checking on the first two events, always average
them (unless the timeout is hit or the direction changes). This averages out
some of the jumps we get on slow motion.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-26 14:02:50 +10:00
Peter Hutterer
588105da31 filter: make the MAX_VELOCITY_DIFF a double
The value is 0.001 which happens to be 0 when you cast it to int.

Introduced in e3554f38f8

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-26 10:34:16 +10:00
Peter Hutterer
31a21c0028 filter: namespace the various trackers_* functions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 17:01:03 +10:00
Peter Hutterer
d8e8b74b06 filter: split the mouse acceleration out into a separate file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:52:00 +10:00
Peter Hutterer
f02c9b9734 filter: drop the ntrackers argument from init_trackers
Reduces the duplication, everyone uses the same value anyway

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:42:58 +10:00
Peter Hutterer
6135e1d878 filter: split the low-dpi acceleration into a separate file
Plenty of duplication there from the normal filter.c, but that also makes it
less likely to break if we adjust the other one.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:24:52 +10:00
Peter Hutterer
f61adfcf9b filter: move the flat filter into a separate file
This also fixes a bug with the _noop function, because we casted to the wrong
struct the dpi value was garbage.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
e3554f38f8 filter: move the velocity diff to the only function we use it in
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
b887353ab9 filter: split the touchpad acceleration code into a separate file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
40c5b64f82 filter: make the simpsons accel calculation available through the header
This is the standard approach for mice and touchpads to calculate the
acceleration based on the last two deltas, let's make that code shareable.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
0ead929838 filter: move the pointer_accelerator struct into the header
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
477f51b6bd filter: split trackpoint acceleration code into a separate file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
f79b2d4df4 filter: split the tablet accel code into a separate file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
d857e36c33 filter: move the x230 filter into a separate file
There's a fair bit of duplication of code from filter.c but it's not worth
disecting this and optimising it. The device is 5 years old now, we don't want
to touch this accel method so duplication is good here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
228d0497b7 filter: add helper function to reset and free trackers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
3f53430ea1 filter: pass trackers to calculate_velocity
So the function to calculate the velocity is easier to call from other sites.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
acb4168053 filter: move the smoothing values to the trackers
This way we can pass them around easier without needing the whole
pointer_accelerator struct (which in theory is device-type specific). The
values relate to the calculation of the delta between trackers anyway, so
logically this is where they belong.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
69d0d188a7 filter: move some functions to the shared header
Prep work for splitting things up better

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
0dcd401485 filter: factor out the pointer trackers from the accel filter
No functional changes, just refactoring

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-18 16:15:38 +10:00
Peter Hutterer
d92d8554c3 filter: don't allow an accel factor of 0 on the flat profile
Leave a narrow gap so the mouse moves excruciatingly slow instead of not
moving at all. This allows to recover from overexcited mouse speed slider
movements.

https://bugs.freedesktop.org/show_bug.cgi?id=102501

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-09-11 08:30:34 +10:00
Hans de Goede
c4857f01d8 touchpad: Enable timestamp smoothing support for bluetooth touchpads
Bluetooth wreaks havoc with the timestamp of the input events coming
from the touchpad, enable timestamp smoothing support to counter this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-01 16:42:19 +01:00
Hans de Goede
6f39a9e1c2 filter: Add timestamp smoothing support
Some devices, specifically some bluetooth touchpads generate quite
unreliable timestamps for their events. The problem seems to be that
(some of) these touchpads sample at aprox 90 Hz, but the bluetooth stack
only communicates about every 30 ms (*) and then sends mutiple HID input
reports in one batch.

This results in 2-4 packets / SYNs every 30 ms. With timestamps really
close together. The finger coordinate deltas in these packets change by
aprox. the same amount between each packet when moving a finger at
constant speed. But the time deltas are e.g. 28 ms, 1 ms, 1 ms resulting
in calculate_tracker_velocity returning vastly different speeds for the
1st and 2nd packet, which in turn results in very "jerky" mouse pointer
movement.

*) Maybe it is waiting for a transmit time slot or some such.

This commit adds support for a real simple timestamp smoothing algorithm,
intended *only* for use with touchpads. Since touchpads will send a
contineous stream of events at their sample rate when a finger is down,
this filter simply assumes that any events which are under
event_delta_smooth_threshold us apart are part of a smooth continuous
stream of events with each event being event_delta_smooth_value us apart.

Theoritically a very still finger may send the exact same coordinates
and pressure twice, but even if this happens that is not a problem because
a still finger generates coordinates changes below the hyst treshold so
we ignore it anyways.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-01 16:42:19 +01:00
Peter Hutterer
87b5682824 filter: add a custom trackpoint accelerator
Switch to a pure factor with a max scaled after a function. The offset is just
0 now (will be removed eventually). Both are determined with a function based
on a linear/exponential regression of a sample set of data pairs.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-20 11:53:01 +10:00
Peter Hutterer
e71ade2755 Replace calloc calls with zalloc
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-12 10:18:08 +10:00
Peter Hutterer
d5d6d4cd53 Abort if zalloc ever fails
There's no guarantee that libinput does the right thing if memory allocation
fails and it's such a niche case on the systems we're targeting that it just
doesn't matter. Simply abort if zalloc ever fails.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-12 10:18:07 +10:00
Peter Hutterer
5f0d310ead filter: normalize deltas before processing or returning them
When the filter code switched to raw device coordinates (bdd4264d) the input
data remained in device coordinates. Since the factor for touchpads was still
based on the physical velocity (and thus all touchpads get the same
acceleration factor for identical moves), the actual delta was dependent on
the resolution. e.g.

touchpad with 40u/mm: delta of 2/2 * accel factor 2 -> accel delta of 4/4
touchpad with 20u/mm: delta of 1/1 * accel factor 2 -> accel delta of 2/2

The normalized coordinates should be independent of the touchpad's resolution
though.

Affected by this was the standard mouse accel code and the touchpad accel
code, other filters always returned unnormalized coordinates (separate bug,
not addressed here).

This patch restores the correct behaviour for mice and touchpads
while leaving the special filters untouched. For comparision:
* 1000+dpi mice: accelerate normalized, return normalized
* touchpads: accelerate unnormalized, return normalized
* low-dpi mice: accelerate unnormalized, return unnormalized
* trackpoints: accelerate unnormalized, return unnormalized
* x230: don't touch, already does the right thing

https://bugs.freedesktop.org/show_bug.cgi?id=99383

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-01-19 11:56:28 +10:00
Peter Hutterer
79339bca9c filter: change the tracker delta type to device-units
We were just switching type here without actual normalization, the filter code
is in device units as of bdd4264d61.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-01-19 09:34:28 +10:00
Peter Hutterer
f4ff619cf7 filter: tweak the magic slowdown
Could be confirmation bias, but it feels better.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
ff31427e80 filter: revamp the touchpad's acceleration code
The previous code had three main issues:
* acceleration kicked in too early, so even slow movements were accelerated
* acceleration kicked in too quickly, there was only a very narrow window
  where we would have less than the max acceleration factor
* the max accel factor was too low for fast movements, so they still fell
  short of expectations

This patch revamps most of the acceleration though it keeps the basic shape of
the acceleration curve.

* The threshold is increased significantly so that faster movement
  still map to the finger movement. Acceleration doesn't kick in until we get
  to something that's really fast like a flick.
* The incline is dropped, so acceleration kicks in slower than before, i.e.
  the difference between the first speed that is accelerated and the speed
  that reaches the maximum is higher than before.
* The maximum acceleration is increased so ever faster movements get ever
  faster. The max is effectively out of reach now, if you move fast enough to
  hit this speed, your cursor will end up on the moon anyway.

A couple of other changes apply now too, specifically:
* The incline remains the same regardless of the speed
* The max accel factor remains the same regardless of the speed

The caculated factor changes with the speed set so that the base speed changes
with the desired speed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
84ab969c26 filter: work the touchpad magic slowdown into the various parameters
We have everything separate from the mouse now, so having a magic slowdown
isn't needed, we can work this into our parameters. So the acceleration
function now uses everything adjusted, but the factor is still multiplied by
the slowdown in the end.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
4c4b5de641 filter: change touchpad accel code to use mm/s
That's something human brains can map to because mapping a touchpad to
equivalent units of a 1000dpi mouse requires a lot of mental acrobatics. And
I'm getting older and my physio told me acrobatics is more something for the
youngens, possibly those on my lawn listening to terrible music, etc.

The various numbers are converted either times 25.4/1000 or times 1000/25.4,
depending on the usage. Somewhere I made a mistake or a rounding error or
something, so the acceleration curve is not exactly the same, but it's close
enough that it shouldn't matter. The difference shows up in a gnuplot of the
curve but it may not even perceivable anyway. And these values will be
overhauled soon anyway, so meh.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
91d287228f filter: drop the now-generic trackpoint and low-dpi filter functions
The profile is what is still special about those two, the filter itself does
the same as the default filter (calculate velocity, calculate accel factor,
apply to delta).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
bdd4264d61 filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).

Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.

No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.

Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:57 +10:00
Peter Hutterer
8e2d3b9049 filter: duplicate pointer accel for touchpads
This duplicates the code so we can change it for touchpads without affecting
mice.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:56 +10:00
Peter Hutterer
a2dbd4f2d7 filter: drop the dpi_factor in favor of direct calculation
This was badly since the factor was the ratio of "dpi:default dpi"

Most devices don't need it, so storing it in all filters event though we only
use it for some devices is confusing. Now that we have the dpi stored
directlyconfusing. Now that we have the dpi stored directly we might as well
use that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:56 +10:00
Peter Hutterer
f04ef9f985 filter: store the raw dpi value in the filter
Currently unused, will be used in the future.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 10:55:56 +10:00
Peter Hutterer
8a389c90e9 filter: fix comment on how we calculate the slow-motion incline
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-12-15 19:44:02 +10:00
Peter Hutterer
ab42022253 Change the directions bitmask to a uin32_t
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-12-15 19:43:41 +10:00
Peter Hutterer
577422f692 filter: fix a comment, the trackpoint profile uses device units
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-12-15 19:43:05 +10:00
Peter Hutterer
0e8be12383 filter: add a comment for how we calculate velocity
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-14 15:20:07 +10:00
Peter Hutterer
5016dcd012 filter: split a condition up so we can mark it as bug
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-14 15:19:57 +10:00
Peter Hutterer
0926f570c4 tablet: make the cursor/lens tool behave like a 1000dpi mouse
The current code tried to emulate the relative motion to be equivalent to the
absolute motion, except in screen coordinates. This is way too slow for the
cursor tool that we want to behave like a mouse.

Tablets have high resolution (e.g. an Intuos 4 is a 5080dpi mouse) and that
motion is way too fast to be usable. Scale it down to match a 1000dpi device
instead. Since the cursor and lens tool are still high precision devices leave
them in a flat acceleration profile without actual acceleration.

For the stylus-like devices leave the current accel, pointer acceleration on a
stylus is hard to handle.

This also adds the missing bits for actually using the speed factor set
through the config interface.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Reviewed-by: Carlos Garnacho <carlosg@gnome.org>
2016-06-28 11:28:49 +10:00
Eric Engestrom
7a81ba9cc2 Fix spelling mistakes
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-04-06 07:42:03 +10:00
Peter Hutterer
7164d6eff5 tablet: hook up relative motion events
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Jason Gerecke <jason.gerecke@wacom.com>
2016-01-22 16:16:55 +10:00
Peter Hutterer
8d9e7a1bcf Add an API to change pointer acceleration profiles
The quartett of new config functions is:
	libinput_device_config_accel_get_profiles
	libinput_device_config_accel_get_profile
	libinput_device_config_accel_set_profile
	libinput_device_config_accel_get_default_profile

The profile defines how the pointer acceleration works, from a very high-level
perspective. Two profiles are on offer, "adaptive", the standard one we have
used so far and "flat" which is a simple multiplier of input deltas and
provides 1:1 mapping of device movement vs pointer movement.

The speed setting is on top of the profile, a speed of 0 (default) is the
equivalent to "no pointer acceleration". This is popular among gamers and
users of switchable-dpi mice.

The flat profile unnormalizes the deltas, i.e. you get what the device does
and any device below 800dpi will feel excruciatingly slow. The speed range
[-1, 1] maps into 0-200% of the speed. At 200%, a delta of 1 is translated
into a 2 pixel movement, anything higher makes it rather pointless.

The flat profile is currently available for all pointer devices but touchpads.

https://bugs.freedesktop.org/show_bug.cgi?id=89485

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-09-11 00:54:01 +10:00
Peter Hutterer
6a0f9411f2 filter: fix constant acceleration for the X230
The x230 has a special acceleration method that relies on the touchpad magic
slowdown. This was missing from commit c8da19b50a, making two-finger
scroll motions unusably fast

https://bugs.freedesktop.org/show_bug.cgi?id=91819

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-08-31 14:05:11 +10:00
Peter Hutterer
c8da19b50a touchpad: use unaccelerated motion data for scrolling
For short and quick scroll gestures, those that should only trigger a few
lines of scroll the pointer acceleration is wildly unpredictable. Since we
average the motion of both fingers it's hard enough to intuitively predict
what the motion will be like. On top of that is the small threshold before we
start scrolling, so some of the initial motion gets swallowed before we
accelerate, making the next motion even more unpredictable.

The end result is that multiple seemingly identical finger motions cause
wildly different scroll motion.

Drop pointer acceleration for two-finger and edge scrolling. This makes short
scroll motions much more predictable and doesn't seem to have much effect on
long scroll motions. Plus, in natural scroll mode it really feels like the
content is stuck to your fingers now. Go wash your hands.

https://bugzilla.redhat.com/show_bug.cgi?id=1249365

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-08-20 07:57:14 +10:00