Patch to xmodmap to allow disabling mouse buttons

Ben North ben at redfrontdoor.org
Tue Jan 20 09:01:26 PST 2009


Hi,

Similar to this poster from 2007:

  http://lists.freedesktop.org/archives/xorg/2007-March/022701.html

I wanted to disable all mouse buttons except button 1 (or re-map them to
appear as button 1).  The man page for XSetPointerMapping says that this
can be achieved by mapping to 'button 0', but xmodmap doesn't allow
this:

  % xmodmap -e 'pointer = 1 0 0 4 5'
  xmodmap:  commandline:0:  bad value 0  given for buttons list
  xmodmap:  1 error encountered, aborting.

On looking at the source, it seems that this is a misbehaviour of
'parse_number' in handle.c, which rejects the string "0 ", i.e., a zero
followed by a space.  The patch below fixes this, and then the above
xmodmap invocation has the desired effect of disabling buttons 2 and 3.

I found a more recent mail message

  http://lists.freedesktop.org/archives/xorg/2008-March/033996.html

which says that xmodmap was going away in favour of xinput, but might it
be worth applying this patch while xmodmap is still around?

Thanks,

Ben.



--- ORIG--handle.c      2007-08-06 23:58:57.000000000 +0100
+++ handle.c    2009-01-20 15:01:47.547413000 +0000
@@ -265,24 +265,25 @@
       print_opcode (p);
    }
    return;
 }

 static Bool
 parse_number(const char *str, unsigned long *val)
 {
    char *fmt = "%ld";

    if (*str == '0') {
       str++;
+       while (isspace(*str)) str++;
       fmt = "%lo";
       if (*str == '\0') {
           *val = 0;
           return 1;
       }
       if (*str == 'x' || *str == 'X') {
           str++;
           fmt = "%lx";
       }
    }
    return (sscanf (str, fmt, val) == 1);
 }



More information about the xorg mailing list