Commit graph

141 commits

Author SHA1 Message Date
Peter Hutterer
2a1095924b Run clang-format over the code
This uses the .clang-format file in the follow-up commit, but committed
prior to that to ease review of said file and various integrations.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1246>
2025-07-01 16:42:44 +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
bbbe757a26 Define a set of cleanup helpers
These are all data structs that are used in libinput and the tests,
let's declare them in a shared header so we can use them everywhere.

For udev and libevdev let's use an ifdef check for a known #define
so we don't have to add those deps everywhere.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +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
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
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
02d01a53c6 util: slightly improve the trace() macro
Only one printf call instead of three, means better termination of the
color code. And auto-append the newline while we're there and use the
ANSI defines we have since added.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/984>
2024-03-18 16:25:47 +00: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
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
c4cb4da33a util: make the trace macro actually useful
This has been there for years and I never used it. Much better to convert it
to a generically useful one (i.e. one that prints red so it's easy to see) and
make it unconditional.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-04-04 21:10:40 +10:00
Peter Hutterer
c84366e85e Split utility functions into separate source files
libinput-util.h is getting a bit of a catchall bucket and it includes things
like libinput-private.h which in turn includes libwacom. This makes
libinput-util.h less useful for bits that only need e.g. the string processing
utilities.

So let's split them all up in to separate files, to be used as-needed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-09-11 12:23:04 +10:00
Peter Hutterer
9dbcc68621 test: auto-generate the udev rules
We only ever set properties in the devices, so let's make that more explicit
and auto-generate the udev rule. This way we're hopefully better protected
from the various typos that hid in those rules over the years, but also be
prepared for passing the udev property key/value pairs elsewhere.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-14 08:52:58 +10:00
Peter Hutterer
3b0f068eaf Warn if NDEBUG is defined
We rely on assert() too much for safety checks, let's not let the user disable
it without warning

Fixes #262

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-05-28 14:10:54 +10:00
Peter Hutterer
7db3233f11 Drop the AS_MASK macro, replace with bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-02-11 13:46:31 +10:00
Peter Hutterer
6bbe03a086 Add a bit() macro
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-02-11 13:46:31 +10:00
makepost
99bb0ee7cb util: fall back to strtod if no locale in libc
uClibc-ng has experimental locale support but it's incomplete and
disabled by default, for example in Hardened Gentoo.

Fixes #63
2018-12-22 19:58:16 +02:00
Peter Hutterer
981f3a47e6 quirks: add the ability to disable custom event codes/types
This is a more flexible approach than adding a model flag and the C code to
just call libevdev_disable_event_code(). There's a risk users will think this
is is a configuration API but there are some devices out there (e.g. the
Microsoft Sculpt mouse) that need a more generic solution.

Case in point: the Sculpt mouse insists on holding BTN_SIDE down at all times.
We cannot ship any quirks for that device because we only have the receiver's
generic VID/PID. So a local override is required, but we might as well make
that one generic enough to catch other devices too in the future.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-10-29 04:16:38 +00:00
Peter Hutterer
c501dabf39 util: check for < 0 explicitly in safe_atou
The previous check only worked if sizeof(long) > sizeof(int). Rather than be
fancy about it, just cast to a signed long, check for negativity and continue
based on that.

Fixes #137

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-09-13 08:32:23 +10:00
Peter Hutterer
19ea63bf23 util: tighten safe_atod parsing to only parse 'normal' numbers
We don't have a sensible use case where we want hex to double, or INF to
double, or any of that. So check the strings for invalid characters and bail
out early. Invalid characters include 'e' and whitespaces too, we don't need
those.

Small chance of things breaking: if the user-exposed calibration matrix
property was specified using hex numbers this will stop working now. I'll take
that risk.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-13 11:50:21 +10:00
Peter Hutterer
c875de4626 util: switch to a check for isnormal for safe_atod
Effectively the same check as before but this should also encompass
FP_SUBNORMAL.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-13 11:50:21 +10:00
Peter Hutterer
a508097e98 util: remove now-unused helper functions
Obsolete with the switch to the device quirks

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-02 15:51:47 +10:00
Peter Hutterer
a738ba1aed util: fix a ubsan complaint about undefined left-shift
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-26 12:06:10 +10:00
Greg V
0e03784e47 Fix include portablity (xlocale, stdlib) 2018-07-16 13:44:15 +03:00
Peter Hutterer
27f7a66de4 filter: add a trackpoint multiplier factor
Measuring the trackpoint range has not shown to be sufficient or precise
enough to be used as an ingredient for trackpoint acceleration. So let's just
switch back to a generic multiplier that we can apply to the input deltas do
undo any device-specific lack of scaling.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-11 16:04:59 +10:00
Peter Hutterer
5354226e59 util: use assert() instead of abort() for testing for size limits
This way we can send a message to the user, a simple abort() isn't informative
enough.

Fixes https://gitlab.freedesktop.org/libinput/libinput/issues/54

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-22 09:37:20 +10:00
Sergiusz Michalik
9873d68bf1 zalloc limit fix for libinput-record 2018-06-20 19:34:28 +02:00
Peter Hutterer
793c8d51e8 util: abort if we try to allocate more than a MB
The ssize_t cast upsets coverity for some reason but we can be a lot more
restrictive here anyway. Quick analysis of the zalloc calls in the test suite
show the largest allocation is 9204 bytes.

Let's put a cap on for one MB, anything above that is likely some memory
corruption and should be caught early.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Matheus Santana <embs@cin.ufpe.br>
2018-06-20 11:41:48 +10:00
Peter Hutterer
000ac14c27 Merge branch 'wip/config-files' 2018-06-11 13:45:50 +10:00
Peter Hutterer
8865d4a29d util: abort for a negative zalloc() size
Nothing in libinput needs large buffers, so if we ever get something that
large, we probably passed a negative number to zalloc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-11 13:43:40 +10:00
Peter Hutterer
be647fbb0d util: add a safe_atou() as unsigned equivalent to safe_atoi()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-08 13:47:33 +10:00
Peter Hutterer
e05fa8444a util: add a list_append()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-08 13:47:33 +10:00
Peter Hutterer
9b1b87cadd touchpad: replace the hardcoded thumb threshold with a udev prop
LIBINPUT_ATTR_THUMB_PRESSURE_THRESHOLD now determines whether we do thumb
pressure detection or not. Much better than having a hardcoded default that
may or may not be correct on any given device.

This patch is likely to break thumb detection on some touchpads, the only
property so far is to restore the default of 100 for all Lenovo Thinkpad
touchpads. More rules are needed, we'll just wait until someone shouts.

https://bugs.freedesktop.org/show_bug.cgi?id=106458

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-30 09:42:06 +10:00
Peter Hutterer
75e4ab05e4 utils: fix leak in kv_double_from_string()
We need to free 'pairs' here, do so by jumping to the error label.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-16 14:23:12 +10:00
Peter Hutterer
1e4c5a93a8 util: add a strv_join() helper function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-03 12:31:30 +10:00
Peter Hutterer
bd04826aa4 util: add a helper function to split a key-value pair string
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-26 14:48:37 +10:00
Peter Hutterer
601a18a602 Whitespace fix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-02-27 14:36:08 +10:00
Peter Hutterer
407649e599 Add helper function for time to timeval conversion
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-09-14 09:43:51 +10:00
Peter Hutterer
c44c028678 udev: move the EKR into the parent's device group
If we find an EKR, search for the usb hub of the Cintiq, then find the Cintiq
Pen (or Touch) device and assume that device's product id. This way we end up
in the same device group as the Cintiq.

Co-authored-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-09-07 08:59:20 +10:00
Peter Hutterer
635dc7d790 util: add a safe_atoi_base() function
For parsing hex numbers

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-09-07 08:59:18 +10:00
Peter Hutterer
3669fa10df trackpoint: drop handling of CONST_ACCEL and undo SENSITIVITY
This was to counteract hardware that doesn't work well out of the box,
resulting in quite different behavior across devices. Specifically, only
some trackpoints even have the sensitivity setting.

Change to take over all of the pointer acceleration on trackpoints, so we can
control the actual behavior mostly independent of the system setting. So we
drop the CONST_ACCEL parsing (which never was handled as const accel anyway)
and undo the effect that the SENSITIVITY udev property has. [1]

We take a default range at the default sensitivity and multiply it by the
proportion of the current sensitivity. This seems to be accurate enough.

[1] In the future, we should read not only the property but also the sysfs file to
make sure we're handling the right value, but for now this will do.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-20 11:53:01 +10:00
Peter Hutterer
688142c8a2 Merge branch 'wip/touchpad-apple-touch-major-v2' 2017-07-14 13:47:29 +10:00
Peter Hutterer
2e4895b888 Add safe_strdup()
Return value is either NULL or a strdup'd string, depending on the input
value.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-12 15:39:31 +10:00
Peter Hutterer
d5d6d4cd53 Abort if zalloc ever fails
There's no guarantee that libinput does the right thing if memory allocation
fails and it's such a niche case on the systems we're targeting that it just
doesn't matter. Simply abort if zalloc ever fails.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-12 10:18:07 +10:00
Peter Hutterer
ca4285de66 touchpad: add touch-size-based palm detection
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-11 12:28:28 +10:00
Peter Hutterer
e08a76674a util: rename the pressure range parser to a more generic range_parser
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-11 12:26:17 +10:00
Peter Hutterer
9e0da73bbf util: drop an unnecessary declaration
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-10 12:00:50 +10:00
Peter Hutterer
25d54b90db touchpad: add pressure-base palm detection
If a touch goes past the fixed pressure threshold it is labelled as a palm and
stays a palm. Default value is one that works well here on a T440 and is
virtually impossible to trigger by a normal finger or thumb. A udev property
is exposed so we can handle this in the udev hwdb and the new tool introduce a
few commits ago can help finding the palm detection threshold.

Unlike the other palm detection features, once a palm goes past the threshold
it remains a palm until the touch is released. This means palm overrides any
other palm detection features. For code simplicity, we don't combine the
states but merely check for pressure before and after the other palm detection
functions. If the pressure triggers, it will trigger before anything else. And
if something else is already active (e.g. edge where the pressure doesn't work
well) it will trigger as soon as the palm is released.

The palm threshold should thus be chosen with some room to spare between the
highest finger pressure.

https://bugs.freedesktop.org/show_bug.cgi?id=94236

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-03 15:58:13 +10:00
Peter Hutterer
1332d883f3 Add tv2us helper function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-02 12:21:35 +10:00
Gabriel Laskar
20f5f2d962 util: harmonize container_of() definition with linux kernel one
commit 3925936 introduced changes to container_of, this is hopefully the
last part of it.

In the linux kernel, container_of() takes a type name, and not a
variable. Without this, in some cases it is needed to declare an unused
variable in order to call container_of().

example:

	return container_of(dispatch, struct fallback_dispatch, base);

instead of:

	struct fallback_dispatch *p;
	return container_of(dispatch, p, base);

This introduce also list_first_entry(), a simple wrapper around
container_of() to retrieve the first element of a non empty list. It
allows to simplify list_for_each() and list_for_each_safe().

Signed-off-by: Gabriel Laskar <gabriel@lse.epita.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-17 15:04:41 +10:00