Commit 705f6309 authored by Benjamin Tissoires's avatar Benjamin Tissoires

hid-decode: read libinput record yaml files

`libinput record` now also integrate the hid report descriptors of the
device when the device is a hid one.

Instead of relying on custom scripts to convert the files into
`hid-recorder` compatible ones, teach `hid-decode` to parse the provided
report descriptors directly.

Note, this adds a new dependency on PyYaml, but it should be common enough
on all distributions now.
Signed-off-by: Benjamin Tissoires's avatarBenjamin Tissoires <>
parent bc5dbb1f
Pipeline #45788 passed with stage
in 3 minutes and 39 seconds
......@@ -25,6 +25,7 @@ import sys
import hidtools.hid
import hidtools.hidraw
import logging
import yaml
logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
base_logger = logging.getLogger('hid')
......@@ -86,6 +87,23 @@ def interpret_file_hidrecorder(lines):
return rdescs
def interpret_file_libinput_record(fd):
libinput_data = yaml.load(fd, Loader=yaml.Loader)
except UnicodeDecodeError:
# binary file?
return None
if 'libinput' not in libinput_data:
# not a libinput record
return None
rdescs_data = [dev['hid'] for dev in libinput_data['devices']]
rdescs = [hidtools.hid.ReportDescriptor.from_bytes(r) for r in rdescs_data]
return rdescs
def open_report_descriptor(path):
abspath = os.path.abspath(path)
logger.debug(f'Processing {abspath}')
......@@ -110,6 +128,11 @@ def open_report_descriptor(path):
if rdesc is not None:
return rdesc
with open(path, 'r') as fd:
rdesc = interpret_file_libinput_record(fd)
if rdesc is not None:
return rdesc
raise Oops(f'Unable to detect file type for {path}')
......@@ -86,7 +86,7 @@ setup(name='hid-tools',
data_files=[], # man pages are added on success
install_requires=['parse', 'pyudev'],
install_requires=['parse', 'pyudev', 'pyyaml'],
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment