Commit graph

110 commits

Author SHA1 Message Date
Sertonix
aa7d58005e Fix format strings on 32-bit with 64-bit time_t
This fixes a segfault when running the test suite on ppc musl

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1318>
2025-10-14 05:40:19 +00:00
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
Ryan Hendrickson
548279abee tools: store virtual property in recordings
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1213>
2025-06-08 23:55:10 +00:00
Peter Hutterer
0ecd08c134 tools: use __attribute__(cleanup)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10: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
d2969f5203 tools/record: correct the --help output for autorestart
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1173>
2025-04-04 04:47:36 +00:00
Peter Hutterer
74617de48d tools/record: record HID_BPF properties too
If this property is set we likely have a udev-hid-bpf property
loaded into the device. Knowing this is going to be important for
debugging why a device may or may not work so let's record this.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1121>
2025-01-20 10:29:47 +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
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
fdb693a6ee tools/record: record the DRIVER property in the recording
So we know which kernel driver is handling the device. Quite useful,
sometimes, without having to ask for extra logs.

This of course requires that we ignore said property in libinput replay
since no uinput device will have that driver property set.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1007>
2024-06-04 16:54:28 +10:00
José Expósito
973c461d4b tools/record: print bus name
A follow up on commit 65eaabf91f ("tools/record: print the vid/pid
with proper 4 hex digits").

Print the bus name in addition to the bus ID. Only the busses available
in quirks are printed.

Example:

    $ sudo libinput record
    [...]
    # ID: bus 0x0003 (usb) vendor 0x046d product 0x406d version 0x0111
    [...]

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2023-09-01 16:21:15 +02:00
Peter Hutterer
17e556503d tools: rename an enum value to fix a FreeBSD 14 name clash
Fixes #931
2023-08-31 12:21:00 +10:00
Peter Hutterer
65eaabf91f tools/record: print the vid/pid with proper 4 hex digits
The field with includes the 0x if printing with "0x04d". And because
that format prints zero as just 0000, let's move the 0x prefix out and
let printf only handle the actual number.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-29 05:35:15 +10:00
José Expósito
7bfdf52db2 tools/record: fix quirk error message
When libinput-record fails to parse the quirks, it suggest to use the
--verbose flag to get more details. However, libinput-record does not
support the --verbose flag.

Replace the error message and add a link to the documentation instead.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-12-12 19:17:01 +01: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
José Expósito
8a6ca3c1c5 sparse: make some variables static
When compiling with Sparse enabled:

	$ CC=cgcc meson builddir

Fix warnings about variables that should be made static.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2022-11-23 21:57:28 +00:00
Peter Hutterer
200bc920ac tools/record: fix indentation for libinput events
Commit 0cdf459643
  tools/record: get rid of indent push/pop, replace with fixed indents

Introduced some magic to detect if there's a '-' at the start of the
format string to fix the identation. This only works if the format
string is constant though, leading to an indentation error when record
is run with --with-libinput.

Fixes 0cdf459643

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-06 14:04:59 +10:00
Peter Hutterer
a6ec596467 tools/record: fix the indentation of the system: section
Fixes 0cdf459643

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-04-07 14:46:57 +10:00
Peter Hutterer
395d12d634 util: auto-declare the element variable in ARRAY_FOR_EACH
All cases we have in our code base have an otherwise unused variable to
loop through the array. Let's auto-declare this as part of the loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-09 10:16:07 +10:00
Peter Hutterer
8fecb19147 Use bit(foo) instead of (1 << foo)
Translates to the same thing, but the bit() helper is nicer and less
likely to be typoed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-11-18 10:11:43 +10: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
luokai
87447a0ee9 using secure functions safe_strdup
Signed-off-by: luokai <l18674732394.com>
2021-06-15 11:27:29 +08:00
Peter Hutterer
e72b30f424 tools/record: narrow down the obfuscation range
Let a few obvious modifiers through, including the F-key range. Especially
left control is useful to know if it's down.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-18 23:14:44 +00:00
Peter Hutterer
cf1abf0818 tools/record: add support for hidraw recording
New commandline switch --with-hidraw. This will open all hidraw devices
associated with this device and add any reports to the output in the
form:

  events:
    - hid:
        time: [0, 0]
        hidraw1: [0x01, 0x02, 0x03, 0x05, 0x06]
	hidraw2: [0x07, 0x08, 0x09, 0x0a, 0x0b]
    - evdev:
      ...

i.e. there's a nesting of `hid` with a list of reports, each with the hidraw
node as dictionary entry.

Because hidraw events do not have timestamps and always occur before the evdev
events, they are in a separate frame (as shown above). We could try to figure
out how to match them with the upcoming evdev frame but it's not worth it for
now.

The timestamp itself is a special key in the hidraw with the timestamp from
clock_gettime.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-05 03:59:34 +00:00
Peter Hutterer
b38c6ca69f tools/record: linebreak the hid report descriptor every 16 bytes
New output:

 hid: [
    0x05, 0x0d, 0x09, 0x04, 0xa1, 0x01, 0x85, 0x01, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15, 0x00,
    0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x75, 0x01, 0x81, 0x03, 0x75, 0x06, 0x09, 0x51,
    0x25, 0x3f, 0x81, 0x02, 0x26, 0xff, 0x00, 0x75, 0x08, 0x09, 0x48, 0x81, 0x02, 0x09, 0x49, 0x81,
    ...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
7da7cd216f tools/record: print the HID report descriptor as hex
YAML does support hex as long as it's 0x-prefixed. The comment here (probably)
dates from an in-development version of libinput-record that used JSON.
Anyway, let's print the HID report descriptor as hex because that's the common
format for it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
57811e40f0 tools/record: fix a strlen assumption
We want to be able to print single-character strings.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
943e258cca tools/record: line up the "neutral state" message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
33b30d4631 tools/record: rework the event printing
For historical (but not very good) reasons, libinput record printed events
from the first device to the output file (or stdout) and buffered everything
else. On ctrl+c, the other devices' descriptions and the buffered events were
appended to the output file.

This makes the printing code rather complex. Simplify it by giving each device
a separate FILE* - the first device points to the real output file, the others
to a tempfile. On Ctrl+C we just append those tempfiles to the real output
file one-by-one and done.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
bacf4e5a62 tools/record: rename the output file handling
Less confusing than having output_file, out_file, and outfile.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
7957f1980d tools/record: remember the first device in the context
No functional changes since we can get this easily from the list itself, but
in the future the first device will be used more extensively.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
0b23cb1ba2 tools/record: append the devices in-order
Using list_insert() here means the last device specified on the commandline is
the one that ends up in the file first - not very obvious...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
0cdf459643 tools/record: get rid of indent push/pop, replace with fixed indents
Our file format is static enough that we don't need to use push/pop, we know
exactly which line is going where. So let's replace it with a static
indent instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
632eedadf5 tools/record: mark the iprintf function as printf
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:33:49 +10:00
Peter Hutterer
9011f91868 tools/record: switch the output file from an fd to a FILE*
This is prep work to be more consistent with the use of tempfile later for
individual devices.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:33:49 +10:00
Peter Hutterer
7f4df04d59 tools/record: deduplicate the device opening logic
With a new helper function strv_from_argv we can re-use the device opening
loop for all the use-cases we have.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:26:30 +10:00
Peter Hutterer
4da9349a91 tools/record: free the namelist when we're done
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
e511f96201 tools/record: localize a variable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
8b822a84c4 tools/record: de-duplicate an error message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
0828fdcea0 tools/record: factor out the output file collection
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Konstantin Kharlamov
3d3d9b7f69 treewide: get rid of tmp argument in list_for_each_safe
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
2021-03-02 09:10:35 +03:00
Peter Hutterer
1b00eb5e03 tools/record: fix two coverity complaints
In both cases we only read to drain the fd, we don't care about the return
value.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 16:55:58 +10:00
Peter Hutterer
627a3dd2b2 tools/record: use a helper function to get the next event for a device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
4a7dece88c tools/record: switch record over to using epoll
Using poll means more difficult fd management, epoll (together with am
modified version of the libinput_sources) makes this a lot easier by simply
using dispatch.

This means we are no longer reliant on a specific file descriptor order in the
poll array.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
ca9067992e tools/record: use safe_basename() to get to the hid report descriptor
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
fd9d165a77 tools/record: simplify the behavior to emulate Python's join()
Instead of a boolean "is_first", just change the separator.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
59ca971898 tools/record: print a header as first line
To make the file format easier to detect

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 14:53:41 +10:00
Peter Hutterer
4b0f200936 tools/record: fix outdated comment
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-19 09:09:53 +10:00
Peter Hutterer
a8597e3ab3 tools/record: de-inline our functions
Let's leave this up to the compiler, the usual side-effect of inline (compiler
doesn't complain about an unused static function) doesn't apply here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-19 09:09:53 +10:00
Peter Hutterer
f6c05ae4cc tools/record: remove a useless assignment
It's overwritten a few lines south of here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-12 07:35:58 +10:00