Re: [PATCH libinput] tools: add a tool to list local devices and the default configurations
Hi, On 15-04-15 05:49, Peter Hutterer wrote: xinput or an equivalent isn't available under wayland, but the majority of use-cases of "why doesn't my device work" or "why does feature X not work" should be covered by simply listing the local devices and their config options. Example output: Device: SynPS/2 Synaptics TouchPad Kernel: /dev/input/event4 Group: 9 Seat: seat0, default Size: 97.33x62.40mm Capabilities: pointer Tap-to-click: disabled Left-handed:disabled Nat.scrolling: disabled Calibration:n/a Scroll methods: *two-finger Click methods: *button-areas clickfinger Signed-off-by: Peter Hutterer Looks good: Reviewed-by: Hans de Goede Regards, Hans --- tools/.gitignore| 1 + tools/Makefile.am | 6 + tools/libinput-list-devices.c | 282 tools/libinput-list-devices.man | 37 ++ 4 files changed, 326 insertions(+) create mode 100644 tools/libinput-list-devices.c create mode 100644 tools/libinput-list-devices.man diff --git a/tools/.gitignore b/tools/.gitignore index 6d530e6..e58dba9 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -1,3 +1,4 @@ event-debug event-gui ptraccel-debug +libinput-list-devices diff --git a/tools/Makefile.am b/tools/Makefile.am index 34d5ab0..b8cc218 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,4 +1,5 @@ noinst_PROGRAMS = event-debug ptraccel-debug +bin_PROGRAMS = libinput-list-devices noinst_LTLIBRARIES = libshared.la AM_CPPFLAGS = -I$(top_srcdir)/include \ @@ -18,6 +19,11 @@ ptraccel_debug_SOURCES = ptraccel-debug.c ptraccel_debug_LDADD = ../src/libfilter.la ptraccel_debug_LDFLAGS = -no-install +libinput_list_devices_SOURCES = libinput-list-devices.c +libinput_list_devices_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) +libinput_list_devices_CFLAGS = $(LIBUDEV_CFLAGS) +man1_MANS = libinput-list-devices.man + if BUILD_EVENTGUI noinst_PROGRAMS += event-gui diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c new file mode 100644 index 000..24c7c53 --- /dev/null +++ b/tools/libinput-list-devices.c @@ -0,0 +1,282 @@ +/* + * Copyright © 2015 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "shared.h" + +static int +open_restricted(const char *path, int flags, void *user_data) +{ + int fd = open(path, flags); + if (fd < 0) + fprintf(stderr, "Failed to open %s (%s)\n", + path, strerror(errno)); + return fd < 0 ? -errno : fd; +} + +static void +close_restricted(int fd, void *user_data) +{ + close(fd); +} + +static const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +static inline const char* +bool_to_str(bool b) +{ + if (b) + return "yes"; + else + return "no"; +} + +static const char * +tap_default(struct libinput_device *device) +{ + if (!libinput_device_config_tap_get_finger_count(device)) + return "n/a"; + + if (libinput_device_config_tap_get_default_enabled(device)) + return "enabled"; + else + return "disabled"; +} + +static const char* +left_handed_default(struct libinput_device *device) +{ + if (!libinput_device_config_left_handed_is_available(device)) + return "n/a"; + + if (libinput_device_config_left_handed_get_default(device)) + return "enabled"; + else + return "disabled"; +} + +static const char * +nat_scroll_default(struct libinput_device *device) +{ + if (!libinput_device_config_scro
[PATCH libinput] tools: add a tool to list local devices and the default configurations
xinput or an equivalent isn't available under wayland, but the majority of use-cases of "why doesn't my device work" or "why does feature X not work" should be covered by simply listing the local devices and their config options. Example output: Device: SynPS/2 Synaptics TouchPad Kernel: /dev/input/event4 Group: 9 Seat: seat0, default Size: 97.33x62.40mm Capabilities: pointer Tap-to-click: disabled Left-handed:disabled Nat.scrolling: disabled Calibration:n/a Scroll methods: *two-finger Click methods: *button-areas clickfinger Signed-off-by: Peter Hutterer --- tools/.gitignore| 1 + tools/Makefile.am | 6 + tools/libinput-list-devices.c | 282 tools/libinput-list-devices.man | 37 ++ 4 files changed, 326 insertions(+) create mode 100644 tools/libinput-list-devices.c create mode 100644 tools/libinput-list-devices.man diff --git a/tools/.gitignore b/tools/.gitignore index 6d530e6..e58dba9 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -1,3 +1,4 @@ event-debug event-gui ptraccel-debug +libinput-list-devices diff --git a/tools/Makefile.am b/tools/Makefile.am index 34d5ab0..b8cc218 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,4 +1,5 @@ noinst_PROGRAMS = event-debug ptraccel-debug +bin_PROGRAMS = libinput-list-devices noinst_LTLIBRARIES = libshared.la AM_CPPFLAGS = -I$(top_srcdir)/include \ @@ -18,6 +19,11 @@ ptraccel_debug_SOURCES = ptraccel-debug.c ptraccel_debug_LDADD = ../src/libfilter.la ptraccel_debug_LDFLAGS = -no-install +libinput_list_devices_SOURCES = libinput-list-devices.c +libinput_list_devices_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) +libinput_list_devices_CFLAGS = $(LIBUDEV_CFLAGS) +man1_MANS = libinput-list-devices.man + if BUILD_EVENTGUI noinst_PROGRAMS += event-gui diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c new file mode 100644 index 000..24c7c53 --- /dev/null +++ b/tools/libinput-list-devices.c @@ -0,0 +1,282 @@ +/* + * Copyright © 2015 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "shared.h" + +static int +open_restricted(const char *path, int flags, void *user_data) +{ + int fd = open(path, flags); + if (fd < 0) + fprintf(stderr, "Failed to open %s (%s)\n", + path, strerror(errno)); + return fd < 0 ? -errno : fd; +} + +static void +close_restricted(int fd, void *user_data) +{ + close(fd); +} + +static const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +static inline const char* +bool_to_str(bool b) +{ + if (b) + return "yes"; + else + return "no"; +} + +static const char * +tap_default(struct libinput_device *device) +{ + if (!libinput_device_config_tap_get_finger_count(device)) + return "n/a"; + + if (libinput_device_config_tap_get_default_enabled(device)) + return "enabled"; + else + return "disabled"; +} + +static const char* +left_handed_default(struct libinput_device *device) +{ + if (!libinput_device_config_left_handed_is_available(device)) + return "n/a"; + + if (libinput_device_config_left_handed_get_default(device)) + return "enabled"; + else + return "disabled"; +} + +static const char * +nat_scroll_default(struct libinput_device *device) +{ + if (!libinput_device_config_scroll_has_natural_scroll(device)) + return "n/a"; + + if (libinput_device_config_scroll_get_default_natur