* See LICENSE file for license details.
*/
+#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
char *tags[TLast] = {
[Tscratch] = "scratch",
[Tdev] = "dev",
- [Tirc] = "irc",
[Twww] = "www",
[Twork] = "work",
};
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':
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
- wa.event_mask = ExposureMask;
+ wa.event_mask = ButtonPressMask | ExposureMask;
bx = by = 0;
bw = sw;
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) {
- 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();