Krolyxon
Commit 9574150

Branches

Refs →

nsxiv9574150

Check file modification time after key handler

Author
Bert Münnich
Date
2014-01-08 20:31 +0100
Parent
cd34aa2
Commit
9574150f2d54790a9482e9c49f118f99ab84c552

+10 −0

1 file changed

  1. M main.c +10 −0
M main.c View
@@ -459,6 +459,7 @@ void key_handler(const char *key, unsigned int mask)
459459 pid_t pid;
460460 int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
461461 char *cmd = exec[EXEC_KEY].cmd, kstr[32];
462+ struct stat oldstat, newstat;
462463
463464 if (cmd == NULL || key == NULL)
464465 return;
@@ -468,6 +469,8 @@ void key_handler(const char *key, unsigned int mask)
468469 mask & Mod1Mask ? "M-" : "",
469470 mask & ShiftMask ? "S-" : "", key);
470471
472+ stat(files[n].path, &oldstat);
473+
471474 if ((pid = fork()) == 0) {
472475 execl(cmd, cmd, kstr, files[n].path, NULL);
473476 warn("could not exec key handler");
@@ -482,6 +485,13 @@ void key_handler(const char *key, unsigned int mask)
482485 retval = WEXITSTATUS(status);
483486 if (WIFEXITED(status) == 0 || retval != 0)
484487 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+ }
485495 if (mode == MODE_IMAGE) {
486496 img_close(&img, true);
487497 load_image(fileidx);