made stdin reader more robust eb756ee1
Anselm R. Garbe · 2006-07-14 12:08 2 file(s) · +22 −9
client.c +9 −4
404 404
	c->next = *l; /* *l == nil */
405 405
	*l = c;
406 406
407 -
	XMapRaised(dpy, c->win);
408 -
	XMapRaised(dpy, c->title);
409 407
	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
410 408
			GrabModeAsync, GrabModeSync, None, None);
411 409
	XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
418 416
			|| ((c->maxw == c->minw) && (c->maxh == c->minh));
419 417
420 418
	arrange(NULL);
421 -
	if(c->tags[tsel])
419 +
	/* mapping the window now prevents flicker */
420 +
	if(c->tags[tsel]) {
421 +
		XMapRaised(dpy, c->win);
422 +
		XMapRaised(dpy, c->title);
422 423
		focus(c);
423 -
	else
424 +
	}
425 +
	else {
424 426
		ban_client(c);
427 +
		XMapRaised(dpy, c->win);
428 +
		XMapRaised(dpy, c->title);
429 +
	}
425 430
}
426 431
427 432
void
main.c +13 −5
264 264
	XDefineCursor(dpy, barwin, cursor[CurNormal]);
265 265
	XMapRaised(dpy, barwin);
266 266
267 +
	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
268 +
	dc.gc = XCreateGC(dpy, root, 0, 0);
269 +
	draw_bar();
270 +
267 271
	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
268 272
269 273
	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
272 276
273 277
	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
274 278
275 -
	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
276 -
	dc.gc = XCreateGC(dpy, root, 0, 0);
277 -
278 279
	strcpy(stext, "dwm-"VERSION);
279 280
	scan_wins();
280 -
	draw_bar();
281 281
282 282
	/* main event loop, reads status text from stdin as well */
283 283
	while(running) {
284 +
Mainloop:
284 285
		FD_ZERO(&rd);
285 286
		FD_SET(0, &rd);
286 287
		FD_SET(ConnectionNumber(dpy), &rd);
298 299
			}
299 300
			if(FD_ISSET(0, &rd)) {
300 301
				i = n = 0;
301 -
				while((i = getchar()) != '\n' && n < sizeof(stext) - 1)
302 +
				for(;;) {
303 +
					if((i = getchar()) == EOF) {
304 +
						stext[0] = 0;
305 +
						goto Mainloop;
306 +
					}
307 +
					if(i == '\n' || n >= sizeof(stext) - 1)
308 +
						break;
302 309
					stext[n++] = i;
310 +
				}
303 311
				stext[n] = 0;
304 312
				draw_bar();
305 313
			}