shithub: riscv

Download patch

ref: 8188b4f4f0e07b6669e6ae3c6c1099af917eaab4
parent: bd3c854f6022c48418ecd918fe921a9140d28f30
author: Jacob Moody <moody@posixcafe.org>
date: Sat Jan 28 05:30:00 EST 2023

rio: sync keyboard state with active window on switch

this addresses issues with stuck modifier keys when clicking
off and on from vncv with a modifier held.

--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -392,6 +392,7 @@
 	char *e;
 	char *watched;
 	Window *w, *cur;
+	static char keys[64];
 
 	threadsetname("keyboardtap");
 	enum { Awin, Actl, Afrom, Adev, Ato, Ainp, Awatch, NALT };
@@ -408,6 +409,7 @@
 
 	cur = nil;
 	watched = nil;
+	keys[0] = 0;
 	for(;;)
 		switch(alt(alts)){
 		case Awin:
@@ -414,16 +416,21 @@
 			cur = w;
 			if(cur != nil){
 				alts[Ainp].c = cur->ck;
-				if(tapseats[OREAD] == Tapoff)	
-					goto Reset;
-				if(alts[Awatch].op == CHANSND)
-					free(watched);
-				watched = smprint("%c%d", Tapfocus, cur->id);
-				alts[Awatch].op = CHANSND;
+				if(tapseats[OREAD] != Tapoff){	
+					if(alts[Awatch].op == CHANSND)
+						free(watched);
+					watched = smprint("%c%d", Tapfocus, cur->id);
+					alts[Awatch].op = CHANSND;
+				}
 			}
 			if(alts[Ainp].op != CHANNOP || alts[Ato].op != CHANNOP)
 				free(s);
-			goto Reset;
+			if(cur == nil)
+				goto Reset;
+			s = smprint("K%s", keys);
+			alts[Ainp].op = CHANSND;
+			alts[Ato].op = CHANNOP;
+			break;
 		case Actl:
 			e = tapctlmsg(ctl);
 			sendp(resptap, e);
@@ -444,6 +451,8 @@
 			alts[Ainp].op = CHANSND;
 			break;
 		case Adev:
+			if(*s == 'k' || *s == 'K')
+				strcpy(keys, s+1);
 			if(tapseats[OWRITE] == Tapoff && cur == nil){
 				free(s);
 				break;