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.
This commit is contained in:
mischief 2014-12-13 11:28:16 -08:00
parent 25a9cc3adb
commit ff4daa7e93

View file

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