dwm-meillo

changeset 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
files client.c main.c
diffstat 2 files changed, 22 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/client.c	Fri Jul 14 11:57:33 2006 +0200
     1.2 +++ b/client.c	Fri Jul 14 12:08:32 2006 +0200
     1.3 @@ -404,8 +404,6 @@
     1.4  	c->next = *l; /* *l == nil */
     1.5  	*l = c;
     1.6  
     1.7 -	XMapRaised(dpy, c->win);
     1.8 -	XMapRaised(dpy, c->title);
     1.9  	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
    1.10  			GrabModeAsync, GrabModeSync, None, None);
    1.11  	XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
    1.12 @@ -418,10 +416,17 @@
    1.13  			|| ((c->maxw == c->minw) && (c->maxh == c->minh));
    1.14  
    1.15  	arrange(NULL);
    1.16 -	if(c->tags[tsel])
    1.17 +	/* mapping the window now prevents flicker */
    1.18 +	if(c->tags[tsel]) {
    1.19 +		XMapRaised(dpy, c->win);
    1.20 +		XMapRaised(dpy, c->title);
    1.21  		focus(c);
    1.22 -	else
    1.23 +	}
    1.24 +	else {
    1.25  		ban_client(c);
    1.26 +		XMapRaised(dpy, c->win);
    1.27 +		XMapRaised(dpy, c->title);
    1.28 +	}
    1.29  }
    1.30  
    1.31  void
     2.1 --- a/main.c	Fri Jul 14 11:57:33 2006 +0200
     2.2 +++ b/main.c	Fri Jul 14 12:08:32 2006 +0200
     2.3 @@ -264,6 +264,10 @@
     2.4  	XDefineCursor(dpy, barwin, cursor[CurNormal]);
     2.5  	XMapRaised(dpy, barwin);
     2.6  
     2.7 +	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
     2.8 +	dc.gc = XCreateGC(dpy, root, 0, 0);
     2.9 +	draw_bar();
    2.10 +
    2.11  	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
    2.12  
    2.13  	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
    2.14 @@ -272,15 +276,12 @@
    2.15  
    2.16  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
    2.17  
    2.18 -	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
    2.19 -	dc.gc = XCreateGC(dpy, root, 0, 0);
    2.20 -
    2.21  	strcpy(stext, "dwm-"VERSION);
    2.22  	scan_wins();
    2.23 -	draw_bar();
    2.24  
    2.25  	/* main event loop, reads status text from stdin as well */
    2.26  	while(running) {
    2.27 +Mainloop:
    2.28  		FD_ZERO(&rd);
    2.29  		FD_SET(0, &rd);
    2.30  		FD_SET(ConnectionNumber(dpy), &rd);
    2.31 @@ -298,8 +299,15 @@
    2.32  			}
    2.33  			if(FD_ISSET(0, &rd)) {
    2.34  				i = n = 0;
    2.35 -				while((i = getchar()) != '\n' && n < sizeof(stext) - 1)
    2.36 +				for(;;) {
    2.37 +					if((i = getchar()) == EOF) {
    2.38 +						stext[0] = 0;
    2.39 +						goto Mainloop;
    2.40 +					}
    2.41 +					if(i == '\n' || n >= sizeof(stext) - 1)
    2.42 +						break;
    2.43  					stext[n++] = i;
    2.44 +				}
    2.45  				stext[n] = 0;
    2.46  				draw_bar();
    2.47  			}