dwm-meillo

diff main.c @ 578:8cb54d02a5b6

applied Manuels patch (thanks to Manuel!)
author arg@mig29
date Sat, 25 Nov 2006 19:26:16 +0100
parents f05cfa7d5128
children e9001b0f53bc
line diff
     1.1 --- a/main.c	Fri Nov 24 17:02:41 2006 +0100
     1.2 +++ b/main.c	Sat Nov 25 19:26:16 2006 +0100
     1.3 @@ -267,22 +267,29 @@
     1.4  		if(readin)
     1.5  			FD_SET(STDIN_FILENO, &rd);
     1.6  		FD_SET(xfd, &rd);
     1.7 -		r = select(xfd + 1, &rd, NULL, NULL, NULL);
     1.8 -		if((r == -1) && (errno == EINTR))
     1.9 -			continue;
    1.10 -		if(r > 0) {
    1.11 -			if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
    1.12 -				readin = NULL != fgets(stext, sizeof(stext), stdin);
    1.13 -				if(readin)
    1.14 -					stext[strlen(stext) - 1] = 0;
    1.15 -				else 
    1.16 -					strcpy(stext, "broken pipe");
    1.17 -				drawstatus();
    1.18 +		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
    1.19 +			if(errno == EINTR)
    1.20 +				continue;
    1.21 +			else
    1.22 +				eprint("select failed\n");
    1.23 +		}
    1.24 +		if(FD_ISSET(STDIN_FILENO, &rd)) {
    1.25 +			switch(r = read(STDIN_FILENO, stext, sizeof(stext))) {
    1.26 +			case -1:
    1.27 +				strncpy(stext, strerror(errno), sizeof(stext));
    1.28 +				readin = False;
    1.29 +				break;
    1.30 +			case 0:
    1.31 +				strncpy(stext, "EOF", sizeof(stext));
    1.32 +				readin = False;
    1.33 +				break;
    1.34 +			default:
    1.35 +				stext[r-1] = 0;
    1.36  			}
    1.37 +			drawstatus();
    1.38  		}
    1.39 -		else if(r < 0)
    1.40 -			eprint("select failed\n");
    1.41 -		procevent();
    1.42 +		if(FD_ISSET(xfd, &rd))
    1.43 +			procevent();
    1.44  	}
    1.45  	cleanup();
    1.46  	XCloseDisplay(dpy);