Commit graph

2726 commits

Author SHA1 Message Date
Peter Hutterer
e53c2141b3 util: add a free_clear() helper to reset after free
Same as e.g. g_clear_pointer(). Switch a number of obvious call sites
over to use this, the rest will come over time.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1472>
2026-04-24 00:24:24 +00:00
Peter Hutterer
c276c9579e plugin: use safe_strdup() instead of strdup()
safe_strdup() handles NULL correctly instead of just blowing up. This
shouldn't matter because without a name our plugins won't get here but
let's do this anwyay.

Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1467>
2026-04-22 04:53:13 +00:00
Peter Hutterer
d97983ee5e util: use lstat() instead of stat() in rmdir_r to prevent symlink attacks
stat() follows symbolic links which is definitely something we don't
want. If an attacker can place a symlink inside a directory being
recursively deleted (e.g. a temporary directory), stat() will report the
type of the symlink's target rather than the symlink itself. If the
target is a directory, rmdir_r() will follow the symlink and recursively
delete the target directory's contents outside the intended directory
tree.

This has no real effect, this is only used in the test suite.

Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1467>
2026-04-22 04:53:13 +00:00
Peter Hutterer
b87532dfb5 touchpad: replace sprintf strv_join in the touch state debugging
This is purely to make Claude happy, the function is ifdef'd out and to
actually hit the limit we'd need more than ~25 slots active.

Anyway, the strv helpers make for much nicer code anyway.

Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1467>
2026-04-22 04:53:13 +00:00
Peter Hutterer
75d4acfe94 util: allow for 'e' in safe_atod strings
1.5e2 is a valid string, so let's parse those.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1467>
2026-04-22 04:53:13 +00:00
Peter Hutterer
0e4492155f doc: add HOLD_END to libinput_event_gesture_get_cancelled() doc
The implementation accepts LIBINPUT_EVENT_GESTURE_HOLD_END in
require_event_type() but the API documentation only listed SWIPE_END
and PINCH_END. This was likely missed when hold gesture support was
added.

Co-authored-by: Claude <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1469>
2026-04-20 01:10:05 +00:00
Peter Hutterer
f854eb0515 doc: fix typos and misspellings across documentation
Co-authored-by: Claude <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1469>
2026-04-20 01:10:05 +00:00
Peter Hutterer
fdd43a4fcd touchpad: time the 3fg fast swipe timeout from the initial contact
We differ between a fast 3fg swipe and a 3fg drag based on whether we
move 5mm within 80ms of contact. Alas, the code started the timeout once
we had enough motion, not on initial contact.

Three fingers down, then resting for >80ms, then moving 5mm within the
subsequent 80ms would thus trigger a fast swipe because the timer wasn't
set until sufficient movement happened. Fix this by setting the timer
based on the initial touch point's time. This requires potentially
setting a negative timer to avoid duplicating parts of the state
machine.

Closes #1266

Fixes: fe1d44637f ("touchpad: add support for fast swipe when 3fg drag is enabled")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1466>
2026-04-17 02:32:50 +00:00
Peter Hutterer
2bea0f3e4e tablet: extend touch arbitration rect to cover full tablet height
The arbitration rectangle previously only covered a region from 100mm
above the pen tip to 150mm below it (250mm total). This let a few
unintentional touches through such as when some of the fingers are
extended while using the pen. Likewise, a large hand could fall below
the bottom edge of the rectangle.

Change the rect to span the full height and width of the tablet while
keeping the same horizontal logic (200mm wide, starting 20mm from the
pen tip toward the hand side). Simplify a few things too, there is no
need for clipping the rect.

Related: #1276
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1463>
2026-04-16 05:10:53 +00:00
Peter Hutterer
5f29257569 util: use zalloc in stringbuf
zalloc() aborts on allocation failure and it's what we use everywhere
else.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1465>
2026-04-16 04:55:23 +00:00
Peter Hutterer
2ea3fb1d13 tablet-pad: use strdup_printf in sysfs path construction
This simplifies the code and means we don't have to deal with snprintf
return values to ensure we're not truncating.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1465>
2026-04-16 04:55:23 +00:00
Peter Hutterer
9d8a8b4530 util: use snprintf for PID formatting in backtrace helper
Use snprintf to make analyziers happier and bump the buffer size to 16.
That's way larger than we'll need given the kernel's PID_MAX_LIMIT
(4194304) but it doesn't cost us anything.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1465>
2026-04-16 04:55:23 +00:00
Peter Hutterer
e32202eeae util: check for NULL on realloc in _infmask_ensure_size
And abort if that ever happens because it really shouldn't.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1465>
2026-04-16 04:55:23 +00:00
Peter Hutterer
aa04f67b1c plugin: guard against unsigned underflow in plugin_has_mask
nevents should never be zero but let's prevent against an underflow, if
only to make the analyzers happy.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1465>
2026-04-16 04:55:23 +00:00
Peter Hutterer
356c498fd4 lua: force text mode for loading plugins
luaL_loadfile() by default allows for both text files and precompiled
lua files. Precompiled files are not verified on load allowing for a
sandbox escape.

CVE-2026-35093

Fixes: #1271

Found-by: Koen Tange <koen@monokles.eu>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1459>
2026-04-01 23:53:12 +00:00
Peter Hutterer
45dfd0f030 lua: separate the API from the metatables
Previously we had one vtable for the libinputplugin and EvdevDevice
objects. This allowed plugins to call __gc(), a decidedly internal
method.

This fixes a use-after-free: A plugin that called EvdevDevice::__gc()
frees the plugin's copy of device->name but leaves the pointer in-place,
a subsequent call will thus cause a UAF read.

Fix this by separating what is the object's metatable from the public
methods that are accessible to a plugin.

CVE-2026-35094

Fixes: #1272

Found-by: Koen Tange <koen@monokles.eu>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1459>
2026-04-01 23:53:12 +00:00
Peter Hutterer
9baccdf44c touchpad: support automatic drag-lock when releasing at the edge
If drag-lock is disabled but we're in a tap-and-drag state and the
finger is released near the edge (within 5mm), enable automatic drag
lock for 400ms.  This allows a user to quickly reset the finger and
continue with the drag.

The 400ms is a randomly guessed timeout - if you're using tap-and-drag
without draglock, finger dexterity should be high enough that resetting
the single finger can be done quickly but it's also short enough to not
make the occasional delayed button be painful in day-to-day use.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1447>
2026-03-24 05:50:24 +00:00
Peter Hutterer
166201d9fc util: fix remaininig usec computation on 32 bits
Follow-up from commit dcbfbc4cf1 ("util: fix usec computation on 32 bits")
which didn't fix all instances, make this consistent.

Fixes: dcbfbc4cf1 ("util: fix usec computation on 32 bits")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1453>
2026-03-24 05:24:35 +00:00
Peter Hutterer
7d15503b45 evdev: fix rel axis disabling on accelerometers
Copy/paste caused only the abs axes being disabled (REL_X == ABS_X,
etc. so the EV_REL bits had no effect).

Found-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1453>
2026-03-24 05:24:35 +00:00
Peter Hutterer
2dc491de1f Fix various typos
Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1452>
2026-03-24 05:09:07 +00:00
Peter Hutterer
ef9624a16b evdev: store the SYN_REPORT value in the frame
If the SYN_REPORT has a value of nonzero we need to keep that value in
the frame - our upper layers rely on this to detect repeat frames.

Closes #1261

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1449>
2026-03-19 00:09:30 +00:00
GKraats
dcbfbc4cf1 util: fix usec computation on 32 bits
Enforce the needed 64-bit computing on 32 bits.

Signed-off-by: GKraats <vd.kraats@hccnet.nl>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1446>
2026-03-18 00:25:48 +00:00
Peter Hutterer
cd9d6c66fd tablet: fix eraser button get_default_mode/get_default_button return values
Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1444>
2026-03-17 00:46:45 +00:00
Ilya Kamenko
8dd25ece10 Fold hold-to-scroll into existing scroll button lock mode
Instead of adding a new ENABLED_HOLD enum value, modify the existing
ENABLED lock mode so that hold+scroll+release doesn't engage the lock.

Add a 500ms grace period: if the button was held and used to scroll for
longer than 500ms, releasing the button does not engage the lock
(temporary scroll). If released within 500ms (e.g. shaky hands
triggering accidental motion), the lock still engages as before.

This fixes the unintuitive behavior where the lock engages even after
actively scrolling, without requiring new API surface.

Closes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/1259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1435>
2026-03-10 23:12:25 +00:00
David Santamaría Rogado
819e943ab0 evdev: use udev's ID_INTEGRATION
Now we have in udev the ID_INTEGRATION propery that tells us if a device
is internal or external, use it while still allow hwdb and quirks to
override it.

In the future is possible that we could remove quirks for keyboards
integration and hwdb for touchpads and joysticks integration.

Signed-off-by: David Santamaría Rogado <howl.nsp@gmail.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1429>
2026-03-10 02:27:36 +00:00
Peter Hutterer
7726350420 tablet: allow for the eraser button to be any button
The previous restriction was BTN_STYLUS* or any button the pen
advertises. This is too restrictive - it works well enough for any pen
with less than 3 buttons (BTN_STYLUS3 is always available on those) but
otherwise it cannot work. A 3-button pen may not advertise any other
buttons, leaving us with the eraser button being a duplicate button. And
events cannot be distinquished between eraser button or real button.

Open up the configuration to effectively any BTN_ event code.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1436>
2026-03-09 01:14:21 +00:00
Peter Hutterer
cdcb827365 Fix the evdev_usage_is_button check for the BTN_STYLUS group
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1436>
2026-03-09 01:14:21 +00:00
Peter Hutterer
0a3ecbea24 tablet: fix missing linebreak after an error message
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1436>
2026-03-09 01:14:21 +00:00
David Santamaría Rogado
a86b8a0008 doc: list-quirks should be quirks list
while at it replace also a code comment in the same line.

Signed-off-by: David Santamaría Rogado <howl.nsp@gmail.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1432>
2026-02-20 19:56:46 +01:00
Peter Hutterer
e78f4f689d util: add guards for the etrace/trace defines
This file is really useful on its own for other projects if
auto-included via export CFLAGS="$CFLAGS -include /path/to/file.h"
However, that causes compiler warnings, let's add indef checks for this
as a quick workaround.

Since these three come as a set and are only used for debugging, we can
ifndef them all in one go rather than individually.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1423>
2026-02-04 11:18:54 +10:00
Peter Hutterer
ad89a83ae6 tablet: ignore the tablet tool name if it's a generic tool
libwacom has generic pens that are used for devices that don't have tool
ids. Let's ignore the names for those pens since they're just made up
names anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1422>
2026-02-03 23:27:14 +00:00
Peter Hutterer
6d514ee6fa touchpad: add get_default_timeout for dwt and dwtp
I doubt this is really needed but our convention for all config options
is set/get/get_default so let's stick with that.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1421>
2026-02-03 13:01:59 +10:00
David Santamaría Rogado
6f79797308 test: recover external usb keyboard touchpad combo
This recovers the testing that a USB keyboard plus touchpad combo both
set as external, only its own keyboard should affect to DWT that was
removed when Acer Hawaii combo was set as internal.

This is uncommon as usb touchpads nowadays are set as internal, but,
perhaps someone that adds a quirk for a really external combo also adds
in udev's hwdb the external integration for the touchpad, or perhaps we
should set the integration to external when AttrTPKComboLayout=below is
used for the touchpad.

The issue is if the touchpad is leave as internal every keyboard affect
DWT, not only the one that belongs to its combo.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1415>
2026-02-02 09:52:08 +00:00
Michał Chojnowski
b58d5a165b tablet: fix handling of AttrPressureRange quirk
tablet_get_quirked_pressure_thresholds() is wrong:
the pressure thresholds for tip press and tip release are swapped around.
This seems to be a regression introduced in commit 4bc27543e9.

This prevents AttrPressureRange from working as intended for tablets,
and causes weird things to happen if it's set.
(For example, when pressure is in the range between
the intended release threshold and the intended press threshold,
the "pressed" status flip-flops between 0 and 1 every frame).

Fix that.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1420>
2026-02-02 08:41:24 +01:00
Peter Hutterer
fe1d44637f touchpad: add support for fast swipe when 3fg drag is enabled
This adds a movement threshold (5mm) and a timeout (80ms) to the 3fg
drag gesture. On 3fg down with 3fg drag enabled we immediately send a
GESTURE_SWIPE event. After the timeout expires we check the movement of
the fingers - if it is below the threshold cancel the swipe and hold a
button down (i.e. a 3fg drag). Otherwise, continue with this being a
swipe.

This allows for swipe gestures to be used while 3fg drag is enabled.

Above applies the same way for 4fg with 4fg drag enabled.
Thresholds selected using the "yeah, that seems about alright" method,
intentionally quite low because we assume that users that enable 3fg
drag prefer 3fg dragging over swipe.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1410>
2026-02-02 06:44:48 +00:00
Peter Hutterer
5b7b8f1bb2 gestures: remove two empty helper functions
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1410>
2026-02-02 06:44:48 +00:00
Peter Hutterer
33b1d87c08 touchpad: don't disable on external mice until we see an event
Instead of disabling the touchpad as soon as a mouse is seen by
libinput, disable it as soon as a mouse sends an actual event. This
works around the current issues with many devices (touchpads and
keyboards alike) announcing a HID Mouse Application Collection which
gets its own event node in the kernel. That event node usually just sits
there and does nothing but its mere presence disabled the touchpad.

Let's change this and instead only disable once we see an event.

Closes: #1104
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1414>
2026-01-28 00:43:37 +00:00
Peter Hutterer
e161abdc19 evdev: rename evdev_paired_keyboard to evdev_paired_device
We'll be using this struct for other devices than keyboards.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1414>
2026-01-28 00:43:36 +00:00
Peter Hutterer
86f19a0978 lua: install a timeout hook before any pcalls to prevent infinite loops
If a lua pcall takes longer than one second, kill the plugin.

How often to call the timeout handler is a trade-off but we err on the
side of "possibly too high" since the overwhelmingly vast majority of
plugins will never trigger it anyway.

Gemini suggests that Lua 5.4 can do ~500k ops per second for string
concat (the slowest listed), Claude suggests 1 to 10 million ops per
second. The test in this patch on my 4y old cheap desktop runs the
timeout hook roughly every 37ms. Any normal plugin will be well and
truly done with its work by then.

Closes: #1245
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1416>
2026-01-27 00:02:15 +00:00
Peter Hutterer
dee2d38476 Add libinput_tablet_tool_get_name() for the tool's specific name
If the tool has a name let's provide that to the caller. We have it
easily accessible so let's export it to make everyone's life easier. The
name is provided by libwacom, there is no need for us
to even copy that value since we don't need it ourselves.

Note that at this point effectively only (some) Wacom devices have
meaningful names. Virtually all non-wacom devices will use a generic
tool and even the built-in Wacoms will largely just say "AES Pen".

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1399>
2026-01-14 16:44:01 +10:00
Peter Hutterer
6b4d1905b6 plugin: always disable wheel debouncing on request
The WHEEL_STATE_NONE check was effectively always false:
- if we didn't receive any event yet, wheel_maybe_disable() wasn't
  called in any code path
- if we did receive a scroll event, the wheel state was either
  WHEEL_STATE_SCROLLING or WHEEL_STATE_ACCUMULATING_SCROLL

Fix this two-pronged: remove the check for WHEEL_STATE_NONE but also
immediately call disable when we disable the feature. We don't carry
enough state in this plugin to really worry about the device being in
a fully neutral state (and realistically the vast majority of use-cases
will likely disable wheel debouncing on new device anyway).

Closes #1241

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1408>
2026-01-13 21:52:52 +00:00
Peter Hutterer
731d4452c3 meson: revamp the debug build detection for the builddir lookup
Ifdef out any special behavior we want so we no longer leak this via
strings in the resulting binary. Ideally we want the compile to fail for
anything missed rather than surprising behavior when we try to access
files in the build directory.

Closes: #1230
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1396>
2026-01-10 10:39:21 +00:00
Peter Hutterer
0412fb3d44 pad: fix missing newline for mode group error messages
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1380>
2025-12-17 14:37:59 +10:00
Peter Hutterer
a202ed6115 Use a newtype usec_t for timestamps for better type-safety
This avoids mixing up milliseconds and usec, both by failing if
we're providing just a number somewhere we expect usecs and also
by making the API blindingly obvious that we're in usecs now.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1373>
2025-12-12 04:15:15 +00:00
Peter Hutterer
c0c809aaa1 util: fix documentation issues for newtypes
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1373>
2025-12-12 04:15:15 +00:00
Peter Hutterer
e8dfc3bfd6 util: make the newtype comparision functions return bool
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1373>
2025-12-12 04:15:15 +00:00
Sicelo A. Mhlongo
b3f7b4b1ea evdev: add support for SW_KEYPAD_SLIDE
A few devices have a keyboard/keypad which can be slid under the device,
leaving the device with only touch-based interaction. The corresponding kernel
event is reported as SW_KEYPAD_SLIDE [0]. Implement support in libinput.

Since the position of the switch varies across devices, it cannot always be
certain whether the keypad is usable when the switch is in the set position.
Therefore, do not automatically disable the keyboard.

[0] e68d80b13b/include/linux/linux/input-event-codes.h (L885)

Closes: #1069
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1242>
2025-12-11 13:28:41 +02:00
Peter Hutterer
0285001272 touchpad: make the dwt/dwtp timeout inclusive min/max
This makes it easier in callers that don't really differ between
inclusive and exclusive and makes the visualization in UIs a bit
nicer to look at too.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1377>
2025-12-10 03:07:36 +00:00
Peter Hutterer
bde6d07d57 quirks: replace ModelPressurepad with setting INPUT_PROP_PRESSUREPAD
This is the more generic approach and doesn't require us to have any
specific implementation in libinput itself.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1374>
2025-12-09 06:07:01 +00:00
Peter Hutterer
38b5c2e0cc touchpad: add configurable timeouts to disable-while-trackpointing
Same motivation as in commit
"touchpad: add configurable timeouts to disable-while-typing"

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1372>
2025-12-02 09:24:15 +10:00