X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=main.c;h=b59ff963f50f650dcb4163276d96bea485812867;hb=59b4a5e4cac68dfe6d245b8b708c3cb805f49f6d;hp=99e9f49cb3ef797165f41386e1c1b4f61763d930;hpb=9cd686c93a80b4095d4ee0960bef320ccd9ea02c;p=dwm.git diff --git a/main.c b/main.c index 99e9f49..b59ff96 100644 --- a/main.c +++ b/main.c @@ -3,10 +3,12 @@ * See LICENSE file for license details. */ +#include #include #include #include #include +#include #include #include @@ -19,7 +21,6 @@ char *tags[TLast] = { [Tscratch] = "scratch", [Tdev] = "dev", - [Tirc] = "irc", [Twww] = "www", [Twork] = "work", }; @@ -185,13 +186,14 @@ quit(Arg *arg) int main(int argc, char *argv[]) { - int i; + int i, n; + fd_set rd; XSetWindowAttributes wa; unsigned int mask; + Bool readstdin = True; Window w; XEvent ev; - /* command line args */ for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { switch (argv[i][1]) { case 'v': @@ -252,7 +254,7 @@ main(int argc, char *argv[]) wa.override_redirect = 1; wa.background_pixmap = ParentRelative; - wa.event_mask = ExposureMask; + wa.event_mask = ButtonPressMask | ExposureMask; bx = by = 0; bw = sw; @@ -263,6 +265,10 @@ main(int argc, char *argv[]) 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 \ @@ -271,17 +277,47 @@ main(int argc, char *argv[]) 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) { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - (handler[ev.type])(&ev); /* call handler */ + FD_ZERO(&rd); + if(readstdin) + FD_SET(STDIN_FILENO, &rd); + FD_SET(ConnectionNumber(dpy), &rd); + + i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); + if(i == -1 && errno == EINTR) + continue; + if(i < 0) + error("select failed\n"); + else if(i > 0) { + if(FD_ISSET(ConnectionNumber(dpy), &rd)) { + while(XPending(dpy)) { + XNextEvent(dpy, &ev); + if(handler[ev.type]) + (handler[ev.type])(&ev); /* call handler */ + } + } + if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { + i = n = 0; + 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(); + } + } } cleanup();