9front - general discussion about 9front
 help / color / mirror / Atom feed
* nusb/kb screwing up trackball button state
@ 2020-11-08  5:18 umbraticus
  2020-11-08  5:29 ` [9front] " umbraticus
  0 siblings, 1 reply; 2+ messages in thread
From: umbraticus @ 2020-11-08  5:18 UTC (permalink / raw)
  To: 9front

diff -r eef7bc730924 sys/src/cmd/nusb/kb/kb.c
--- a/sys/src/cmd/nusb/kb/kb.c	Fri Nov 06 18:15:15 2020 -0800
+++ b/sys/src/cmd/nusb/kb/kb.c	Sun Nov 08 17:56:48 2020 +1300
@@ -65,6 +65,7 @@
 	int	y;
 	int	z;
 
+	int	binfo;
 	int	b;
 	int	m;
 
@@ -602,6 +603,7 @@
 		case 0x090008:
 			m = 1<<(l[Usage] - 0x090001);
 		Button:
+			s->binfo = 1;
 			s->m |= m;
 			s->b &= ~m;
 			if(v != 0)
@@ -629,7 +631,7 @@
 			s->h = v;
 			break;
 
-		case 0x0D0051:	/* Conteact identifier */
+		case 0x0D0051:	/* Contact identifier */
 			s->id = v;
 			break;
 
@@ -677,7 +679,7 @@
 	char	err[ERRMAX], mbuf[80];
 	uchar	lastk[64], uk, dk;
 	int	i, c, nerrs, lastb, nlastk;
-	int	abs, x, y, z, b;
+	int	abs, x, y, z, b, binfo;
 	Hidreport p;
 	Hidslot lasts[nelem(p.s)], *s, *l;
 	Hiddev *f = a;
@@ -766,7 +768,7 @@
 			continue;
 
 		/* combine all the slots */
-		abs = x = y = z = b = 0;
+		abs = x = y = z = b = binfo = 0;
 		for(i=0; i<p.ns; *l = *s, i++){
 			s = &p.s[i];
 
@@ -777,7 +779,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;
@@ -795,8 +797,9 @@
 			}
 
 			/* map to mouse buttons */
-			b |= s->b & 1;
-			if(s->b & (4|8))
+			binfo |= s->binfo;
+			b |= s->b & ~6;
+			if(s->b & 4)
 				b |= 2;
 			if(s->b & 2)
 				b |= 4;
@@ -818,6 +821,7 @@
 			}
 		}
 	
+		if(binfo == 0) b = lastb;
 		if(z != 0)
 			b |= z > 0 ? 8 : 16;


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

* Re: [9front] nusb/kb screwing up trackball button state
  2020-11-08  5:18 nusb/kb screwing up trackball button state umbraticus
@ 2020-11-08  5:29 ` umbraticus
  0 siblings, 0 replies; 2+ messages in thread
From: umbraticus @ 2020-11-08  5:29 UTC (permalink / raw)
  To: 9front

Oops, forgot the explanation. I recently got a Kensington trackball
which, when button state doesn't change, only sends XY info, like
this:

hidparse: t=8 f=6 usage=10030 v=0
hidparse: t=8 f=6 usage=10031 v=0
ptr[0]: id=102 b=0 m=0 x=0 y=0 z=0

But this results in button state being set to zero, even if buttons
are still held down, which makes selection, dragging, and menu use
impossible.  The patch below fixes it by using last button state when
no new state is sent.  I am a complete amateur in this area, so have
no idea if this is the correct approach: feedback very much
appreciated.

I also changed the logic that makes any button 4 act as a second
button 2.  Not sure if there was a reason this was in place...  It is
kind of nice being able to use extra buttons to scroll instead of
oversensitive scroll wheel.

umbraticus

diff -r eef7bc730924 sys/src/cmd/nusb/kb/kb.c
--- a/sys/src/cmd/nusb/kb/kb.c	Fri Nov 06 18:15:15 2020 -0800
+++ b/sys/src/cmd/nusb/kb/kb.c	Sun Nov 08 17:56:48 2020 +1300
@@ -65,6 +65,7 @@
 	int	y;
 	int	z;
 
+	int	binfo;
 	int	b;
 	int	m;
 
@@ -602,6 +603,7 @@
 		case 0x090008:
 			m = 1<<(l[Usage] - 0x090001);
 		Button:
+			s->binfo = 1;
 			s->m |= m;
 			s->b &= ~m;
 			if(v != 0)
@@ -629,7 +631,7 @@
 			s->h = v;
 			break;
 
-		case 0x0D0051:	/* Conteact identifier */
+		case 0x0D0051:	/* Contact identifier */
 			s->id = v;
 			break;
 
@@ -677,7 +679,7 @@
 	char	err[ERRMAX], mbuf[80];
 	uchar	lastk[64], uk, dk;
 	int	i, c, nerrs, lastb, nlastk;
-	int	abs, x, y, z, b;
+	int	abs, x, y, z, b, binfo;
 	Hidreport p;
 	Hidslot lasts[nelem(p.s)], *s, *l;
 	Hiddev *f = a;
@@ -766,7 +768,7 @@
 			continue;
 
 		/* combine all the slots */
-		abs = x = y = z = b = 0;
+		abs = x = y = z = b = binfo = 0;
 		for(i=0; i<p.ns; *l = *s, i++){
 			s = &p.s[i];
 
@@ -777,7 +779,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;
@@ -795,8 +797,9 @@
 			}
 
 			/* map to mouse buttons */
-			b |= s->b & 1;
-			if(s->b & (4|8))
+			binfo |= s->binfo;
+			b |= s->b & ~6;
+			if(s->b & 4)
 				b |= 2;
 			if(s->b & 2)
 				b |= 4;
@@ -818,6 +821,7 @@
 			}
 		}
 	
+		if(binfo == 0) b = lastb;
 		if(z != 0)
 			b |= z > 0 ? 8 : 16;


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

end of thread, other threads:[~2020-11-08  5:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-08  5:18 nusb/kb screwing up trackball button state umbraticus
2020-11-08  5:29 ` [9front] " umbraticus

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).