shithub: riscv

Download patch

ref: 0e5888a0cf993c89e4d52fd80b07990993e5abac
parent: ec60da4961b4acff96631e7b99c90a0f4500dbed
author: aiju <devnull@localhost>
date: Tue May 8 04:28:48 EDT 2018

add usb tablet support

--- a/sys/src/9/port/devmouse.c
+++ b/sys/src/9/port/devmouse.c
@@ -351,6 +351,8 @@
 	}
 }
 
+void scmousetrack(int, int, int, ulong);
+
 static long
 mousewrite(Chan *c, void *va, long n, vlong)
 {
@@ -468,6 +470,8 @@
 
 		if(buf[0] == 'A')
 			absmousetrack(pt.x, pt.y, b, msec);
+		else if(buf[0] == 'a')
+			scmousetrack(pt.x, pt.y, b, msec);
 		else
 			mousetrack(pt.x, pt.y, b, msec);
 		return n;
@@ -638,6 +642,22 @@
 	wakeup(&mouse.r);
 
 	mouseredraw();
+}
+
+void
+scmousetrack(int x, int y, int b, ulong msec)
+{
+	vlong vx, vy;
+
+	if(gscreen==nil)
+		return;
+	
+	vx = (vlong)(uint)x * (gscreen->clipr.max.x - gscreen->clipr.min.x);
+	x = (vx + (1<<30) - (~vx>>31&1) >> 31) + gscreen->clipr.min.x;
+	vy = (vlong)(uint)y * (gscreen->clipr.max.y - gscreen->clipr.min.y);
+	y = (vy + (1<<30) - (~vy>>31&1) >> 31) + gscreen->clipr.min.y;
+	
+	absmousetrack(x, y, b, msec);
 }
 
 static ulong
--- a/sys/src/cmd/nusb/kb/hid.h
+++ b/sys/src/cmd/nusb/kb/hid.h
@@ -8,6 +8,7 @@
 	/* HID class subclass protocol ids */
 	PtrCSP		= 0x020103,	/* mouse.boot.hid */
 	HidCSP		= 0x000003,	/* could be a trackpoint */
+	PtrNonBootCSP	= 0x020003,
 	KbdCSP		= 0x010103,	/* keyboard.boot.hid */
 
 	/* Requests */
--- a/sys/src/cmd/nusb/kb/kb.c
+++ b/sys/src/cmd/nusb/kb/kb.c
@@ -55,9 +55,8 @@
 	int	b;
 	int	m;
 
-	int	absx;
-	int	absy;
 	int	absz;
+	u8int	abs;
 
 	int	nk;
 	uchar	k[64];
@@ -550,25 +549,21 @@
 			break;
 		case 0x010030:
 			if((f & (Fabs|Frel)) == Fabs){
-				p->x = (v - p->absx);
-				p->absx = v;
-			} else {
-				p->x = v;
-				p->absx += v;
+				v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]);
+				p->abs = 1;
 			}
+			p->x = v;
 			break;
 		case 0x010031:
 			if((f & (Fabs|Frel)) == Fabs){
-				p->y = (v - p->absy);
-				p->absy = v;
-			} else {
-				p->y = v;
-				p->absy += v;
+				v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]);
+				p->abs = 1;
 			}
+			p->y = v;
 			break;
 		case 0x010038:
 			if((f & (Fabs|Frel)) == Fabs){
-				p->z = (v - p->absz);
+				p->z = v - p->absz;
 				p->absz = v;
 			} else {
 				p->z = v;
@@ -632,6 +627,7 @@
 
 		p.o = 0;
 		p.e = p.p + c;
+		p.abs = 0;
 		repparse(f->rep, f->rep+f->nrep, hidparse, &p);
 
 		if(p.nk != 0 || nlastk != 0){
@@ -684,9 +680,12 @@
 		if(p.z != 0)
 			b |= (p.z > 0) ? 8 : 16;
 
-		if(p.x != 0 || p.y != 0 || p.z != 0 || b != lastb){
+		if(p.abs || p.x != 0 || p.y != 0 || p.z != 0 || b != lastb){
 			if(debug)
-				fprint(2, "ptr: b=%x m=%x x=%d y=%d z=%d\n", p.b, p.m, p.x, p.y, p.z);
+				if(p.abs)
+					fprint(2, "ptr: b=%x m=%x x=%f y=%f z=%d\n", p.b, p.m, (uint)p.x / 2147483648.0, (uint)p.y / 2147483648.0, p.z);
+				else
+					fprint(2, "ptr: b=%x m=%x x=%d y=%d z=%d\n", p.b, p.m, p.x, p.y, p.z);
 
 			if(f->minfd < 0){
 				f->minfd = open("/dev/mousein", OWRITE);
@@ -694,7 +693,7 @@
 					hdfatal(f, "open /dev/mousein");
 			}
 
-			seprint(mbuf, mbuf+sizeof(mbuf), "m%11d %11d %11d", p.x, p.y, b);
+			seprint(mbuf, mbuf+sizeof(mbuf), "%c%11d %11d %11d", "ma"[p.abs], p.x, p.y, b);
 			write(f->minfd, mbuf, strlen(mbuf));
 
 			lastb = b;
@@ -767,6 +766,7 @@
 		switch(ep->iface->csp){
 		case KbdCSP:
 		case PtrCSP:
+		case PtrNonBootCSP:
 		case HidCSP:
 			hdsetup(d, ep);
 			break;