Commit graph

654 commits

Author SHA1 Message Date
Peter Hutterer
b481170918 evdev: use autofree for the sysname
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1193>
2025-04-24 15:31:19 +10:00
Peter Hutterer
cefab21e42 util: add an _unused_ macro and replace LIBINPUT_UNUSED
For annotating intentionally used variables it needs to be a bit
shorter, so let's replace the current one which was aimed at functions.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
546debe926 Remove empty lines between closing braces
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1190>
2025-04-16 11:44:09 +10: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
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
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
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
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
fe3175748a evdev: don't return a size for 0-1 axes
Tablet pads historically need to have ABS_X/Y to be detected as tablets
but their min/max values are 0 and 1. Let's not return a size for those.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1004>
2024-05-27 14:51:23 +10:00
José Expósito
a2515fc3f6 evdev: log the right mouse wheel angle
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1002>
2024-05-18 18:55:29 +02:00
Martin Rys
7c91e3539c Add definitions for LIBINPUT_LED_COMPOSE and LIBINPUT_LED_KANA
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/990>
2024-04-28 23:59:14 +00:00
José Expósito
a43f1edbfe Add libinput_device_get_id_bustype()
Allow to get the device bus type ID in addition to its vid and pid.

Closes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/975
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/977>
2024-02-28 22:49:29 +00:00
Peter Hutterer
11a7de7640 evdev: default tablets to allow for rotation
If libwacom is disabled or there is no .tablet file in libwacom for this
device yet, default to enabling a left-handed setting. Otherwise the
tablet may not be usable.

See https://github.com/linuxwacom/libwacom/issues/616
2024-01-03 12:20:16 +10:00
José Expósito
bf59231f23 evdev: Fix uninitialized variable
Due to a patch pushed accidentally to main, the `key_count` variable is
uninitialized in the `evdev_log_bug_libinput` code path:

  ../src/evdev.c:148:12: error: ‘key_count’ may be used uninitialized [-Werror=maybe-uninitialized]
    148 |         if (key_count > 32) {
        |            ^
  ../src/evdev.c: In function ‘evdev_pointer_post_button’:
  ../src/evdev.c:132:13: note: ‘key_count’ was declared here
    132 |         int key_count;
        |             ^~~~~~~~~

Fixes commit bb1e4a493f ("evdev: Log bug when releasing key with count 0")
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2023-09-01 10:07:20 +02:00
José Expósito
bb1e4a493f evdev: Log bug when releasing key with count 0
libinput keeps an internal key count. It is increased by 1 when the key
is pressed and decreased by one when the key is released.

The count should never be negative, however a user found an issue while
running Sway and hit an assert.

Replace the assert with a log to avoid the crash.

Fix https://gitlab.freedesktop.org/libinput/libinput/-/issues/928
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2023-08-31 16:46:46 +02: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
Hector Martin
d61d385951 evdev: Enable natural scrolling by default on Apple
As suggested by the comment itself. I think most users expect this.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-04-06 15:30:14 +09:00
Yinon Burgansky
5324f425a1 Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.

This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.

regular filter is Motion type.
constant filter is Fallback type.

This allows possible expansion of new movement types for the
different devices.

The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.

The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.

The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.

Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-01-17 01:46:17 +00:00
Peter Hutterer
38dbfe41a1 evdev: only read the trackpoint multiplier on trackpoints
Check the tag before we read any multiplier quirks. And don't bother
reading the DPI for trackpoints either because it doesn't make sense for
those devices.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-05 14:38:25 +10:00
Peter Hutterer
a7e4cbc212 quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.

Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:

  [first]
  AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE

  [second]
  AttrEventCodeDisable=BTN_RIGHT

  [third]
  AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;

Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.

Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.

Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.

For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
  enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
  recent one to the existing entry (instead of creating a new entry in
  the array). This way we have all entries that match and in-order of
  precedence - i.e. we can process them left-to-right to end up
  with the right state.

Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-28 08:25:41 +10:00
Peter Hutterer
a5dd45e8ce Remove duplicate empty lines in our source
We only touch src and tools, imported headers from include are not ours
to change.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-25 10:08:20 +10:00
Peter Hutterer
ad71c74885 filter: add a flat trackpoint accel
Previously, trackpoints got assigned the normal flat profile which does not
accommodate for the trackpoint magic multiplier *and* had a config range
that was too small if you take the multiplire indo account anyway.

Fix this by adding a trackpoint-specific flat accel that has a wider
configuration range and take sthe magic multiplier into account.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-09-08 09:03:15 +10:00
Peter Hutterer
c16844d1b2 evdev: remove duplicate "device is a switch" message
We log this a few lines south of here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-08-23 13:23:37 +10:00
Peter Hutterer
368b12ad45 evdev: fix a tab vs space indentation issue
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-07-12 10:00:24 +00:00
Alexander Courtis
e0813f4825 AttrLidSwitchReliability quirk default unreliable->reliable 2022-04-26 01:55:22 +00:00
Peter Hutterer
a423d7d326 evdev: strip the device name of format directives
This fixes a format string vulnerabilty.

evdev_log_message() composes a format string consisting of a fixed
prefix (including the rendered device name) and the passed-in format
buffer. This format string is then passed with the arguments to the
actual log handler, which usually and eventually ends up being printf.

If the device name contains a printf-style format directive, these ended
up in the format string and thus get interpreted correctly, e.g. for a
device "Foo%sBar" the log message vs printf invocation ends up being:
  evdev_log_message(device, "some message %s", "some argument");
  printf("event9 - Foo%sBar: some message %s", "some argument");

This can enable an attacker to execute malicious code with the
privileges of the process using libinput.

To exploit this, an attacker needs to be able to create a kernel device
with a malicious name, e.g. through /dev/uinput or a Bluetooth device.

To fix this, convert any potential format directives in the device name
by duplicating percentages.

Pre-rendering the device to avoid the issue altogether would be nicer
but the current log level hooks do not easily allow for this. The device
name is the only user-controlled part of the format string.

A second potential issue is the sysname of the device which is also
sanitized.

This issue was found by Albin Eldstål-Ahrens and Benjamin Svensson from
Assured AB, and independently by Lukas Lamster.

Fixes #752

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-04-20 13:32:31 +10:00
José Expósito
5664007013 evdev: modernize variable declaration in evdev_device_is_joystick_or_gamepad
Declare the variables used to keep track of joystick buttons and
keyboard keys right before they are used for better readability and
consistency.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-03-02 08:35:23 +01:00
José Expósito
ea568a7bcb evdev: check well-known keyboard keys on joystick/gamepad detection
Create a list of well-known keyboard keys containing one the most
representative key(s) of a group.
The rule is based on the assumption that if the representative key is
present, other keys of the group should be present as well.

The groups are:

 - Modifiers group: KEY_LEFTCTRL.
 - Character group: KEY_CAPSLOCK.
 - Numeric group: KEY_NUMLOCK.
 - Editing keys: KEY_INSERT.
 - Multimedia keys: KEY_MUTE, KEY_CALC, KEY_FILE, KEY_MAIL,
   KEY_PLAYPAUSE and KEY_BRIGHTNESSDOWN.

When 4 of these keys are found, the device is tagged as a keyboard.

Fix #745

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-03-02 08:21:49 +01:00
Peter Hutterer
5a568cfaf0 evdev: silence a clang compiler warning
Signed-off-by:Peter Hutterer <peter.hutterer@who-t.net>
2021-12-22 15:07:56 +10:00
Peter Hutterer
a1e9150210 timer: only warn about timer expiry issues when we're more than 20ms behind
The most common trigger for this is the debouncing timer which is a mere
12ms and is effectively unavoidable, virtually every caller will
trigger those messages at some point.

Let's add a grace period of 20ms below which we don't log this message
to avoid logspam. And in the process, bump the equivalent warning
message up to 20ms as well.

Related #711

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-12-07 11:54:08 +10:00
José Expósito
8dd8786c48 evdev: improve joystick and gamepad detection
The EVDEV_UDEV_TAG_JOYSTICK is set when a joystick or gamepad button
is found. However, it can not be used to identify joysticks or
gamepads because there are keyboards that also have it. Even worse,
many joysticks also map KEY_* and thus are tagged as keyboards.

In order to be able to detect joysticks and gamepads and
differentiate them from keyboards, apply the following rules:

  1. The device is tagged as joystick but not as tablet
  2. It has at least 2 joystick buttons
  3. It doesn't have 10 keyboard keys

Fix #701
Fix #415
Fix #703

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-12-03 00:20:47 +00:00
José Expósito
a694a06b92 evdev: refactor joystick/gamepad detection
Move the logic to detect joysticks and gamepads to its own function.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-12-03 00:20:47 +00:00
Eduardo de Souza Cruz
f5c20fe6b3 evdev: avoid usage of bogus BTN_FORWARD name
Signed-off-by: Eduardo Cruz <eduardo.cruz@kdemail.net>
2021-10-11 17:43:26 -03:00
Eduardo de Souza Cruz
34bab6e15e evdev: disable button scroll timeout for extra mouse buttons
Signed-off-by: Eduardo Cruz <eduardo.cruz@kdemail.net>
2021-10-10 23:32:36 +00:00
José Expósito
ceda09e87b evdev: v120 scroll: invert horizontal scrolling quirk
When required, invert horizontal scrolling in evdev_notify_axis_wheel
following the QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING quirk.

Fix #669

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-09-21 19:21:03 +02:00
José Expósito
dbcb003c5e util: add a function to parse bool properties
Move the logic used to parse boolean quirks and udev flags to a common
function in utils.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-09-12 21:16:32 +00:00
Peter Hutterer
6bb02aaf30 High-resolution scroll wheel support
Starting with kernel v5.0 two new axes are available for high-resolution wheel
scrolling: REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES. Both axes send data in
fractions of 120 where each multiple of 120 amounts to one logical scroll
event. Fractions of 120 indicate a wheel movement less than one detent.

This commit adds a new API for scroll events. Three new event types that encode
the axis source in the event type name and a new API to get a normalized-to-120
value that also used by Windows and the kernel (each multiple of 120 represents
a logical scroll click).

This addresses a main shortcoming with the existing API - it was unreliable to
calculate the click angle based on the axis value+discrete events and thus any
caller using the axis value alone would be left with some ambiguity. With the
v120 API it's now possible to (usually) calculate the click angle, but more
importantly it provides the simplest hw-independent way of scrolling by a
click or a fraction of a click.

A new event type is required, the only way to integrate the v120 value
otherwise was to start sending events with a discrete value of 0. This
would break existing xf86-input-libinput (divide by zero, fixed in 0.28.2) and
weston (general confusion). mutter, kwin are unaffected.

With the new API, the old POINTER_AXIS event are deprecated - callers should use
the new API where available and discard any POINTER_AXIS events.

Notable: REL_WHEEL/REL_HWHEEL are emulated by the kernel but there's no
guarantee that they'll come every accumulated 120 values, e.g. Logitech mice
often send events that don't add up to 120 per detent.

We use the kernel's wheel click emulation instead of doing our own.

libinput guarantees high-resolution events even on pre-5.0 kernels.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-08-31 08:45:01 +02:00
Peter Hutterer
fc70c4f862 Silence compiler warnings for -Wformat-nonliteral
In the various logging functions where we need to modify the format
argument, disable the compiler warnings. Interestingly, GCC doesn't seem
to mind those but building with clang unleashes pages of warnings.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-22 23:14:43 +00:00
Thomas Weißschuh
b7aac3c148 evdev: remove device when it is gone
This was observed when running in device mode with:
`libinput debug-events $EVENT_NODE`

When removing the monitored device, the no "device removed" message was
not shown.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-06-21 10:41:19 +00:00
Peter Hutterer
04dc67e092 evdev: don't truncate event time to 32 bits
This causes a bunch of "your system is too slow" messages in e.g. the various
gesture tests.

Fixes 95a72990
Fixes #601

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-09 10:14:47 +10:00
Peter Hutterer
95a72990ad evdev: don't check the event time if it's higher than the dispatch time
The dispatch time is taken during libinput_dispatch(), i.e. at the beginning
of an event sequence. We always read all events off the device, so where
events come in while we're inside the main dispatch loop, our event time may
be later than the saved dispatch_time. This causes an uint underflow and our
tdelta > 10 will be true for that case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-07 12:38:25 +10:00
Peter Hutterer
5faa3b7ae9 evdev: reduce the "your system is slow" warning to 5 per hour
Two cases where this can happen: system is currently slow and delaying events,
n which case we'll get a burst and it'll show up in the log files anyway. Or
the system is generally slow and we get these warnings all the time. In the
latter case, let's not spam the log.

Fixes #533

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-28 02:58:03 +00:00
Peter Hutterer
b925a0878b quirks: switch the models with missing buttonpad to use the new attr
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 13:35:50 +10:00
Peter Hutterer
e882bd0216 quirks: add AttrInputPropEnable and Disable
The latter requires libevdev 1.10 but since that'll take a while to filter
into our various CI systems, let's make it conditional.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 13:35:50 +10:00
Peter Hutterer
e3c4ff3898 quirks: add AttrEventCodeEnable as counterpoint to the disable one
Currently unused, but let's get this in because we may need this very soon for
broken tablets.

Enabling EV_ABS axes requires an absinfo struct - we default to a simple 0-1
axis range for those as the most generic option. Anything more custom will
need more custom treatment when we need it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 13:35:50 +10:00
Peter Hutterer
30502dee1e evdev: localize two variables during quirks handling
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 12:54:54 +10:00
Peter Hutterer
fa0c3ee388 evdev: quirks_get_tuples can deal with a NULL quirks
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 12:53:35 +10:00
Rosen Penev
467752047e
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-08-27 01:17:24 -07:00
Peter Hutterer
585dab0ae2 evdev: remove now-misleading comment
libwacom has been removing ID_INPUT_JOYSTICK for years

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 11:02:33 +10:00