Xinput patches

Peter Hutterer peter.hutterer at who-t.net
Wed Apr 8 04:17:12 PDT 2009


On Tue, Apr 07, 2009 at 12:07:08PM +0200, Simon Thum wrote:
> I've had some patches laying around for xinput. They make it possible to  
> select devices by using the device's type name.
>
> This is useful for scripting, since some mice have cool names such as  
> "HID:1002-08/15", making it hard to use xinput to just set your mouse.  
> Id's vary by design.
>
> Now you can
> xinput do-stuff [MOUSE-0]

Two things:
- How about an array notation in the form or MOUSE[1]?
  (and make MOUSE[] to have the same behaviour for your current [MOUSE-0])
- I'd prefer a commandline-switch --by-type to trigger this, rather than
  guessing from the name of the device.

> From 95f78f6815570af575ea138b3e98de580b30e167 Mon Sep 17 00:00:00 2001
> From: Simon Thum <simon.thum at gmx.de>
> Date: Thu, 26 Mar 2009 13:52:15 +0100
> Subject: [PATCH] xinput: include device type in device list
> 
> ---
>  src/list.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/list.c b/src/list.c
> index de8aca7..bd71a5c 100644
> --- a/src/list.c
> +++ b/src/list.c
> @@ -26,7 +26,7 @@
>  #include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
>  
>  static void
> -print_info(XDeviceInfo	*info, Bool shortformat)
> +print_info(Display* dpy, XDeviceInfo	*info, Bool shortformat)
>  {
>      int			i,j;
>      XAnyClassPtr	any;
> @@ -65,6 +65,9 @@ print_info(XDeviceInfo	*info, Bool shortformat)
>      if (shortformat)
>          return;
>  
> +    if(info->type != None)
> +	printf("\tType is %s\n", XGetAtomName(dpy, info->type));
> +
>      if (info->num_classes > 0) {
>  	any = (XAnyClassPtr) (info->inputclassinfo);
>  	for (i=0; i<info->num_classes; i++) {
> @@ -140,7 +143,7 @@ list(Display	*display,
>          do {
>              info = XListInputDevices(display, &num_devices);
>              for(loop=0; loop<num_devices; loop++) {
> -                print_info(info+loop, shortformat);
> +                print_info(display, info+loop, shortformat);
>              }
>  
>  #if HAVE_XI2
> @@ -175,7 +178,7 @@ list(Display	*display,
>  		fprintf(stderr, "unable to find device %s\n", argv[loop]);
>  		ret = EXIT_FAILURE;
>  	    } else {
> -		print_info(info, shortformat);
> +		print_info(display, info, shortformat);
>  	    }
>  	}
>  	return ret;
> -- 
> 1.6.0.6

pushed, thanks.

> From 872da62a19c5bfee70cdf4cd046fb723d395b205 Mon Sep 17 00:00:00 2001
> From: Simon Thum <simon.thum at gmx.de>
> Date: Thu, 26 Mar 2009 15:15:26 +0100
> Subject: [PATCH] xinput: new syntax to select devices by type
> 
> see manpage changes for details. 

just copy the text from the man page so git log is still useful.

> Also, states clearly
> when device selection fails because it is a extension
> device.
> ---
>  man/xinput.man |    6 ++++-
>  src/xinput.c   |   58 ++++++++++++++++++++++++++++++++++++++++++++-----------
>  2 files changed, 51 insertions(+), 13 deletions(-)
> 
> diff --git a/man/xinput.man b/man/xinput.man
> index c9ff46f..f66fd71 100644
> --- a/man/xinput.man
> +++ b/man/xinput.man
> @@ -80,7 +80,11 @@ loop displaying events received. If the -proximity is given, ProximityIn
>  and ProximityOut are registered.
>  .PP
>  \fIdevice_name\fP can be the device name as a string or the XID of the
> -device.
> +device. Also possible is a type-based locator notation \fI[Type-Num]\fP
> +(the brackets are literal).
> +\fIType\fP specifies the device type, \fINum\fP is 1 for the first
> +device, 2 for the second and so on. 0 means select the only device of
> +this type; it fails when more than one device has the specified type.  
>  .PP
>  \fIproperty\fP can be the property as a string or the Atom value.
>  .PP
> diff --git a/src/xinput.c b/src/xinput.c
> index 466a814..7dde29b 100644
> --- a/src/xinput.c
> +++ b/src/xinput.c
> @@ -166,8 +166,10 @@ find_device_info(Display	*display,
>      int		loop;
>      int		num_devices;
>      int		len = strlen(name);
> -    Bool	is_id = True;
> +    Bool	is_id = True, is_locator, is_name;
>      XID		id = (XID)-1;
> +    int		loc_num;
> +    char	loc_type[100];
>  
>      for(loop=0; loop<len; loop++) {
>  	if (!isdigit(name[loop])) {
> @@ -178,24 +180,56 @@ find_device_info(Display	*display,
>  
>      if (is_id) {
>  	id = atoi(name);
> +    }else{
> +	if(sscanf(name, "[%[A-Z_a-z ]-%i]", loc_type, &loc_num) == 2) {
> +	    is_locator = True;
> +	}
>      }
>  
> +    is_name = !is_id && !is_locator;
> +
>      devices = XListInputDevices(display, &num_devices);
>  
> -    for(loop=0; loop<num_devices; loop++) {
> -	if ((!only_extended || (devices[loop].use >= IsXExtensionDevice)) &&
> -	    ((!is_id && strcmp(devices[loop].name, name) == 0) ||
> -	     (is_id && devices[loop].id == id))) {
> -	    if (found) {
> -	        fprintf(stderr,
> -	                "Warning: There are multiple devices named \"%s\".\n"
> -	                "To ensure the correct one is selected, please use "
> -	                "the device ID instead.\n\n", name);
> -	    } else {
> -		found = &devices[loop];
> +    if(is_name || is_id){
> +	for(loop=0; loop<num_devices; loop++) {
> +	    if ((is_name && strcmp(devices[loop].name, name) == 0) ||
> +		(is_id && devices[loop].id == id)) {
> +		if (found) {
> +		    fprintf(stderr,
> +			    "Warning: There are multiple devices named \"%s\".\n"
> +			    "To ensure the correct one is selected, please use "
> +			    "the device ID instead.\n\n", name);
> +		} else {
> +		    found = &devices[loop];
> +		}
> +	    }
> +	}
> +    }else if (is_locator) {
> +	for(loop=0; loop<num_devices; loop++) {
> +	    if (devices[loop].type != None &&
> +		strcmp(XGetAtomName(display, devices[loop].type),
> +		       loc_type) == 0) {
> +		//Handle zero -> find only device of given type
> +		if(loc_num == 0 && !found) {
> +		    found = &devices[loop];
> +		}else if(loc_num == 0 && found) {
> +		    fprintf(stderr,
> +			    "Error: selecting only device failed because there"
> +		            "are multiple devices with type %s.\n\n", loc_type);
> +		    return 0;
> +		}else if(loc_num > 1) {
> +		    loc_num--; //countdown
> +		}else if(loc_num == 1 && !found) {
> +		    found = &devices[loop];
> +		}
>  	    }
>  	}
>      }
> +
> +    if (found && only_extended && (found->use >= IsXExtensionDevice)){
> +	fprintf(stderr, "Extension device ignored.\n\n");
> +	return 0;
> +    }
>      return found;
>  }
>  
> -- 
> 1.6.0.6

NACK, for the reasons mentioned above.

> From 4ef4f3601ab93508818e7a7d95582e0f82f5db83 Mon Sep 17 00:00:00 2001
> From: Simon Thum <simon.thum at gmx.de>
> Date: Thu, 26 Mar 2009 15:19:47 +0100
> Subject: [PATCH] xinput: mention set-float-prop in manpage
> 
> ---
>  man/xinput.man |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/man/xinput.man b/man/xinput.man
> index f66fd71..78fd711 100644
> --- a/man/xinput.man
> +++ b/man/xinput.man
> @@ -65,6 +65,10 @@ Sets an integer property for the device.  Appropriate values for \fIformat\fP
>  are 8, 16, or 32, depending on the property.
>  .PP
>  .TP 8
> +.B xinput set-float-prop \fIdevice_name\fP \fIproperty\fP \fIvalue\fP
> +Sets a float property for the device.
> +.PP
> +.TP 8
>  .B xinput watch-props \fIdevice_name\fP
>  Prints to standard out when property changes occur.
>  .PP
> -- 
> 1.6.0.6
 
pushed, thanks.

Cheers,
  Peter


More information about the xorg-devel mailing list