Commit graph

2478 commits

Author SHA1 Message Date
Peter Hutterer
6770131e94 util: fix a memleak in mkdir_p
In the error case path would leak.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
051ac26a20 util: shut up clang-tidy about our use of strcat
These are pre-counted strings, we're fine.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
0fc52abd79 util: change the builddir_lookup() to return a boolean
All but one callers of this function only care about yes/no, so let's
change it to only return the build dir in the one case it's needed.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
d8482a2540 util: use a late declaration to avoid one ifdef
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
f123da174e Add a few 0 enum values to shut up clang-tidy
These are all internal API so having a NONE value means we can shut up
warnings about 0 not being an enum value without having those exposed in
our public API.

And they slightly improve readability in the callers anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
a55dd604e1 util: add a newtype macro
In a valiant approach to introduce some type-safety (after spending time
debugging a int vs double confusion) this adds a DECLARE_NEWTYPE()
macro that declares a named struct with a single typed value field.

This is basically the C version of Rusts "struct Foo(u32)" with
a few accessors auto-generated by the macro.

C is happy to silently convert between base types but it doesn't do
so for structs so this allows us to have some type safety
when we accidentally assign two incompatible fields to each other (e.g.
an axis value in device units vs a percentage value).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1171>
2025-04-04 11:05:20 +00:00
Peter Hutterer
95fca82977 tools/debug-events: print pinch angle and rotation again
Fixes: 9907cf2eeb ("Move the event printing out into a utility")

Closes #1108

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1163>
2025-04-01 02:25:08 +00:00
Peter Hutterer
7d4e152aea tablet: delete the tablet's pressure range from the tool pressure ranges
Commit 48cd4c7287 ("tablet: track pressure ranges per tablet") added
up to 4 per-tablet pressure ranges that are stored in the tool on the
assumption that tools are never used across more than 4 tools.

However, if the tablet gets unplugged it will show up as new devices.
Fix this by removing the tool's reference to the previous tablet after
device removal.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1165>
2025-03-31 19:41:00 +10:00
Peter Hutterer
fc4e806e0b tablet: always initialize the pressure thresholds
When the tool is moved in proximity of a new tablet but the pressure
range hasn't changed since the last proximity, the new tablet was left
with a threshold range of 0:0.

For some reason this requires tightening up the check for the test too,
with our default episolon 0.091 fails the test of being > 0.9

Closes #1109

Fixes: 48cd4c7287 ("tablet: track pressure ranges per tablet")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1165>
2025-03-31 18:09:19 +10:00
Peter Hutterer
be679889e5 util: fix a memleak printing a tablet tip event
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1165>
2025-03-31 18:09:19 +10:00
Peter Hutterer
39fa451e7e pad: fix handling of direct mode switch buttons
A tablet with multiple mode toggle buttons had each mode toggle button
merely cycle to the next mode in the sequence, removing the whole point
of having multiple toggle buttons.

Fix this by defaulting each mode toggle button to "next". Once we
have initialized all buttons we can check if we have multiple buttons -
if so we number them sequentially so that the first button maps to mode
0, the second maps to mode 1, etc.

Closes #1082

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1132>
2025-03-27 04:57:33 +00:00
Peter Hutterer
79dc0261e2 tablet: fix an indentation issue
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1161>
2025-03-25 15:05:45 +10:00
Peter Hutterer
3f232131a1 util: provide better alignment for the function name/line no in trace
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1161>
2025-03-25 15:05:45 +10:00
Peter Hutterer
bcb467da4c test: add extra highlighting for the backtrace
Pass through the function name where the condition failed so we can
highlight that line in the backtrace.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1159>
2025-03-14 09:52:30 +10:00
Peter Hutterer
8cd5cad1c1 meson: add option for internal event debugging
These have been behind #if 0 for ages but there are more to come, let's
make it possible to toggle those on/off with a meson option.

This is an option that must not be used in a release build, it will leak
key codes to the logs.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
2025-03-13 06:13:38 +00:00
Peter Hutterer
6c3c2e99c0 libinput: use the shared event printing for debugging events
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
2025-03-13 06:13:38 +00:00
Peter Hutterer
9907cf2eeb Move the event printing out into a utility
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
2025-03-13 06:13:38 +00:00
Peter Hutterer
1dd8a8965c tools/debug-events: make the print_ functions return the printed string
Two advantages here: fewer actual printf() calls making the output
slightly more coherent if there are other things writing to stdout but
also better re-usability since we can now move the print functions to
shared code.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
2025-03-13 06:13:38 +00:00
Peter Hutterer
99ceda011c util: add strdup_printf helper functions
More straightforward than using xasprintf

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
2025-03-13 06:13:38 +00:00
Peter Hutterer
67428b64e0 doc: fix two duplicated references
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1155>
2025-03-12 11:43:25 +10:00
Peter Hutterer
48cd4c7287 tablet: track pressure ranges per tablet
Tablets may have different ABS_PRESSURE ranges with the oldest tablets
having 1k pressure range, then 2k, and the newer ones 8k.

If the same tool is used across two tablets with different ABS_PRESSURE
ranges, the first tablet in proximity calculated the range on where to
normalize to. As a result the other tablet either couldn't reach the
full pressure (2k pressure first, then 8k) or the full pressure range
was reached at a fraction of the full range (8k pressure first, then
2k).

Fix this by moving the threshold handling into a separate struct and
hardcoding up to 4 of those per tool. That is 2 more than the more
complicated setups I've heard of (and this only applies to tracking the
same stylus across those tablets anyway).

This duplicates the pressure offset heuristics but that's easier than
figuring out how to handle heuristics across potentially two tablets.

The range configuration is left as-is on the assumption that this one is
per tool, not per tablet.

Closes #1089

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1143>
2025-02-25 05:18:58 +00:00
satrmb
3a60c47e33 test: add optional value names to parametrized tests
Only implemented for i32 values so far, used for enums and enum-like constants,
replaces a runtime lookup from stringly-typed parameters.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1141>
2025-02-20 08:18:48 +01:00
Peter Hutterer
bf3a67de6c gestures: if 3fg drag fingers are in a nice position, start dragging
Similar to the condition just north of here, if we have 3 fingers in a
roughly linear line and 3fg dragging is enabled, assume we're actually
trying to drag. This reduces the minimum movement otherwise required
to detect the type of gesture.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
1d9e307e2b touchpad: implement support for three-finger drag
Exposed via new configuration option this enables 3 and 4 finger
dragging on touchpads. When enabled a 3/4 finger swipe
gesture is actually a button down + motion + button up sequence.

If tapping is disabled the drag starts immediately, if tapping is
enabled the drag starts after the tap timeout/motion so we can distinguish
between a tap and a drag.

When fingers are released:
- if two fingers remain -> keep dragging
- if one finger remains -> release drag, switch to pointer motion

When 3/4 fingers are set down immediately after releasing all fingers
the drag continues, similar to the tap drag lock feature. This drag lock
is not currently configurable.

This matches the macos behavior for the same feature.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
ae86d8b1b6 gestures: disambiguate between a tap timeout and a hold timeout
Where the tapping code calls into the timeout function make sure we have
a separate event for this. This way we know whether the current gesture
event is caused by the hold timeout or something else.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
659b49b3a3 gestures: localize a set of variables better
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
16a8c1d06c gestures: rename a helper function
has_started() is a bit misleading here, this merely decides whether we
should delay any finger changes or not.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
c73fc78407 touchpad: cancel any ongoing gesture if we're about to send a button
This shouldn't have any effect in the current setup as there is
"coincidentally" no overlap between the two state machines so this is
effectively a noop.

Nonetheless, if we're about to send a tap button event we cannot be in
any other gesture than tapping so all swipe/pinch/holds need to be
cancelled.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1042>
2025-02-18 06:44:01 +00:00
Peter Hutterer
9ae15c6a45 pad: be more robust to kernel bugs of multiple EV_ABS
This is a workaround for a kernel bug with the Wacom Mobile Studio Pro
13: this device sends erroneous ABS_WHEEL events when pressing
buttons:

  - evdev:
    - [  0,      0,   1, 256,       1] # EV_KEY / BTN_0                     1
    - [  0,      0,   3,   8,      17] # EV_ABS / ABS_WHEEL                17 (+17)
    - [  0,      0,   3,   8,       0] # EV_ABS / ABS_WHEEL                 0 (-17)
    - [  0,      0,   3,  40,      15] # EV_ABS / ABS_MISC                 15 (+15)
    - [  0,      0,   0,   0,       0] # ------------ SYN_REPORT (0) ---------- +0ms

ABS_WHEEL to 17 then to 0 in the same frame. We should (and do) treat this
as a zero event and drop the 17 to the floor. Alas, we then generate a
ring event for the zero value despite our current value being zero
anyway. This again causes confusing behavior.

This is simple enough to work around, at least until the kernel is fixed
but also to prevent this happening in the future: warn if we get
multiple events and if so and the later event is zero, undo the axis
change state.

Closes: #1081
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1136>
2025-02-12 03:58:23 +00:00
Peter Hutterer
86b9142a02 test: highlight the interesting part of the backtrace
This makes it easier to immediately see where things are breaking since
the full backtrace has >70% noise.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1124>
2025-01-20 11:30:01 +00:00
Peter Hutterer
2c0c4a6516 Replace strneq() with hardcoded lengths with strstartswith()
Slightly less efficient but easier to read and it's not possible to
accidentally provide the wrong length. Plus it handles null pointers
correctly so get to skip the checks (which weren't needed for strneq()
either, but still).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1121>
2025-01-20 10:29:47 +00:00
Kirill Primak
00bc910df7 tablet: add missing event types in tool/pad event docs
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1126>
2025-01-20 10:08:36 +00:00
Peter Hutterer
1d8f2903ed tablet: always unset the various statuses if we're leaving proximity
The previous invocation was gated behind a TABLET_OUT_OF_AREA check
resulting in a nonresponsive tool when the tablet was moved out of
proximity outside the tablet area and the area was changed.

Move the actual status bit changes up into tablet_flush()
so we unconditionally set those.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1118>
2025-01-20 09:54:32 +00:00
Peter Hutterer
c3bf478d41 util: add truefalse and yesno macros for easy string conversion
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1118>
2025-01-20 09:54:32 +00:00
Peter Hutterer
530ca423a7 Improve the event queuing debugging a bit
Print a bit more information if this ifdef is disabled for
debugging, in this case for button events. That's all
I need for now, we can extend later.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1122>
2025-01-09 11:36:32 +10:00
Peter Hutterer
45389468a7 evdev: print the EV_SYN with better alignment to other messages
This affects the debugging output only and it's invocation is if 0 by
default.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1117>
2025-01-07 13:04:30 +10:00
Peter Hutterer
1e445f3f84 test: implement support for parametrizing tests
litest supports ranged tests but they are not enough, doubly so with
tests where we want to parametrize across multiple options.

This patch adds support for just that, in clunky C style.
The typical invocation for a test is by giving the test parameter
a name, a number of values and then the values themselves:

	struct litest_parameters *params = litest_parameters_new("axis", 's', 2, "ABS_X", "ABS_Y",
	                                                         "enabled", 'b', '2', true, false,
	                                                         "number", 'u', '2', 10, 11,
	                                                         NULL);
	litest_add_parametrized(sometest, LITEST_ANY, LITEST_ANY, params);
	litest_parameters_unref(params);

Currently supported are u (uint32), i (int32), d (double), b (bool),
c (char) and s (string).

In the test itself, the `test_env->params` variable is available and
retrieval of the parameters works like this:

	const char *axis;
	uint32_t number;
	bool enabled;
	litest_test_param_fetch(test_env->params,
	                        "axis", &axis,
	                        "enabled", &enabled,
	                        "number", &number,
	                        NULL);

Note that since this is an effectively internal test-suite only
functionality we don't do type-checking here, it's assumed that if you
write the code to pass parameters into a test you remember the type
of said params when you write the test code.

Because we don't have hashmaps or anything useful other than lists the
implementation is a bit clunky: we copy the parameter into the test
during litest_add_*, permutate it for our test list which gives us yet
another linked list C struct, and finally copy the actual value into
the test and test environment as it's executed. Not pretty, but it
works.

A few tests are switched as simple demonstration. The name of the
test has the parameters with their names and values appended now, e.g.:
   "pointer:pointer_scroll_wheel_hires_send_only_lores:ms-surface-cover:axis:ABS_X"
   "pointer:pointer_motion_relative_min_decel:mouse-roccat:direction:NW"

Filtering by parameters can be done via globs of their string
representation:
   libinput-test-suite --filter-params="axis:ABS_*,enabled:true,number:10*"

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2025-01-07 02:02:37 +00:00
Peter Hutterer
da296c9976 util: Add a multivalue special type
A stripped down version of e.g GVariant that's enough for the few
parameter types we need to support.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2025-01-07 02:02:37 +00:00
Peter Hutterer
9ac040f72a util: add etrace to trace to stderr
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1116>
2025-01-07 11:40:00 +10:00
Peter Hutterer
b1f804c5f1 Fix two scan-build warnings that appear on F41
../../../src/util-files.h:61:3: warning: The 1st argument to 'close' is <= -2 but should be >= -1 [unix.StdCLibraryFunctions]
   61 |                 close(*fd);

 ../../../test/test-quirks.c:66:8: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker]
   66 |                 rc = fputs(file_content, fp);

The latter is bogus because we have a litest_assert for this but
somehow this is ignored, so... shrug.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1111>
2024-12-23 07:17:31 +00:00
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