X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=main.c;h=b59ff963f50f650dcb4163276d96bea485812867;hb=e7fa504c3e095db65853afd39d2d1324d439dcf4;hp=0e851b3d48b6cbff091d8c7e2d9933339241578d;hpb=eb756ee169ad0c94167ff41a9ab2712b348afe4f;p=dwm.git diff --git a/main.c b/main.c index 0e851b3..b59ff96 100644 --- a/main.c +++ b/main.c @@ -190,6 +190,7 @@ main(int argc, char *argv[]) fd_set rd; XSetWindowAttributes wa; unsigned int mask; + Bool readstdin = True; Window w; XEvent ev; @@ -280,10 +281,11 @@ main(int argc, char *argv[]) scan_wins(); /* main event loop, reads status text from stdin as well */ - while(running) { Mainloop: + while(running) { FD_ZERO(&rd); - FD_SET(0, &rd); + if(readstdin) + FD_SET(STDIN_FILENO, &rd); FD_SET(ConnectionNumber(dpy), &rd); i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); @@ -292,16 +294,20 @@ Mainloop: if(i < 0) error("select failed\n"); else if(i > 0) { - if(FD_ISSET(ConnectionNumber(dpy), &rd) && XPending(dpy) > 0) { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - (handler[ev.type])(&ev); /* call handler */ + if(FD_ISSET(ConnectionNumber(dpy), &rd)) { + while(XPending(dpy)) { + XNextEvent(dpy, &ev); + if(handler[ev.type]) + (handler[ev.type])(&ev); /* call handler */ + } } - if(FD_ISSET(0, &rd)) { + if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { i = n = 0; for(;;) { if((i = getchar()) == EOF) { - stext[0] = 0; + /* broken pipe/end of producer */ + readstdin = False; + strcpy(stext, "broken pipe"); goto Mainloop; } if(i == '\n' || n >= sizeof(stext) - 1)