Commit graph

2438 commits

Author SHA1 Message Date
Peter Hutterer
0288781383 gestures: change the debug log messages for state debugging
Prefix the result of handle_event with "event" and the handle_state with
"state"

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1106>
2024-12-20 09:47:46 +00:00
Peter Hutterer
3563b6780f gestures: use a macro for debugging transition states
This avoids bugs where we forget to update a state but also provides
some bounds checking now to ensure our array is large enough to store
those transitions.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1106>
2024-12-20 09:47:46 +00:00
Joshua Noeske
ce7b7c94e7 gestures: fix transformation of scroll to pinch
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1099>
2024-12-18 15:50:50 +01:00
Peter Hutterer
eef0650759 touchpad: init the thumb size threshold to INT_MAX
For consistency with the pressure threshold, both are guarded behind
a use_size/use_pressure boolean anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1095>
2024-12-18 08:24:41 +00:00
Peter Hutterer
c3aa00ef90 gestures: don't handle SWIPE if we transitioned from SWIPE_START
If we get to SWIPE_START we send out the BEGIN event and transition to
state SWIPE. We must not process that state immediately to avoid sending
out a spurious UPDATE event when nothing has changed.

Same for the PINCH_START/PINCH and SCROLL_START/SCROLL states.

This also fixes a crasher where we end up with NaN in the custom
acceleration function because passing the same timestamp in twice causes
a division by zero (delta time is zero).

Closes #1053

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1088>
2024-12-10 06:15:21 +00:00
Peter Hutterer
d773056d2e touchpad: remove assert that may trigger during a race condition
There appears to be a race condition where an ABS_MT_TRACKING_ID -1
event is on the wire but libevdev_fetch_slot_value() for that slot
already gives us -1 as well.

If we just (re)opened our device, synching our slots would thus set zero
active slots and then trigger the assert when that event is being
processed.

It's unclear how to reliably reproduce this issue but removing the
assert and simply ignoring this event if we don't have active slots
is correct anyway.

Closes #1050

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1081>
2024-12-01 22:44:50 +00:00
Peter Hutterer
865b2e748f tablet: ignore movements started outside the configured area
If a tablet has an area configured and the pen goes into proximity
outside this area, ignore all events from this sequence. This truly
deactivates that area so it can even be used for e.g. placing a pen
there.

For simplicity, a sequence that starts outside the configured area will
be completely ignored, i.e. moving into the tablet area will not trigger
any fake proximity events as we cross into the allowed area. This
requires quite a bit of effort and it's unclear if it's really needed by
users - we can reconsider when we get complaints.

We do however accept a proximity event within within 3% of the
configured area.  This gives us 6mm on a 200mm tablet where we can move
in from the area and still have events work, i.e. some error margin for
where a user needs both an area and work closes to the edge of that
area.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:10:48 +10:00
Peter Hutterer
0b28eeea5a tablet: implement support for area configuration for external tablets
For external tablets like the Intuos series we now expose the area
rectangle configuration and the (minimum) implementation required to
make this work.

Because an area configuration may apply late and tablet events usually
get scaled by the compositor we need to store the current axis extents
in each event. This is to behave correctly in this events sequence:

1. tool proximity in
2. caller changes config, config is pending
3. tool moves, generates events
4. tool goes out of prox, new config applies
5. caller processes motion events from step 3

If the caller in step five uses any of the get_x_transformed calls these
need to be scaled relative to the original area, not the one set in
step 2.

The current implementation merely clips into the area so moving a stylus
outside the area will be equivalent to moving it along the respective
edge of the area. It's not a true dead zone yet.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:10:48 +10:00
Peter Hutterer
cf5b7bee01 Add tablet area configuration
This adds the configuration option to define a rectangle that serves as
an input area on external tablets such as an Intuos.

The intention behind this is to make this input area behave as if it was
the only physical input area on this tablet with libinput emulating
proximity events as required for where the tools moves in and out
of this area.

This could also be achieved with the existing calibration setting but
area configuration is not calibration and we don't want to expose other
side-effects of the matrix (e.g. scaling and rotation) for these
devices.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:10:48 +10:00
Peter Hutterer
9735229dee tablet: use our absinfo_x/y struct instead of the libevdev one
device->abs.absinfo_x/y points to the x/y axis we want to use and
that axis is used in all the evdev helper function. For consistency
use that one here too.

This is for consistency only and has no effect on tablet devices, the
only time this isn't ABS_X/Y is on multitouch devices where that points to
ABS_MT_POSITION_X/Y.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:05:05 +10:00
Peter Hutterer
cfbdca5953 Move evdev_convert_to_mm to a more generic helper
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:05:05 +10:00
Peter Hutterer
df242c108d Move scale_axis to a utility header so we can re-use it better
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>
2024-11-05 12:05:05 +10:00
José Expósito
3f3071cb88 editorconfig: add settings for sym files
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1076>
2024-11-04 10:31:30 +00:00
Peter Hutterer
d1e49c7b3d tablet: default to a built-in tablet
The vast majority of devices that libwacom doesn't know about are the
various built-in ones. Since the only effect in our code here is that we
enable the calibration matrix, let's default to built-in if we don't
know any better - better to have the matrix and not use it than to not
be able to calibrate a tablet.

Note that libwacom 2.11 and later also now default to a built-in tablet.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1074>
2024-10-31 15:58:31 +10:00
Peter Hutterer
2b2959fc8b tablet: centralize the libwacom handling
Instead of re-creating the the libwacom device from the database every
time we need it let's create it once during tablet|pad_init and pass it
down to the functions.

This allows us to have one point per tablet/pad where we can log an
error if the device is not supported by libwacom - previously this was
printed during the left-handed setup.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1073>
2024-10-31 13:38:28 +10:00
Peter Hutterer
d3bc0c79ff tablet: minor rework to remove one ifdef HAVE_LIBWACOM
Change to a boolean for more obvious return values and move the ifdef
into the function so we can skip the ifdef in the caller.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1073>
2024-10-31 13:38:28 +10:00
Peter Hutterer
384e946960 pad: support dial modeswitch buttons
This requires unreleased updates to libwacom [1], currently hiding
behind an ifdef so we don't require that particular version.

[1] https://github.com/linuxwacom/libwacom/pull/805

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1070>
2024-10-31 11:04:45 +10:00
Peter Hutterer
90e9c9f832 pad: rework the tablet pad mode setup
This was historically based on the LEDs on the device: we'd loop through
the LEDs and assign them to pad mode groups, then figure out which
button is the mode toggle for that group and finally which buttons
are in the same position as that toggle button.

Devices like the XP Pen ACK05 Remote don't have LEDs though but they do
have a mode toggle button [1] inside the dial. Let's support those by
switching the initialization on its head: search for mode toggle
buttons, create a mode group per toggle button, then associate
LEDs with that group.

The outcome should be functionally the same for devices with LEDs but
allows us to create mode groups where no LEDs exist.

Closes #1045

[1] As per Windows default button behavior

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1070>
2024-10-31 11:04:45 +10:00
Peter Hutterer
7ae4fabb76 pad: don't clobber the errno if the pad led failed to initialize
pad_led_destroy() may call something that sets errno, so let's protect
against that.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1070>
2024-10-31 10:28:08 +10:00
Peter Hutterer
181c667266 pad: remove an unused argument
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1070>
2024-10-31 10:28:08 +10:00
Peter Hutterer
c969b5f6e2 pad: rename an argument for more clarity
Yes, we're using the LED count here but what it is used for is the
number of modes.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1070>
2024-10-31 10:28:08 +10:00
Peter Hutterer
4fa5ea268e util: add a generic stringbuffer with a few helper functions
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
817dc42381 util: add the range handling as separate header file
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
f91f0a7ea5 util: add a bunch more time conversions
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
02f5faf6f6 util: move libinput_now() into a utility function
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
d3922661ba util: add xclose(fd) to close-and-reset an fd
This prevents accidentally leaving the fd set after closing.

And it includes the -1 check so we don't need this everywhere ourselves
(not that we use it right now but valgrind likes to complain about
this).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
5e235a6546 util: make a float to int conversion explicit
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1071>
2024-10-29 10:18:54 +10:00
Peter Hutterer
e0f671126d util: add the backtrace printing function as separate util
Might as well make this easier to re-use since it doesn't do anything
specific to litest.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1066>
2024-10-23 10:08:12 +10:00
Peter Hutterer
4546480e13 pad: default a pad group to mode 0 if all LEDs are off
Since our API doesn't accomodate for "dunno" we need to pick a mode that
we are actually in. This happens on the Intuos Pro 2 (PTH-660) which has
all LEDs on brightness zero, resulting in a failure to set up the modes
and we're left without a mode button.

Fix it by just picking zero as the default mode until specified
otherwise.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1069>
2024-10-22 18:14:15 +00:00
Peter Hutterer
04cff1c721 pad: move a function to save on an ifdef
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1069>
2024-10-22 18:14:15 +00:00
Peter Hutterer
0c782c4084 pad: don't print a clobbered errno
is_litest_device() may change errno since it calls into libudev.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1069>
2024-10-22 18:14:15 +00:00
Peter Hutterer
3390f2e647 test: make the TEST_COLLECTION() macro re-usable in the same file
Concat the line number to the generated variable names, this way we can
have more than one TEST_COLLECTION() in the same file.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1065>
2024-10-18 10:49:47 +10:00
Peter Hutterer
5f744c8928 tablet: fix a memory leak caused by an early return
Previously we'd return early, failing to libwacom_destroy() the device.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1064>
2024-10-18 09:48:05 +10:00
Peter Hutterer
2b77bdab5c gestures: change a boolean to an enum for more expressive code
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
0fd074c974 gestures: add debugging for state transitions
Our state machine allows falling through multiple transitions, so let's
make it possible to debug this.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
68a2ff0d49 gestures: get rid of tp_gestures_start
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
89596e61f8 gestures: rename gesture_notify_hold to gesture_notify_hold_begin()
HOLD gestures only have begin/end so let's rename this so it's
immediately obvious which one we're sending.

notify_swipe/pinch pass the event type in so it's clear that it's a
BEGIN vs an UPDATE.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
8899800de8 gestures: rename most events to FOO_START
These events aren't used to signal scroll/swipe/pinch/..., merely to
signal the start of that gesture. So let's rename it to make the code
clearer (e.g. why do we log a bug when for a FOO event when we're in
state FOO?).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
e88007d4ae gestures: push tp_gesture_start() for hold gestures into the state handling
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
fd0875029b gestures: push tp_gesture_end() into the actual state machine
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
c1690d408a gestures: log a bug if we're trying to reset an actual gesture
Now that end/cancel are separate states, we shouldn't get here.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
942fd0dc8f gestures: distinguish between a gesture reset and a gesture end/cancel
All current states treat them the same way but let's distinguish those
two so we can have different code depending on whether a gesture was
cancelled/reset or ended properly.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
96500d81fb gestures: replace switch-timeout based gesture_cancel calls with a state
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
6b5aeab51e gestures: rename tp_gesture_handle_state and tp_gesture_post_gesture
Confusingly, tp_gesture_handle_state() would do almost nothing with our
state machine and the various tp_gesture_handle_state_foo() were called
later from tp_gesture_post_gesture().

Rename those functions into so that we have
tp_gesture_update_finger_state() first followed by
tp_gesture_handle_state() which is responsible for dealing with the
state machine.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
c9c128f2b1 gestures: make a error message more informative
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
1d4e2e2e2d gestures: log the finger count together with the gesture state
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1049>
2024-10-04 15:13:23 +10:00
Peter Hutterer
54dccd66d1 Fix a few potential NULL dereferences
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1052>
2024-09-30 15:35:36 +00:00
Peter Hutterer
1790171c76 util: add a safe version of strlen
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1052>
2024-09-30 15:35:36 +00:00
Peter Hutterer
b1b3692e08 gestures: use a colon-suffixed debug prefix like the other state machines
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1048>
2024-09-12 15:24:45 +10:00
Peter Hutterer
e8495b8d36 gestures: cancel the hold before initializing the pinch
If we're in state HOLD we have an ongoing hold gesture - make sure we
cancel that one first before we initialize the pinch.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1046>
2024-09-11 09:38:29 +00:00