JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
dwm is now exit, if stdin is closed due broken pipe
[dwm.git] / main.c
diff --git a/main.c b/main.c
index db36536..86d72fa 100644 (file)
--- a/main.c
+++ b/main.c
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/select.h>
 #include <X11/cursorfont.h>
 #include <X11/Xatom.h>
 #include <X11/Xproto.h>
@@ -84,9 +85,7 @@ xerrorstart(Display *dsply, XErrorEvent *ee)
 /* extern */
 
 char stext[1024];
-/* CUSTOMIZE */
-int tsel = Tdev; /* default tag */
-/* END CUSTOMIZE */
+int tsel = DEFTAG;
 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
 Atom wmatom[WMLast], netatom[NetLast];
 Bool running = True;
@@ -112,7 +111,7 @@ getproto(Window w)
        }
        for(i = 0; i < res; i++) {
                if(protocols[i] == wmatom[WMDelete])
-                       protos |= WM_PROTOCOL_DELWIN;
+                       protos |= PROTODELWIN;
        }
        free((char *) protocols);
        return protos;
@@ -163,10 +162,9 @@ xerror(Display *dpy, XErrorEvent *ee)
 int
 main(int argc, char *argv[])
 {
-       int i, n;
+       int i;
        unsigned int mask;
        fd_set rd;
-       Bool readin = True;
        Window w;
        XEvent ev;
        XSetWindowAttributes wa;
@@ -253,8 +251,7 @@ main(int argc, char *argv[])
        /* main event loop, reads status text from stdin as well */
        while(running) {
                FD_ZERO(&rd);
-               if(readin)
-                       FD_SET(STDIN_FILENO, &rd);
+               FD_SET(STDIN_FILENO, &rd);
                FD_SET(ConnectionNumber(dpy), &rd);
 
                i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
@@ -270,12 +267,11 @@ main(int argc, char *argv[])
                                                (handler[ev.type])(&ev); /* call handler */
                                }
                        }
-                       if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
-                               readin = NULL != fgets(stext, sizeof(stext), stdin);
-                               if(readin)
-                                       stext[strlen(stext) - 1] = 0;
+                       if(FD_ISSET(STDIN_FILENO, &rd)) {
+                               if(!fgets(stext, sizeof(stext), stdin))
+                                       break;
                                else 
-                                       strcpy(stext, "broken pipe");
+                                       stext[strlen(stext) - 1] = 0;
                                drawstatus();
                        }
                }