dwm-meillo
diff main.c @ 59:5d4653de9a1c
implemented dwm reading status text from stdin
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 11:57:33 +0200 |
parents | 1269bd127551 |
children | 24f9c674d03f |
line diff
1.1 --- a/main.c Fri Jul 14 10:34:07 2006 +0200 1.2 +++ b/main.c Fri Jul 14 11:57:33 2006 +0200 1.3 @@ -3,10 +3,12 @@ 1.4 * See LICENSE file for license details. 1.5 */ 1.6 1.7 +#include <errno.h> 1.8 #include <stdarg.h> 1.9 #include <stdio.h> 1.10 #include <stdlib.h> 1.11 #include <string.h> 1.12 +#include <unistd.h> 1.13 1.14 #include <X11/cursorfont.h> 1.15 #include <X11/Xatom.h> 1.16 @@ -19,7 +21,6 @@ 1.17 char *tags[TLast] = { 1.18 [Tscratch] = "scratch", 1.19 [Tdev] = "dev", 1.20 - [Tirc] = "irc", 1.21 [Twww] = "www", 1.22 [Twork] = "work", 1.23 }; 1.24 @@ -185,13 +186,13 @@ 1.25 int 1.26 main(int argc, char *argv[]) 1.27 { 1.28 - int i; 1.29 + int i, n; 1.30 + fd_set rd; 1.31 XSetWindowAttributes wa; 1.32 unsigned int mask; 1.33 Window w; 1.34 XEvent ev; 1.35 1.36 - /* command line args */ 1.37 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 1.38 switch (argv[i][1]) { 1.39 case 'v': 1.40 @@ -278,10 +279,31 @@ 1.41 scan_wins(); 1.42 draw_bar(); 1.43 1.44 + /* main event loop, reads status text from stdin as well */ 1.45 while(running) { 1.46 - XNextEvent(dpy, &ev); 1.47 - if(handler[ev.type]) 1.48 - (handler[ev.type])(&ev); /* call handler */ 1.49 + FD_ZERO(&rd); 1.50 + FD_SET(0, &rd); 1.51 + FD_SET(ConnectionNumber(dpy), &rd); 1.52 + 1.53 + i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); 1.54 + if(i == -1 && errno == EINTR) 1.55 + continue; 1.56 + if(i < 0) 1.57 + error("select failed\n"); 1.58 + else if(i > 0) { 1.59 + if(FD_ISSET(ConnectionNumber(dpy), &rd) && XPending(dpy) > 0) { 1.60 + XNextEvent(dpy, &ev); 1.61 + if(handler[ev.type]) 1.62 + (handler[ev.type])(&ev); /* call handler */ 1.63 + } 1.64 + if(FD_ISSET(0, &rd)) { 1.65 + i = n = 0; 1.66 + while((i = getchar()) != '\n' && n < sizeof(stext) - 1) 1.67 + stext[n++] = i; 1.68 + stext[n] = 0; 1.69 + draw_bar(); 1.70 + } 1.71 + } 1.72 } 1.73 1.74 cleanup();