dwm.c
changeset 1054 28813060c35f
parent 1053 9990c1b25ceb
child 1055 f2838f633a85
equal deleted inserted replaced
1053:9990c1b25ceb 1054:28813060c35f
  1143 void
  1143 void
  1144 quit(const char *arg) {
  1144 quit(const char *arg) {
  1145 	readin = running = False;
  1145 	readin = running = False;
  1146 }
  1146 }
  1147 
  1147 
       
  1148 
  1148 void
  1149 void
  1149 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1150 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1150 	XWindowChanges wc;
  1151 	XWindowChanges wc;
  1151 
  1152 
  1152 	if(sizehints) {
  1153 	if(sizehints) {
  1278 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1279 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1279 }
  1280 }
  1280 
  1281 
  1281 void
  1282 void
  1282 run(void) {
  1283 run(void) {
       
  1284 	char *p;
  1283 	fd_set rd;
  1285 	fd_set rd;
  1284 	int xfd;
  1286 	int r, xfd;
       
  1287 	unsigned int len, offset;
  1285 	XEvent ev;
  1288 	XEvent ev;
  1286 
  1289 
  1287 	/* main event loop, also reads status text from stdin */
  1290 	/* main event loop, also reads status text from stdin */
  1288 	XSync(dpy, False);
  1291 	XSync(dpy, False);
  1289 	xfd = ConnectionNumber(dpy);
  1292 	xfd = ConnectionNumber(dpy);
  1290 	readin = True;
  1293 	readin = True;
  1291 	stext[sizeof stext - 1] = '\0'; /* 0-terminator is never touched */
  1294 	offset = 0;
       
  1295 	len = sizeof stext - 1;
       
  1296 	stext[len] = '\0'; /* 0-terminator is never touched */
  1292 	while(running) {
  1297 	while(running) {
  1293 		FD_ZERO(&rd);
  1298 		FD_ZERO(&rd);
  1294 		if(readin)
  1299 		if(readin)
  1295 			FD_SET(STDIN_FILENO, &rd);
  1300 			FD_SET(STDIN_FILENO, &rd);
  1296 		FD_SET(xfd, &rd);
  1301 		FD_SET(xfd, &rd);
  1298 			if(errno == EINTR)
  1303 			if(errno == EINTR)
  1299 				continue;
  1304 				continue;
  1300 			eprint("select failed\n");
  1305 			eprint("select failed\n");
  1301 		}
  1306 		}
  1302 		if(FD_ISSET(STDIN_FILENO, &rd)) {
  1307 		if(FD_ISSET(STDIN_FILENO, &rd)) {
  1303 			if((readin = (stext == fgets(stext, sizeof stext - 1, stdin))))
  1308 			switch((r = read(STDIN_FILENO, stext + offset, len - offset))) {
  1304 				stext[strlen(stext) - 1] = '\0'; /* remove tailing '\n' */
  1309 			case -1:
  1305 			else if(feof(stdin))
  1310 				strncpy(stext, strerror(errno), len);
       
  1311 				readin = False;
       
  1312 				break;
       
  1313 			case 0:
  1306 				strncpy(stext, "EOF", 4);
  1314 				strncpy(stext, "EOF", 4);
  1307 			else /* error occured */
  1315 				readin = False;
  1308 				strncpy(stext, strerror(errno), sizeof stext - 1);
  1316 				break;
       
  1317 			default:
       
  1318 				stext[offset + r] = '\0';
       
  1319 				for(p = stext; *p && *p != '\n'; p++);
       
  1320 				if(*p == '\n') {
       
  1321 					*p = '\0';
       
  1322 					offset = 0;
       
  1323 				}
       
  1324 				else if(offset + r < len - 1)
       
  1325 					offset += r;
       
  1326 				else
       
  1327 					offset = 0;
       
  1328 			}
  1309 			drawbar();
  1329 			drawbar();
  1310 		}
  1330 		}
  1311 		while(XPending(dpy)) {
  1331 		while(XPending(dpy)) {
  1312 			XNextEvent(dpy, &ev);
  1332 			XNextEvent(dpy, &ev);
  1313 			if(handler[ev.type])
  1333 			if(handler[ev.type])