From e9e134a18d46da20ddf835efe3df1dab2b29e9f1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 8 Mar 2018 09:31:02 +1000 Subject: [PATCH] tools: record udev properties in libinput-record Only the ones we care about in libinput but for those it's handy to know which ones are set (especially the LIBINPUT_MODEL ones). Signed-off-by: Peter Hutterer --- meson.build | 2 +- tools/libinput-record.c | 52 +++++++++++++++++++++++++++++++++++++++ tools/libinput-record.man | 14 +++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index aee863f3..5142280d 100644 --- a/meson.build +++ b/meson.build @@ -472,7 +472,7 @@ configure_file(input : 'tools/libinput-measure-trackpoint-range.man', libinput_record_sources = [ 'tools/libinput-record.c', git_version_h ] executable('libinput-record', libinput_record_sources, - dependencies : deps_tools, + dependencies : deps_tools + [dep_udev], include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, diff --git a/tools/libinput-record.c b/tools/libinput-record.c index aaaa6cae..b0f11e8b 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -26,13 +26,16 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include +#include #include #include @@ -551,12 +554,61 @@ print_evdev_description(struct record_context *ctx, struct record_device *dev) indent_pop(ctx); } +static inline void +print_udev_properties(struct record_context *ctx, struct record_device *dev) +{ + struct udev *udev = NULL; + struct udev_device *udev_device = NULL; + struct udev_list_entry *entry; + struct stat st; + + if (stat(dev->devnode, &st) < 0) + return; + + udev = udev_new(); + if (!udev) + goto out; + + udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); + if (!udev_device) + goto out; + + iprintf(ctx, "udev:\n"); + indent_push(ctx); + + iprintf(ctx, "properties:\n"); + indent_push(ctx); + + entry = udev_device_get_properties_list_entry(udev_device); + while (entry) { + const char *key, *value; + + key = udev_list_entry_get_name(entry); + + if (strneq(key, "ID_INPUT", 8) || + strneq(key, "LIBINPUT", 8) || + strneq(key, "EV_ABS", 6)) { + value = udev_list_entry_get_value(entry); + iprintf(ctx, "- %s=%s\n", key, value); + } + + entry = udev_list_entry_get_next(entry); + } + + indent_pop(ctx); + indent_pop(ctx); +out: + udev_device_unref(udev_device); + udev_unref(udev); +} + static inline void print_device_description(struct record_context *ctx, struct record_device *dev) { iprintf(ctx, "- node: %s\n", dev->devnode); print_evdev_description(ctx, dev); + print_udev_properties(ctx, dev); } static int is_event_node(const struct dirent *dir) { diff --git a/tools/libinput-record.man b/tools/libinput-record.man index 8f9787f4..5ff263ad 100644 --- a/tools/libinput-record.man +++ b/tools/libinput-record.man @@ -119,6 +119,10 @@ devices: 57: [0, 65535, 0, 0, 0] 58: [0, 255, 0, 0, 0] properties: [0, 2, 4] + udev: + properties: + - ID_INPUT_MOUSE=1 + - ID_INPUT=1 events: - evdev: - [ 0, 0, 3, 57, 1420] # EV_ABS / ABS_MT_TRACKING_ID 1420 @@ -192,6 +196,9 @@ the device node recorded .B evdev A dictionary with the evdev device information. .TP 8 +.B udev +A dictionary with the udev device information. +.TP 8 .B events A list of dictionaries with the recorded events .SS evdev @@ -213,6 +220,13 @@ in decimal format. .TP 8 .B properties: [0, 1, ...] Array with all \fBINPUT_PROP_FOO\fR constants. May be an empty array. +.SS udev +.TP 8 +.B properties: list of strings +A list of udev properties in the \fBkey=value\fR format. This is not the +complete list of properties assigned to the device but a subset that is +relevant to libinput. These properties may include properties set on a +parent device. .SS events A list of the recorded events. The list contains dictionaries