Commit graph

251 commits

Author SHA1 Message Date
Peter Hutterer
54aa01a267 tablet: move tool creation into a helper function 2024-01-30 14:29:25 +10:00
Peter Hutterer
7cffd28e8f tablet: don't use absinfo_range for the percentage calculation
Our percents are inclusive 0% and 100%.
2024-01-30 14:29:25 +10:00
Peter Hutterer
0322403ea4 tablet: fix tilt handling for even-ranged tablets
The tablet tilt range may be set as [-N, M] in which case we assume that
a value of zero is vertical (and thus should result in a libinput tilt
value of zero). Unfortunately some tablets report an even total value
range, e.g. [-64, 63] so zero is not actually the mathematical center of
the axis.

Fix this by bumping the axis maximum so zero becomes the logical center.
All devices we've seen so far have [-A, (A-1)] as range so bumping it by
one makes it symmetric.
2024-01-30 14:29:25 +10:00
Peter Hutterer
72eca2db56 util: add a helper to normalize an axis to [0.0, 1.0]
Like the input axis, a normalized range has min/max inclusive so we
cannot use the absinfo_range() helper which assumes the max is exclusive.

Reverts parts of 4effe6b1b9
2024-01-30 14:29:25 +10:00
Peter Hutterer
f20eefbc59 Revert "tablet: fix the pressure offset range being off by one"
Fixing the range is only required when the output range is not inclusive
of the min/max (such as when mapping an abs axis to a screen width).

Our pressure range is inclusive 0.0 and 1.0, so we want absinfo->maximum
to map to exactly 1.0

This reverts commit a5b6f4009b.
2024-01-30 14:29:25 +10:00
Peter Hutterer
8bb53150a9 tablet: handle BTN_STYLUS3
And add a test to make sure the tool we know that has three buttons (Pro
Pen 3) can send all those. Enough to run that test one one compatible
device, no real benefit of running it on all tablet devices.
2024-01-24 12:34:25 +10:00
Peter Hutterer
cf1c07e066 Add a helper for radians to degrees 2024-01-16 19:49:02 +10:00
Peter Hutterer
4effe6b1b9 evdev: add a helper macro for the absinfo range
The range is (max - min + 1) because the kernel range is inclusive min
and max. Let's fix that once and for all with a helper function.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-29 17:07:38 +00:00
Peter Hutterer
a5b6f4009b tablet: fix the pressure offset range being off by one
Kernel ranges are inclusiv min/max, so let's make sure we calculate that
correctly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-29 17:07:38 +00:00
Peter Hutterer
d75a0fa42d tablet: fix the tilt range being off by one
Kernel ranges are inclusiv min/max, so let's make sure we calculate that
correctly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-29 17:07:38 +00:00
Bjørn Forsman
3dba00845c tablet: increase pressure offset limit from 20% to 50%
detect_pressure_offset() currently rejects offsets that are greater than
20%. My graphics tablet (Wacom Bamboo Fun) is about 30%. The pen tip is
2 mm. Wacom recommends replacing at 1 mm, which means this isn't worn
out yet and we should instead increase the limit to make these devices
usable.

Without this change a "pen down" event happens simultaneously with the
pen being detected -- about 1 cm above the surface -- and producing
libinput pressure of about 0.30. This means you start drawing "in the
air", without knowing up front where the cursor is going to be.

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
2023-08-24 08:04:03 +02:00
Peter Hutterer
a244b9e32b tablet: apply pressure offset handling for non-distance tablets
Previously we only applied pressure offset handling for tablets that
supported ABS_DISTANCE. Detecting a pressure offset when the tool
doesn't actually touch the surface is easy after all.

But tablets without distance handling may also have a pressure offset,
so let's try to detect this. This is obviously harder since the pen will
always touch the tablet's surface whenever it is in proximity and thus
will always have *some* pressure applied to it.

The process here is to merely observe the minimum pressure value during
the first two strokes of the pen. On the third prox in, that minimum
pressure value is taken as the offset. If the pressure drops below the
offset, the offset is adjusted downwards [1] so over time we'll
get closer to the pen's real offset.

[1] this is already done for distance tablets too

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-23 05:21:51 +00:00
Peter Hutterer
ecf02deb17 tablet: split proximity and axis update handling
Let's make this two conditions, this is too confusing to read otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-23 05:21:51 +00:00
Peter Hutterer
eea10aef47 tablet: split detecting and updating the pressure offset
detect_pressure_offset() would previously update an existing offset but
otherwise skip most of the work for any event other than proximity-in
events. This was too hidden, let's split this into two functions - one
to update an existing offset and another one to detect a new offset.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-23 05:21:51 +00:00
Peter Hutterer
71f5dc6e23 tablet: move setting the pressure offset into a helper function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-23 05:21:51 +00:00
Peter Hutterer
898f80fa37 tablet: always enable touch arbitration with touchscreens/ext. touchpads
Right now for touch arbitration to work, we require the device group to
be the same (i.e. they're hanging off the same physical bus). That's not
always the case and statistically we have a lot more devices that have
a built-in tablet + touchscreen than we have Intuos-like external
tablets.

So let's default to the more common case - enabling arbitration with the
first touchscreen/external touchpad we find. If a subsequent device is
"better", swap it out. Right now, the only heuristic we have here is the
device group check but in the future we could get more precise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-30 05:53:23 +00:00
Peter Hutterer
c26c05b255 tablet: split out arbitration/rotation handling assignment
No functional changes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-30 05:53:23 +00:00
hrdl
1e64d52fe9 evdev-tablet: clip touch arbitration rectangle
Previously the arbitration rectangle would be moved to lie completely in
the first quadrant of the coordinate system.

Signed-off-by: hrdl <51402-hrdl@users.noreply.gitlab.freedesktop.org>
2023-02-07 11:26:27 +01:00
José Expósito
96e57b5eff tablet: increase touch arbitration rectangle height
A user was experiencing issues with their hand being recognized as
touch input above the stylus tip.

Since touch above the stylus should be rare, increase the touch
arbitration rectangle height by 50mm.

Fix: https://gitlab.freedesktop.org/libinput/libinput/-/issues/809
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-11-23 22:39:02 +00:00
José Expósito
d84fc4ad11 tablet: fix compiler warning when -Dlibwacom=false
Fix the warning generated:

	[82/243] Compiling C object libinput.so.10.13.0.p/src_evdev-tablet.c.o
	../src/evdev-tablet.c:938:1: warning: unused function
	'tool_set_bits_from_libwacom' [-Wunused-function]
	tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet,
	^

When building with Clang v15 and without libwacom:

	$ CC=clang CXX=clang++ meson builddir -Dlibwacom=false

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-11-23 18:42:34 +01:00
José Expósito
640208531c tablet: avoid errors calling libevdev_get_abs_info()
Commit 806d4a1393 ("tablet: check libevdev_get_abs_info() return
value") prevented a crash when tilt was deactivated by a quirk.
For more information check [1].

Add similar checks before calling libevdev_get_abs_info() to avoid
possible crashes.

[1] https://gitlab.freedesktop.org/libinput/libinput/-/issues/805
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-10-03 12:53:22 +02:00
José Expósito
806d4a1393 tablet: check libevdev_get_abs_info() return value
Commit b5f0536a4f ("quirks: add a quirk for the Wacom 524c device")
added the quirk "AttrEventCodeDisable=ABS_TILT_X;ABS_TILT_Y;" to the
Wacom 524c.

When using the pen in a display with tilt support, the tilt X/Y axes
are set as changed. Using the pen again, but this time in the display
without tilt support, will try to get the tilt information, crashing.

Check the return value of libevdev_get_abs_info() to avoid this crash.

Fix https://gitlab.freedesktop.org/libinput/libinput/-/issues/805
Fixes: b5f0536a4f ("quirks: add a quirk for the Wacom 524c device")
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-09-18 16:00:26 +02:00
Peter Hutterer
bfbcf1737b tablet: require a minimum pressure before we process pressure events
Tools default to 1% lower threshold (tip up) and 5% upper threshold (tip
down). But our distance vs pressure exclusion would reset the distance
for *any* pressure value, regardless how low that value was and how high
distance was in comparison.

A very low pressure value of less than 1% would then result in a
normalized pressure of 0, so we'd effectively just reset the distance to
zero and do nothing with the pressure. This can cause distance jumps
when the tool arbitrarily sends low pressure values while hovering as
seen in https://github.com/libsdl-org/SDL/pull/5481#issuecomment-1118969064

Commit 61bdc05fb0 from Dec 2017
  "tablet: set the tip-up pressure threshold to 1%"
was presumably to address this but no longer (?) works.

Fix this by addressing multiple issues at the same time:
- anything under that 1% threshold is now considered as zero pressure
  and any distance value is kept as-is. Once pressure reaches 1%,
  distance is always zero.
- axis normalization is now from 1% to 100% (previously: upper threshold
  to 100%). So a tip down event should always have ~4% pressure and we
  may get tablet motion events with nonzero pressure before the tip down
  event.
  From memory, this was always intended anyway since a tip event should
  require some significant pressure, maybe too high compared to e.g.
  pressure-sensitive painting
- where a tablet has an offset, add the same 1%/5% thresholds, on top of
  that offset. And keep adjusting those thresholds as we change the
  offset. Assuming that the offset is the absolute minimum a worn-out
  pen can reach, this gives us the same behaviour as a new pen. The
  calculation here uses a simple approach so the actual range is
  slightly larger than 5% but it'll do.

  Previously, the lower threshold for an offset pen was the axis minimum
  but that can never be reached. So there was probably an undiscovered
  bug in there.

And fix a bunch of comments that were either wrong, confusing or
incomplete, e.g. the pressure thresholds were already in device
coordinates.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-23 05:43:18 +00:00
Peter Hutterer
988329d5d9 tablet: use a helper variable to make the code more readable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-23 05:43:18 +00:00
Peter Hutterer
374d32c6be tablet: remove an always-true part of an if condition
A few lines north of here we return early if neither bit is set. If we
get to this point, at least one bit is set so this part of the condition
always evaluates to true.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-23 05:43:18 +00:00
Peter Hutterer
395d12d634 util: auto-declare the element variable in ARRAY_FOR_EACH
All cases we have in our code base have an otherwise unused variable to
loop through the array. Let's auto-declare this as part of the loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-09 10:16:07 +10:00
Peter Hutterer
57a592e2df tablet: handle a BTN_TOOL_PEN on top of BTN_TOOL_RUBBER
The Wacom 524C device triggers a kernel bug in the InRange and Invert
handling. Every time BTN_TOUCH is set/unset the device also sets/unsets
BTN_TOOL_PEN even when we nominally have the eraser in proximity.

The event sequence effectively looks like this:

    # on prox in
    BTN_TOOL_RUBBER 1
    -- SYN_REPORT ---
    # on tip down
    BTN_TOOL_PEN 1
    BTN_TOUCH 1
    -- SYN_REPORT ---
    # on tip up
    BTN_TOUCH 0
    BTN_TOOL_PEN 0
    -- SYN_REPORT ---
    # on prox out
    BTN_TOOL_RUBBER 1
    -- SYN_REPORT ---

To work around this, bias our duplicate tool detection code towards the
eraser - if we have an eraser in-prox already and the pen goes
in-prox, ignore it and continue with the eraser. But if we have a pen
in-prox and the eraser goes in-prox as well, force a prox-out for the
pen and put the eraser in-prox.

Recording originally from
https://github.com/linuxwacom/xf86-input-wacom/issues/186

Fixes #702

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-12-14 08:09:20 +00:00
Quytelda Kahja
e6c4b1d16e quirks: Add tablet smoothing attribute.
https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/512 disables
input smoothing for AES devices. However, some AES devices produce
segmented/wobbly curves without smoothing. This change introduces an
`AttrTabletSmoothing` boolean property, which overrides the default smoothing
behavior.

See #632

Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
2021-07-28 23:53:36 +00:00
Konstantin Kharlamov
3d3d9b7f69 treewide: get rid of tmp argument in list_for_each_safe
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
2021-03-02 09:10:35 +03:00
Torstein Husebø
18c9265224 treewide: fix typos
Signed-off-by: Torstein Husebø <torstein@huseboe.net>
2020-12-16 22:08:23 +01:00
Peter Hutterer
a506d092b8 tablet: disable smoothing for AES devices
Data in
https://gitlab.freedesktop.org/libinput/libinput/-/issues/225#note_379034
suggests that AES devices have lower noise than the older EMR
devices, so let's try disabling it for those devices.

We can't directly get the AES devices in libinput unless we want to add a
whole bunch of quirks for the various vid/pid combinations. But we can get
that info from libwacom, primarily because we know that libwacom will list all
known AES pens for any device. So we can check for one that we know of (0x11)
and if it's in the list, the tablet is an AES tablet.

Setting the history size to 1 means we never do any actual smoothing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-11-25 03:54:47 +00:00
Peter Hutterer
06e7adfca3 tablet: split a ternary condition into a normal if else for readability
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-22 17:35:41 +10:00
Peter Hutterer
0e9fe09f1e tablet: group the pressure related bit into a substruct
No functional changes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-22 17:35:41 +10:00
Peter Hutterer
a62e2b14a2 Drop the trailing slash from the HTTP_DOC_LINK
It makes the printf statements nicer and we ne don't use it on its own
anywhere anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-09 11:36:07 +10:00
Peter Hutterer
2a7ea444e3 Ignore key repeat in all backends
Since we don't really care about keys in any of these backends and buttons
shouldn't autorepeat anyway, this should have no effect on functionality. But
it does guard us against potential kernel bugs like  this one:
https://www.spinics.net/lists/linux-input/msg67653.html

See https://gitlab.freedesktop.org/libinput/libinput/-/issues/447#note_468971

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-06-02 01:07:01 +00:00
Peter Hutterer
0d06bfc4e2 tablet: add support for sendevents on tablets
This is merely the simple support that we use in the fallback backend as
well. It doesn't interact with touch arbitration directly but it'll be
good enough for the default use-case.

Fixes #476

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-26 05:11:01 +00:00
Peter Hutterer
0b221c6c97 tablet: handle a valid prox-out sequence after a forced proximity out
With the previous patches a tablet would ignore a valid proximity out sequence
where it happends after a forced prox-out. Fix this by checking the state when
we're in forced proximity out - if we have a zero tool state but a tool
updated then we did get a proximity out.

And fix the existing test to check for that case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-22 03:10:06 +00:00
Peter Hutterer
c457050d44 Revert "tablet: don't disable the proximity quirk on good sequences"
This quirk was introduced for #248 was caused by buggy input-wacom drivers,
not by actual firmware, see
https://gitlab.freedesktop.org/libinput/libinput/issues/381#note_279371

This appears to be the only tablet where this fix was needed, but we've been
playing whack-a-mole ever since to work around the various other tablets that
break with this behavior in place.

So let's revert that fix and hope there aren't any other tablets out there
(and if they are, we can probably quirk those). The revert makes the ISDV4 pen
quirk obsolete (see 9cb089f2b6), so this was
folded into this commit.

This reverts commit 4f63345b60.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-22 03:10:06 +00:00
Peter Hutterer
72af32c89e tablet: use the AttrPressureRange quirk for tablets too
The Aiptek 8000U has a pressure offset above our default (%5) but no
meaningful way of detecting that. It doesn't provide distance or BTN_TOOL_PEN
either, so our heuristics can't hook onto anything. BTN_TOUCH is set by this
tablet but not at consistent pressure thresholds.

Work around this by shipping a quirk that ups it to 70. Aiptek
re-uses USB IDs because of course they do, so this applies to more than one
device. Let's see what breaks.

Fixes #462

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-03-31 02:49:24 +00:00
Peter Hutterer
07a86b85dd tablet: don't force a proximity out while buttons are down
While buttons are down, don't let a forced proximity out happen. If the tablet
goes out of proximity normally that's fine but we don't force a proximity out.

Remains to be seen if this causes stuck buttons now on devices that rely on
the forced proximity out...

Fixes #403

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-13 04:53:27 +00:00
Peter Hutterer
71830dd460 tablet: fix the handling of axis updates after a forced proximity out
Where a pen was forced out of proximity and an eraser came into proximity
without axis updates on the prox-in, subsequent axis updates would trigger the
pen back into proximity. This resulted in two tools in proximity at once
though the new pen never went out of proximity

This would trigger crashes in various compositors/applications, see
https://github.com/xournalpp/xournalpp/issues/1141#issuecomment-578362497

The cause was a wrong condition introduced in ffd8c71e4e. We only need to
force the pen bit on if the current tool state is currently zero and no tool
update was sent with the axis event. In our case, the tool state is nonzero
already (eraser) and we can skip this bit.

Fixes #418

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-02 23:46:14 +00:00
Peter Hutterer
d20bbfa5cb tablet: handle a direct tool switch correctly
Fixes #259

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-31 23:27:39 +00:00
Peter Hutterer
bc461b0292 tablet: add a helper function to get the current tool
No functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-31 23:27:39 +00:00
John Chadwick
8568cf1b3a tablet: Improve forced prox out behavior.
Some graphics tablets (most or all Wacom, for example) do not emit
proximity out events when the tablet pen goes out of range. To
compensate for this, libinput synthesizes proximity out events when no
events are received for a certain period of time. Unfortunately, on some
tablets, this is fairly failure prone when moving the pen slowly. As a
workaround, this patch causes libinput to avoid synthesizing proximity
out events when the pen is still in contact with the tablet pad, as
defined by the TABLET_TOOL_IN_CONTACT status.
2019-09-29 23:35:09 +00:00
Konstantin Kharlamov
8f278e69c2 evdev-tablet.c: remove unused include
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
2019-09-12 09:36:40 +10:00
Peter Hutterer
d93feba134 tablet: scale the available pressure range into the pressure thresholds
Pens that don't have a pressure offset (caused by a worn-out tip) still have
basic pressure thresholds to avoid tip events when we're still a bit away from
the tablet or barely touching it. That range is currently 5% of the pressure
for tip down, 1% for tip up.

This leaves us with 95% of the range and that needs to be scaled correctly,
otherwise the bottom 5% happen before a tip event and are inaccessible where
applications don't look at pressure before tip down.

Fixes #332

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-08 13:58:54 +10:00
Peter Hutterer
72121d6f6c tablet: reduce the pressure range by the offset
Previously, the pressure range was calculated from the axis total range. A
device with a pressure offset making the bottom 10% inaccessible would lose
10% of that range as non-accessible. Due to the implementation, this affected
the upper range of the device, so the top N percent became unaccessible. Which
may be why no-one's noticed this yet.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-08 13:58:54 +10:00
Peter Hutterer
f97e361d5d tablet: make the pressure-offset inclusive of the axis minimum
The offset handling was inconsistent, stored as relative to the axis minimum
but used as absolute in some places. Fix this by always using the absolute
value including the minimum (i.e. no pressure offset means offset == minimum).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-08 13:58:54 +10:00
Peter Hutterer
a71d091e59 tablet: add a comment explaining why we adjust the pressure offset downwards
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-08 12:54:52 +10:00
Peter Hutterer
c5865f3ef0 tablet: point the pressure offset log messages to the right URL
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-08 12:54:52 +10:00