From 7010a6c924ce6937c8e040c837a118663d6dfdb3 Mon Sep 17 00:00:00 2001 From: Thomas Jaeger Date: Wed, 7 Oct 2009 13:05:15 -0400 Subject: 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 squashed in a man page update for --short and --long. Signed-off-by: Peter Hutterer --- src/list.c | 89 ++++++++++++++++++++++++++++++------------------------------ src/xinput.c | 2 +- 2 files changed, 46 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/list.c b/src/list.c index 0abde7a..ecf1f4b 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= 1 && strcmp(argv[0], "--short") == 0); + int longformat = (argc >= 1 && strcmp(argv[0], "--long") == 0); + int arg_dev = shortformat || longformat; + + if (argc > arg_dev) + { #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 || ...]", + "[--short || --long] [...]", list }, {"query-state", -- cgit v1.2.3