shithub: riscv

Download patch

ref: 4260392749bb9f1092c537a3e02c720e4e43f31e
parent: ffa54947bc52cf9a09d3cee9780e6858792a8b9b
author: cinap_lenrek <[email protected]>
date: Sun Nov 25 17:37:53 EST 2012

nusb/kb: skip 0x01 lead byte hack, you dont wanna know

apparently, some mouse send constant 0x01 byte
before normal 4 byte mouse packet. this is known in
openbsd/freebsd as UQ_MS_LEADING_BYTE quirk.

--- a/sys/src/cmd/nusb/kb/kb.c
+++ b/sys/src/cmd/nusb/kb/kb.c
@@ -226,12 +226,13 @@
 ptrwork(void* a)
 {
 	static char maptab[] = {0x0, 0x1, 0x4, 0x5, 0x2, 0x3, 0x6, 0x7};
-	int x, y, b, c, nerrs;
+	int x, y, b, c, nerrs, skiplead;
 	char	err[ERRMAX], buf[64];
 	char	mbuf[80];
 	KDev*	f = a;
 
 	sethipri();
+	skiplead = -1;
 	nerrs = 0;
 	for(;;){
 		if(f->ep == nil)
@@ -256,6 +257,21 @@
 		nerrs = 0;
 		if(c < 3)
 			continue;
+
+		if(c > 4){
+			/*
+			 * horrible horrible hack. some mouse send a
+			 * constant 0x01 lead byte. stop the hack as
+			 * soon as buf[0] changes.
+			 */
+			if(skiplead == -1)
+				skiplead = buf[0] & 0xFF;
+			if(skiplead == 0x01 && skiplead == buf[0])
+				memmove(buf, buf+1, --c);
+			else
+				skiplead = 0;
+		}
+
 		if(f->accel){
 			x = scale(f, buf[1]);
 			y = scale(f, buf[2]);