1278 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
1278 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
1279 } |
1279 } |
1280 |
1280 |
1281 void |
1281 void |
1282 run(void) { |
1282 run(void) { |
1283 char *p; |
|
1284 int r, xfd; |
|
1285 fd_set rd; |
1283 fd_set rd; |
|
1284 int xfd; |
1286 XEvent ev; |
1285 XEvent ev; |
1287 |
1286 |
1288 /* main event loop, also reads status text from stdin */ |
1287 /* main event loop, also reads status text from stdin */ |
1289 XSync(dpy, False); |
1288 XSync(dpy, False); |
1290 xfd = ConnectionNumber(dpy); |
1289 xfd = ConnectionNumber(dpy); |
1291 readin = True; |
1290 readin = True; |
|
1291 stext[sizeof stext - 1] = '\0'; /* 0-terminator is never touched */ |
1292 while(running) { |
1292 while(running) { |
1293 FD_ZERO(&rd); |
1293 FD_ZERO(&rd); |
1294 if(readin) |
1294 if(readin) |
1295 FD_SET(STDIN_FILENO, &rd); |
1295 FD_SET(STDIN_FILENO, &rd); |
1296 FD_SET(xfd, &rd); |
1296 FD_SET(xfd, &rd); |
1298 if(errno == EINTR) |
1298 if(errno == EINTR) |
1299 continue; |
1299 continue; |
1300 eprint("select failed\n"); |
1300 eprint("select failed\n"); |
1301 } |
1301 } |
1302 if(FD_ISSET(STDIN_FILENO, &rd)) { |
1302 if(FD_ISSET(STDIN_FILENO, &rd)) { |
1303 switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) { |
1303 if(stext == fgets(stext, sizeof stext - 1, stdin)) |
1304 case -1: |
1304 stext[strlen(stext) - 1] = '\0'; /* remove tailing '\n' */ |
|
1305 else |
1305 strncpy(stext, strerror(errno), sizeof stext - 1); |
1306 strncpy(stext, strerror(errno), sizeof stext - 1); |
1306 stext[sizeof stext - 1] = '\0'; |
|
1307 readin = False; |
|
1308 break; |
|
1309 case 0: |
|
1310 strncpy(stext, "EOF", 4); |
|
1311 readin = False; |
|
1312 break; |
|
1313 default: |
|
1314 for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0'); |
|
1315 for(; p >= stext && *p != '\n'; --p); |
|
1316 if(p > stext) |
|
1317 strncpy(stext, p + 1, sizeof stext); |
|
1318 } |
|
1319 drawbar(); |
1307 drawbar(); |
1320 } |
1308 } |
1321 while(XPending(dpy)) { |
1309 while(XPending(dpy)) { |
1322 XNextEvent(dpy, &ev); |
1310 XNextEvent(dpy, &ev); |
1323 if(handler[ev.type]) |
1311 if(handler[ev.type]) |