shithub: riscv

Download patch

ref: d831a028dc82c4b20c4748b764bbfda3d9addc04
parent: 294e4f10971ccb746a6e15d5dd29b3caa685231c
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed May 11 05:23:01 EDT 2011

ignore \0 bytes, disable navigation keys when /dev/kbd is open

--- a/sys/src/cmd/aux/kbdfs.c
+++ b/sys/src/cmd/aux/kbdfs.c
@@ -400,7 +400,8 @@
 		x = buf + n;
 		while(p < x && fullrune(p, x - p)){
 			p += chartorune(&r, p);
-			send(rawchan, &r);
+			if(r)
+				send(rawchan, &r);
 		}
 		n = x - p;
 		if(n > 0){
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -337,6 +337,7 @@
 	char *s;
 
 	threadsetname("keyboardthread");
+
 	while(s = recvp(kbdchan)){
 		if(input == nil || sendp(input->ck, s) <= 0)
 			free(s);
@@ -360,8 +361,10 @@
 		r = runemalloc(cnt);
 		cvttorunes(s, cnt, r, &nb, &nr, nil);
 		for(i=0; i<nr; i++){
-			chanprint(kbdchan, "%C", r[i]);
-			chanprint(kbdchan, "");
+			if(r[i]){
+				chanprint(kbdchan, "%C", r[i]);
+				chanprint(kbdchan, "");
+			}
 		}
 		free(r);
 	}
@@ -1191,13 +1194,13 @@
 }
 
 static void
-kbdioproc(void *arg)
+kbdproc(void *arg)
 {
 	Channel *c = arg;
 	char buf[128], *p, *e;
 	int fd, cfd, kfd, n;
 
-	threadsetname("kbdioproc");
+	threadsetname("kbdproc");
 
 	if((fd = open("/dev/cons", OREAD)) < 0){
 		chanprint(c, "%r");
@@ -1234,8 +1237,10 @@
 			e = p + n;
 			while(p < e && fullrune(p, e - p)){
 				p += chartorune(&r, p);
-				chanprint(c, "%C", r);
-				chanprint(c, "");
+				if(r){
+					chanprint(c, "%C", r);
+					chanprint(c, "");
+				}
 			}
 			n = e - p;
 			if(n > 0){
@@ -1252,15 +1257,15 @@
 initkbd(void)
 {
 	Channel *c;
-	char *err;
+	char *e;
 
 	c = chancreate(sizeof(char*), 16);
-	proccreate(kbdioproc, c, STACK);
-	if(err = recvp(c)){
+	proccreate(kbdproc, c, STACK);
+	if(e = recvp(c)){
 		chanfree(c);
-		werrstr(err);
-		free(err);
-		return nil;
+		c = nil;
+		werrstr(e);
+		free(e);
 	}
 	return c;
 }
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -23,7 +23,6 @@
 
 static	int		topped;
 static	int		id;
-static	int		reverse;
 
 static	Image	*cols[NCOL];
 static	Image	*grey;
@@ -31,7 +30,6 @@
 static	Cursor	*lastcursor;
 static	Image	*titlecol;
 static	Image	*lighttitlecol;
-static	Image	*dholdcol;
 static	Image	*holdcol;
 static	Image	*lightholdcol;
 static	Image	*paleholdcol;
@@ -43,36 +41,19 @@
 	Rectangle r;
 
 	if(cols[0] == nil){
-		/* there are no pastel paints in the dungeons and dragons world
-		 * - rob pike
-		 */
-		reverse = 0;
-		if(getenv("reverse") != nil)
-			reverse = ~0xFF;
-
 		/* greys are multiples of 0x11111100+0xFF, 14* being palest */
-		grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF^reverse);
-		darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
-		cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse);
-		cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF^reverse);
+		grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF);
+		darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF);
+		cols[BACK] = display->white;
+		cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF);
 		cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);
-		cols[TEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
-		cols[HTEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
-		if(reverse == 0) {
-			titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
-			lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
-		} else {
-			titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPurpleblue);
-			lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
-		}
-		dholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
+		cols[TEXT] = display->black;
+		cols[HTEXT] = display->black;
+		titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
+		lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
+		holdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
 		lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue);
 		paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
-
-		if(reverse == 0)
-			holdcol = dholdcol;
-		else
-			holdcol = paleholdcol;
 	}
 	w = emalloc(sizeof(Window));
 	w->screenr = i->r;
@@ -623,8 +604,8 @@
 
 	if(w->deleted)
 		return;
-	/* navigation keys work only when mouse is not open */
-	if(!w->mouseopen)
+	/* navigation keys work only when mouse and kbd is not open */
+	if(!w->mouseopen && !w->kbdopen)
 		switch(r){
 		case Kdown:
 			n = w->maxlines/3;
@@ -759,7 +740,7 @@
 			w->cols[TEXT] = w->cols[HTEXT] = lightholdcol;
 	else
 		if(w == input)
-			w->cols[TEXT] = w->cols[HTEXT] = cols[TEXT];
+			w->cols[TEXT] = w->cols[HTEXT] = display->black;
 		else
 			w->cols[TEXT] = w->cols[HTEXT] = darkgrey;
 }
@@ -1360,6 +1341,7 @@
 		if(hidden[i] == w){
 			--nhidden;
 			memmove(hidden+i, hidden+i+1, (nhidden-i)*sizeof(hidden[0]));
+			hidden[nhidden] = nil;
 			break;
 		}
 	for(i=0; i<nwindow; i++)