nsxiv9574150
Check file modification time after key handler
+10 −0
1 file changed
- M main.c +10 −0
| @@ -459,6 +459,7 @@ void key_handler(const char *key, unsigned int mask) | |||
| 459 | 459 | pid_t pid; | |
| 460 | 460 | int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel; | |
| 461 | 461 | char *cmd = exec[EXEC_KEY].cmd, kstr[32]; | |
| 462 | + | struct stat oldstat, newstat; | |
| 462 | 463 | ||
| 463 | 464 | if (cmd == NULL || key == NULL) | |
| 464 | 465 | return; | |
| @@ -468,6 +469,8 @@ void key_handler(const char *key, unsigned int mask) | |||
| 468 | 469 | mask & Mod1Mask ? "M-" : "", | |
| 469 | 470 | mask & ShiftMask ? "S-" : "", key); | |
| 470 | 471 | ||
| 472 | + | stat(files[n].path, &oldstat); | |
| 473 | + | ||
| 471 | 474 | if ((pid = fork()) == 0) { | |
| 472 | 475 | execl(cmd, cmd, kstr, files[n].path, NULL); | |
| 473 | 476 | warn("could not exec key handler"); | |
| @@ -482,6 +485,13 @@ void key_handler(const char *key, unsigned int mask) | |||
| 482 | 485 | retval = WEXITSTATUS(status); | |
| 483 | 486 | if (WIFEXITED(status) == 0 || retval != 0) | |
| 484 | 487 | warn("key handler exited with non-zero return value: %d", retval); | |
| 488 | + | ||
| 489 | + | if (stat(files[n].path, &newstat) == 0 && | |
| 490 | + | memcmp(&oldstat, &newstat, sizeof(oldstat)) == 0) | |
| 491 | + | { | |
| 492 | + | /* file has not changed */ | |
| 493 | + | return; | |
| 494 | + | } | |
| 485 | 495 | if (mode == MODE_IMAGE) { | |
| 486 | 496 | img_close(&img, true); | |
| 487 | 497 | load_image(fileidx); | |