fd_set rd;
XSetWindowAttributes wa;
unsigned int mask;
+ Bool readstdin = True;
Window w;
XEvent ev;
XDefineCursor(dpy, barwin, cursor[CurNormal]);
XMapRaised(dpy, barwin);
+ dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
+ dc.gc = XCreateGC(dpy, root, 0, 0);
+ draw_bar();
+
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
- dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
- dc.gc = XCreateGC(dpy, root, 0, 0);
-
strcpy(stext, "dwm-"VERSION);
scan_wins();
- draw_bar();
/* main event loop, reads status text from stdin as well */
+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);
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;
- while((i = getchar()) != '\n' && n < sizeof(stext) - 1)
+ for(;;) {
+ if((i = getchar()) == EOF) {
+ /* broken pipe/end of producer */
+ readstdin = False;
+ strcpy(stext, "broken pipe");
+ goto Mainloop;
+ }
+ if(i == '\n' || n >= sizeof(stext) - 1)
+ break;
stext[n++] = i;
+ }
stext[n] = 0;
draw_bar();
}