main.c
changeset 65 4f7b232bd72d
parent 64 46d44d185464
child 73 c2ddb9dbbd10
equal deleted inserted replaced
64:46d44d185464 65:4f7b232bd72d
   188 {
   188 {
   189 	int i, n;
   189 	int i, n;
   190 	fd_set rd;
   190 	fd_set rd;
   191 	XSetWindowAttributes wa;
   191 	XSetWindowAttributes wa;
   192 	unsigned int mask;
   192 	unsigned int mask;
       
   193 	Bool readstdin = True;
   193 	Window w;
   194 	Window w;
   194 	XEvent ev;
   195 	XEvent ev;
   195 
   196 
   196 	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
   197 	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
   197 		switch (argv[i][1]) {
   198 		switch (argv[i][1]) {
   281 
   282 
   282 	/* main event loop, reads status text from stdin as well */
   283 	/* main event loop, reads status text from stdin as well */
   283 Mainloop:
   284 Mainloop:
   284 	while(running) {
   285 	while(running) {
   285 		FD_ZERO(&rd);
   286 		FD_ZERO(&rd);
   286 		FD_SET(STDIN_FILENO, &rd);
   287 		if(readstdin)
       
   288 			FD_SET(STDIN_FILENO, &rd);
   287 		FD_SET(ConnectionNumber(dpy), &rd);
   289 		FD_SET(ConnectionNumber(dpy), &rd);
   288 
   290 
   289 		i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
   291 		i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
   290 		if(i == -1 && errno == EINTR)
   292 		if(i == -1 && errno == EINTR)
   291 			continue;
   293 			continue;
   297 					XNextEvent(dpy, &ev);
   299 					XNextEvent(dpy, &ev);
   298 					if(handler[ev.type])
   300 					if(handler[ev.type])
   299 						(handler[ev.type])(&ev); /* call handler */
   301 						(handler[ev.type])(&ev); /* call handler */
   300 				}
   302 				}
   301 			}
   303 			}
   302 			if(FD_ISSET(STDIN_FILENO, &rd)) {
   304 			if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) {
   303 				i = n = 0;
   305 				i = n = 0;
   304 				for(;;) {
   306 				for(;;) {
   305 					if((i = getchar()) == EOF) {
   307 					if((i = getchar()) == EOF) {
   306 						stext[0] = 0;
   308 						/* broken pipe/end of producer */
       
   309 						readstdin = False;
       
   310 						strcpy(stext, "broken pipe");
   307 						goto Mainloop;
   311 						goto Mainloop;
   308 					}
   312 					}
   309 					if(i == '\n' || n >= sizeof(stext) - 1)
   313 					if(i == '\n' || n >= sizeof(stext) - 1)
   310 						break;
   314 						break;
   311 					stext[n++] = i;
   315 					stext[n++] = i;