diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-14 11:57:33 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-14 11:57:33 +0200 |
| commit | 0e5c8198bc5a69e87b0114b81d6569188828edfa (patch) | |
| tree | ac564b321cca1acb88bfe3ba720e77fa8fb12fe5 /main.c | |
| parent | made barclick to select the specific tag (diff) | |
| download | dwm-0e5c8198bc5a69e87b0114b81d6569188828edfa.tar.gz dwm-0e5c8198bc5a69e87b0114b81d6569188828edfa.zip | |
implemented dwm reading status text from stdin
Diffstat (limited to '')
| -rw-r--r-- | main.c | 34 |
1 files changed, 28 insertions, 6 deletions
| @@ -3,10 +3,12 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <errno.h> | ||
| 6 | #include <stdarg.h> | 7 | #include <stdarg.h> |
| 7 | #include <stdio.h> | 8 | #include <stdio.h> |
| 8 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 9 | #include <string.h> | 10 | #include <string.h> |
| 11 | #include <unistd.h> | ||
| 10 | 12 | ||
| 11 | #include <X11/cursorfont.h> | 13 | #include <X11/cursorfont.h> |
| 12 | #include <X11/Xatom.h> | 14 | #include <X11/Xatom.h> |
| @@ -19,7 +21,6 @@ | |||
| 19 | char *tags[TLast] = { | 21 | char *tags[TLast] = { |
| 20 | [Tscratch] = "scratch", | 22 | [Tscratch] = "scratch", |
| 21 | [Tdev] = "dev", | 23 | [Tdev] = "dev", |
| 22 | [Tirc] = "irc", | ||
| 23 | [Twww] = "www", | 24 | [Twww] = "www", |
| 24 | [Twork] = "work", | 25 | [Twork] = "work", |
| 25 | }; | 26 | }; |
| @@ -185,13 +186,13 @@ quit(Arg *arg) | |||
| 185 | int | 186 | int |
| 186 | main(int argc, char *argv[]) | 187 | main(int argc, char *argv[]) |
| 187 | { | 188 | { |
| 188 | int i; | 189 | int i, n; |
| 190 | fd_set rd; | ||
| 189 | XSetWindowAttributes wa; | 191 | XSetWindowAttributes wa; |
| 190 | unsigned int mask; | 192 | unsigned int mask; |
| 191 | Window w; | 193 | Window w; |
| 192 | XEvent ev; | 194 | XEvent ev; |
| 193 | 195 | ||
| 194 | /* command line args */ | ||
| 195 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | 196 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { |
| 196 | switch (argv[i][1]) { | 197 | switch (argv[i][1]) { |
| 197 | case 'v': | 198 | case 'v': |
| @@ -278,10 +279,31 @@ main(int argc, char *argv[]) | |||
| 278 | scan_wins(); | 279 | scan_wins(); |
| 279 | draw_bar(); | 280 | draw_bar(); |
| 280 | 281 | ||
| 282 | /* main event loop, reads status text from stdin as well */ | ||
| 281 | while(running) { | 283 | while(running) { |
| 282 | XNextEvent(dpy, &ev); | 284 | FD_ZERO(&rd); |
| 283 | if(handler[ev.type]) | 285 | FD_SET(0, &rd); |
| 284 | (handler[ev.type])(&ev); /* call handler */ | 286 | FD_SET(ConnectionNumber(dpy), &rd); |
| 287 | |||
| 288 | i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); | ||
| 289 | if(i == -1 && errno == EINTR) | ||
| 290 | continue; | ||
| 291 | if(i < 0) | ||
| 292 | error("select failed\n"); | ||
| 293 | else if(i > 0) { | ||
| 294 | if(FD_ISSET(ConnectionNumber(dpy), &rd) && XPending(dpy) > 0) { | ||
| 295 | XNextEvent(dpy, &ev); | ||
| 296 | if(handler[ev.type]) | ||
| 297 | (handler[ev.type])(&ev); /* call handler */ | ||
| 298 | } | ||
| 299 | if(FD_ISSET(0, &rd)) { | ||
| 300 | i = n = 0; | ||
| 301 | while((i = getchar()) != '\n' && n < sizeof(stext) - 1) | ||
| 302 | stext[n++] = i; | ||
| 303 | stext[n] = 0; | ||
| 304 | draw_bar(); | ||
| 305 | } | ||
| 306 | } | ||
| 285 | } | 307 | } |
| 286 | 308 | ||
| 287 | cleanup(); | 309 | cleanup(); |
