shithub: riscv

Download patch

ref: ff4daa7e93f4ea09506276ecdb69fa1cca19a7a7
parent: 25a9cc3adbf9f9af8e71dc6125fc32a9a17ab839
author: mischief <mischief@offblast.org>
date: Sat Dec 13 06:28:16 EST 2014

stats: handle 'q' to close

a side effect of this is keys typed other than q/Del no longer get drawn on top of the window.

--- a/sys/src/cmd/stats.c
+++ b/sys/src/cmd/stats.c
@@ -5,6 +5,7 @@
 #include <fcall.h>
 #include <draw.h>
 #include <event.h>
+#include <keyboard.h>
 
 #define	MAXNUM	10	/* maximum number of numbers on data line */
 
@@ -85,7 +86,7 @@
 enum
 {
 	Mainproc,
-	Mouseproc,
+	Inputproc,
 	NPROC,
 };
 
@@ -204,7 +205,7 @@
 int	oldsystem = 0;
 int 	sleeptime = 1000;
 
-char	*procnames[NPROC] = {"main", "mouse"};
+char	*procnames[NPROC] = {"main", "input"};
 
 void
 killall(char *s)
@@ -1238,29 +1239,36 @@
 }
 
 void
-mouseproc(void)
+inputproc(void)
 {
-	Mouse mouse;
+	Event e;
 	int i;
 
 	for(;;){
-		mouse = emouse();
-		if(mouse.buttons == 4){
-			lockdisplay(display);
-			for(i=0; i<Nmenu2; i++)
-				if(present[i])
-					memmove(menu2str[i], "drop ", Opwid);
-				else
-					memmove(menu2str[i], "add  ", Opwid);
-			i = emenuhit(3, &mouse, &menu2);
-			if(i >= 0){
-				if(!present[i])
-					addgraph(i);
-				else if(ngraph > 1)
-					dropgraph(i);
-				resize();
+		switch(eread(Emouse|Ekeyboard, &e)){
+		case Emouse:
+			if(e.mouse.buttons == 4){
+				lockdisplay(display);
+				for(i=0; i<Nmenu2; i++)
+					if(present[i])
+						memmove(menu2str[i], "drop ", Opwid);
+					else
+						memmove(menu2str[i], "add  ", Opwid);
+				i = emenuhit(3, &e.mouse, &menu2);
+				if(i >= 0){
+					if(!present[i])
+						addgraph(i);
+					else if(ngraph > 1)
+						dropgraph(i);
+					resize();
+				}
+				unlockdisplay(display);
 			}
-			unlockdisplay(display);
+			break;
+		case Ekeyboard:
+			if(e.kbdc==Kdel || e.kbdc=='q')
+				killall(nil);
+			break;
 		}
 	}
 }
@@ -1413,8 +1421,8 @@
 		exits("initdraw");
 	}
 	colinit();
-	einit(Emouse);
-	startproc(mouseproc, Mouseproc);
+	einit(Emouse|Ekeyboard);
+	startproc(inputproc, Inputproc);
 	pids[Mainproc] = getpid();
 	display->locking = 1;	/* tell library we're using the display lock */