comparison 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
comparison
equal deleted inserted replaced
58:1269bd127551 59:5d4653de9a1c
1 /* 1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
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>
13 #include <X11/Xproto.h> 15 #include <X11/Xproto.h>
14 16
17 /********** CUSTOMIZE **********/ 19 /********** CUSTOMIZE **********/
18 20
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 };
26 27
27 /********** CUSTOMIZE **********/ 28 /********** CUSTOMIZE **********/
183 } 184 }
184 185
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':
198 fprintf(stdout, "%s", version); 199 fprintf(stdout, "%s", version);
199 exit(0); 200 exit(0);
276 277
277 strcpy(stext, "dwm-"VERSION); 278 strcpy(stext, "dwm-"VERSION);
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();
288 XCloseDisplay(dpy); 310 XCloseDisplay(dpy);
289 311