This does two things (well, three, but I'd delete the third one). First, it adds "scrollswap" as a ctl for mousectl. The reason is that some mouses we found send the wrong buttons (5/4) instead of the usual ones (4/5) for the wheel. Second (the reason for this patch) it changes buf in mouseread to hold one extra space after the 4th number and puts an space after the 4th number in the read buffer. We noticed (the hard way) that /dev/mouse was not supplying 49 bytes as the man page said. This has nasty effects when sending mouse events through tcp (that does not have message delimiters). I'd either fix this, or change the man page. In any case, I think /dev/mouse is supplying the extra \0 of the string instead of the extra " ", which is weird. The third thing (that I'd probably not apply), is to support "M ..." messages instead of "m ...", to let the user send absolute mouse positions to the mouse. We use this for the usb touch screen, but we're going to convert it to use #m/mousein instead. Hope it's not hard for you to just extract the useful part of this patch. Notes: Sat Oct 30 18:54:40 EDT 2004 rsc i edited this before applying. Reference: /n/sources/patch/applied/devmouse Date: Sun Oct 31 00:54:49 CES 2004 Reviewed-by: rsc --- /sys/src/9/port/devmouse.c Sun Oct 31 00:54:49 2004 +++ /sys/src/9/port/devmouse.c Sun Oct 31 00:54:49 2004 @@ -47,6 +47,7 @@ enum { CMbuttonmap, + CMscrollswap, CMswap, CMwildcard, }; @@ -54,6 +55,7 @@ static Cmdtab mousectlmsg[] = { CMbuttonmap, "buttonmap", 0, + CMscrollswap, "scrollswap", 0, CMswap, "swap", 1, CMwildcard, "*", 0, }; @@ -87,7 +89,7 @@ 0, 1, 2, 3, 4, 5, 6, 7, }; static int mouseswap; - +static int scrollswap; extern Memimage* gscreen; static void @@ -210,7 +212,7 @@ static long mouseread(Chan *c, void *va, long n, vlong off) { - char buf[4*12+1]; + char buf[1+4*12+1]; uchar *p; static int map[8] = {0, 4, 2, 6, 1, 5, 3, 7 }; ulong offset = off; @@ -265,7 +267,12 @@ b = buttonmap[m.buttons&7]; /* put buttons 4 and 5 back in */ b |= m.buttons & (3<<3); - sprint(buf, "m%11d %11d %11d %11lud", + if (scrollswap) + if (b == 8) + b = 16; + else if (b == 16) + b = 8; + sprint(buf, "m%11d %11d %11d %11lud ", m.xy.x, m.xy.y, b, m.msec); @@ -372,6 +379,10 @@ else setbuttonmap("321"); mouseswap ^= 1; + break; + + case CMscrollswap: + scrollswap ^= 1; break; case CMbuttonmap: