9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] nusb/kb mouse handling
@ 2020-12-08  0:59 umbraticus
  2020-12-08  8:44 ` umbraticus
  0 siblings, 1 reply; 6+ messages in thread
From: umbraticus @ 2020-12-08  0:59 UTC (permalink / raw)
  To: 9front

This patch is tidier than the last one I sent.  It does three things:

1. Only update button state if a button event was actually received.
2. Send b = 8 through instead of treating like b = 2.
3. Fix some typos.

umbraticus

diff -r 7a249c0196e5 sys/src/cmd/nusb/kb/kb.c
--- a/sys/src/cmd/nusb/kb/kb.c	Mon Dec 07 18:59:54 2020 +0100
+++ b/sys/src/cmd/nusb/kb/kb.c	Tue Dec 08 13:38:54 2020 +1300
@@ -637,7 +637,7 @@
 			s->h = v;
 			break;
 
-		case 0x0D0051:	/* Conteact identifier */
+		case 0x0D0051:	/* Contact identifier */
 			s->id = v;
 			break;
 
@@ -684,7 +684,7 @@
 {
 	char	err[ERRMAX], mbuf[80];
 	uchar	lastk[64], uk, dk;
-	int	i, c, nerrs, lastb, nlastk;
+	int	i, c, nerrs, bpress, lastb, nlastk;
 	int	abs, x, y, z, b;
 	Hidreport p;
 	Hidslot lasts[nelem(p.s)], *s, *l;
@@ -774,7 +774,7 @@
 			continue;
 
 		/* combine all the slots */
-		abs = x = y = z = b = 0;
+		bpress = abs = x = y = z = b = 0;
 		for(i=0; i<p.ns; *l = *s, i++){
 			s = &p.s[i];
 
@@ -785,7 +785,7 @@
 			if(l == &lasts[nelem(lasts)-1] || !l->valid)
 				*l = *s;
 
-			/* convet absolute z to relative */
+			/* convert absolute z to relative */
 			z += s->z;
 			if(s->abs & 4)
 				z -= l->z;
@@ -803,11 +803,8 @@
 			}
 
 			/* map to mouse buttons */
-			b |= s->b & 1;
-			if(s->b & (4|8))
-				b |= 2;
-			if(s->b & 2)
-				b |= 4;
+			bpress |= s->m;
+			b |= s->b & ~6 | (s->b & 2) << 1 | (s->b & 4) >> 1;
 
 			/* X/Y are absolute? */
 			if((s->abs & 3) == 3){
@@ -829,6 +826,7 @@
 		if(z != 0)
 			b |= z > 0 ? 8 : 16;
 
+		if(!bpress) b = lastb;
 		if(abs || x != 0 || y != 0 || z != 0 || b != lastb){
 			lastb = b;
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-09  0:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08  0:59 [9front] nusb/kb mouse handling umbraticus
2020-12-08  8:44 ` umbraticus
2020-12-08 11:37   ` umbraticus
2020-12-08 13:50     ` kvik
2020-12-08 21:18       ` umbraticus
2020-12-09  0:14         ` kvik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).