dwm-meillo

diff main.c @ 60:24f9c674d03f

made stdin reader more robust
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 12:08:32 +0200
parents 5d4653de9a1c
children db93644de522
line diff
     1.1 --- a/main.c	Fri Jul 14 11:57:33 2006 +0200
     1.2 +++ b/main.c	Fri Jul 14 12:08:32 2006 +0200
     1.3 @@ -264,6 +264,10 @@
     1.4  	XDefineCursor(dpy, barwin, cursor[CurNormal]);
     1.5  	XMapRaised(dpy, barwin);
     1.6  
     1.7 +	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
     1.8 +	dc.gc = XCreateGC(dpy, root, 0, 0);
     1.9 +	draw_bar();
    1.10 +
    1.11  	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
    1.12  
    1.13  	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
    1.14 @@ -272,15 +276,12 @@
    1.15  
    1.16  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
    1.17  
    1.18 -	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
    1.19 -	dc.gc = XCreateGC(dpy, root, 0, 0);
    1.20 -
    1.21  	strcpy(stext, "dwm-"VERSION);
    1.22  	scan_wins();
    1.23 -	draw_bar();
    1.24  
    1.25  	/* main event loop, reads status text from stdin as well */
    1.26  	while(running) {
    1.27 +Mainloop:
    1.28  		FD_ZERO(&rd);
    1.29  		FD_SET(0, &rd);
    1.30  		FD_SET(ConnectionNumber(dpy), &rd);
    1.31 @@ -298,8 +299,15 @@
    1.32  			}
    1.33  			if(FD_ISSET(0, &rd)) {
    1.34  				i = n = 0;
    1.35 -				while((i = getchar()) != '\n' && n < sizeof(stext) - 1)
    1.36 +				for(;;) {
    1.37 +					if((i = getchar()) == EOF) {
    1.38 +						stext[0] = 0;
    1.39 +						goto Mainloop;
    1.40 +					}
    1.41 +					if(i == '\n' || n >= sizeof(stext) - 1)
    1.42 +						break;
    1.43  					stext[n++] = i;
    1.44 +				}
    1.45  				stext[n] = 0;
    1.46  				draw_bar();
    1.47  			}