[PATCH] Rework 'xinput list' code
Peter Hutterer
peter.hutterer at who-t.net
Wed Oct 7 16:10:29 PDT 2009
On Wed, Oct 07, 2009 at 01:12:45PM -0400, Thomas Jaeger wrote:
> This has been bugging me for a while: Nobody wants to see the details
> for all the devices when querying the device list.
yeah, good point. xinput has changed from "i need to know everything about
the input devices" to "I need to know which devices are there". I can't
remember last time I used the --long format where it wasn't for testing
purposes.
> From 01850dbbaae5da7c625a91781275e26edd697e5b Mon Sep 17 00:00:00 2001
> From: Thomas Jaeger <ThJaeger at gmail.com>
> Date: Wed, 7 Oct 2009 13:05:15 -0400
> Subject: [PATCH] Rework 'xinput list' code
>
> * Drop the questionable --loop option
> * Add a --long option (opposite of --short)
> * Make --short the default if no device argument is given
> * XI2: Make it possible to query a single device
>
> Signed-off-by: Thomas Jaeger <ThJaeger at gmail.com>
> ---
> man/xinput.man | 5 +--
> src/list.c | 90 ++++++++++++++++++++++++++++---------------------------
> src/xinput.c | 2 +-
> 3 files changed, 49 insertions(+), 48 deletions(-)
>
> diff --git a/man/xinput.man b/man/xinput.man
> index 518e1a0..75ca03c 100644
> --- a/man/xinput.man
> +++ b/man/xinput.man
> @@ -23,9 +23,8 @@ of the program.
> .PP
> .TP 8
> .B xinput list [\fIdevice_name\fP]
> -If no argument is given list all the input devices showing all their
> -features. If an argument is given, show all the feature of \fIdevice_name\fP.
> -Uses XListInputDevices(3).
> +If no argument is given list all the input devices. If an argument is given,
> +show all the features of \fIdevice_name\fP. Uses XListInputDevices(3).
> .PP
> .TP 8
> .B xinput get-feedbacks \fIdevice_name\fP
> diff --git a/src/list.c b/src/list.c
> index 0abde7a..9cfb8ea 100644
> --- a/src/list.c
> +++ b/src/list.c
> @@ -104,42 +104,15 @@ print_info(Display* dpy, XDeviceInfo *info, Bool shortformat)
> }
>
> static int list_xi1(Display *display,
> - int argc,
> - char *argv[],
> - char *name,
> - char *desc)
> + int shortformat)
> {
> XDeviceInfo *info;
> int loop;
> - int shortformat = False;
> - int daemon = False;
> + int num_devices;
>
> - shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
> - daemon = (argc == 1 && strcmp(argv[0], "--loop") == 0);
> -
> - if (argc == 0 || shortformat || daemon) {
> - int num_devices;
> -
> - do {
> - info = XListInputDevices(display, &num_devices);
> - for(loop=0; loop<num_devices; loop++) {
> - print_info(display, info+loop, shortformat);
> - }
> - } while(daemon);
> - } else {
> - int ret = EXIT_SUCCESS;
> -
> - for(loop=0; loop<argc; loop++) {
> - info = find_device_info(display, argv[loop], False);
> -
> - if (!info) {
> - fprintf(stderr, "unable to find device %s\n", argv[loop]);
> - ret = EXIT_FAILURE;
> - } else {
> - print_info(display, info, shortformat);
> - }
> - }
> - return ret;
> + info = XListInputDevices(display, &num_devices);
> + for(loop=0; loop<num_devices; loop++) {
> + print_info(display, info+loop, shortformat);
> }
> return EXIT_SUCCESS;
> }
> @@ -240,21 +213,16 @@ print_info_xi2(Display* display, XIDeviceInfo *dev, Bool shortformat)
> }
>
>
> -int
> -list_xi2(Display *display,
> - int argc,
> - char *argv[],
> - char *name,
> - char *desc)
> +static int
> +list_xi2(Display *display,
> + int shortformat)
> {
> int major = XI_2_Major,
> minor = XI_2_Minor;
> int ndevices;
> - int i, j, shortformat;
> + int i, j;
> XIDeviceInfo *info, *dev;
>
> - shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
> -
> if (XIQueryVersion(display, &major, &minor) != Success ||
> (major * 1000 + minor) < (XI_2_Major * 1000 + XI_2_Minor))
> {
> @@ -312,11 +280,45 @@ list(Display *display,
> char *name,
> char *desc)
> {
> + int shortformat = (argc >= 1 && strcmp(argv[0], "--short") == 0);
> + int longformat = (argc >= 1 && strcmp(argv[0], "--long") == 0);
> + int arg_dev = shortformat || longformat;
> +
> + if (argc > arg_dev)
> + {
> + XDeviceInfo *info;
compiler warning:
list.c: In function ‘list’:
list.c:289: warning: unused variable ‘info’
line removed before applying.
> #ifdef HAVE_XI2
> - if (xinput_version(display) == XI_2_Major)
> - return list_xi2(display, argc, argv, name, desc);
> + if (xinput_version(display) == XI_2_Major)
> + {
> + XIDeviceInfo *info = xi2_find_device_info(display, argv[arg_dev]);
> +
> + if (!info) {
> + fprintf(stderr, "unable to find device %s\n", argv[arg_dev]);
> + return EXIT_FAILURE;
> + } else {
> + print_info_xi2(display, info, shortformat);
> + return EXIT_SUCCESS;
> + }
> + } else
> #endif
> - return list_xi1(display, argc, argv, name, desc);
> + {
> + XDeviceInfo *info = find_device_info(display, argv[arg_dev], False);
> +
> + if (!info) {
> + fprintf(stderr, "unable to find device %s\n", argv[arg_dev]);
> + return EXIT_FAILURE;
> + } else {
> + print_info(display, info, shortformat);
> + return EXIT_SUCCESS;
> + }
> + }
> + } else {
> +#ifdef HAVE_XI2
> + if (xinput_version(display) == XI_2_Major)
> + return list_xi2(display, !longformat);
> +#endif
> + return list_xi1(display, !longformat);
> + }
> }
>
> /* end of list.c */
> diff --git a/src/xinput.c b/src/xinput.c
> index 1a1e7ce..3c8b23c 100644
> --- a/src/xinput.c
> +++ b/src/xinput.c
> @@ -68,7 +68,7 @@ static entry drivers[] =
> set_mode
> },
> {"list",
> - "[--loop || --short || <device name>...]",
> + "[--short || --long] [<device name>...]",
> list
> },
> {"query-state",
> --
> 1.6.3.3
Thanks for the patch, merged. I'll squash the man page update below into your patch before pushing if you don't mind.
Cheers,
Peter
diff --git a/man/xinput.man b/man/xinput.man
index 75ca03c..eba85fd 100644
--- a/man/xinput.man
+++ b/man/xinput.man
@@ -6,7 +6,9 @@ xinput - utility to configure and test XInput devices
.SH SYNOPSIS
.B xinput
-[version] [list [\fIdevice_name\fP]] [set-pointer \fIdevice_name\fP]
+[version]
+[list [--short || --long] [\fIdevice_name\fP]]
+[set-pointer \fIdevice_name\fP]
[get-feedbacks \fIdevice_name\fP]
[set-mode \fIdevice_name\fP \fIABSOLUTE|RELATIVE\fP]
[set-ptr-feedback \fIdevice_name\fP \fIthreshold\fP \fInum\fP \fIdenom\fP]
@@ -22,9 +24,12 @@ test if the XInput extension is available and return the version number
of the program.
.PP
.TP 8
-.B xinput list [\fIdevice_name\fP]
+.B xinput list [--short || --long] [\fIdevice_name\fP]
If no argument is given list all the input devices. If an argument is given,
show all the features of \fIdevice_name\fP. Uses XListInputDevices(3).
+If --long is provided, the output includes detailed information about the
+capabilities of each devices. Otherwise, or if --short is provided, only the
+device names and some minimal information is listed.
.PP
.TP 8
.B xinput get-feedbacks \fIdevice_name\fP
More information about the xorg-devel
mailing list