diff options
-rw-r--r-- | glslview.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -31,6 +31,7 @@ static unsigned time_orig = 0; #ifdef USE_INOTIFY static int inotify_fd = -1; +static int inotify_watch = -1; #endif #endif @@ -122,6 +123,23 @@ static void load(void) { glDeleteProgram(program); } +#if defined(USE_INOTIFY) && !defined(GLSLWRITE) +static void reset_watch(void) { + if (inotify_watch >= 0) { + if (inotify_rm_watch(inotify_fd, inotify_watch)) { + fprintf(stderr, "unable to remove watch\n"); + exit(1); + } + } + + inotify_watch = inotify_add_watch(inotify_fd, filename, IN_CLOSE_WRITE); + if (inotify_watch < 0) { + fprintf(stderr, "unable to watch '%s' for changes\n", filename); + return; + } +} +#endif + static void init(void) { #if defined(USE_INOTIFY) && !defined(GLSLWRITE) inotify_fd = inotify_init(); @@ -130,14 +148,9 @@ static void init(void) { exit(1); } - int watch = inotify_add_watch(inotify_fd, filename, IN_CLOSE_WRITE); - if (watch < 0) { - fprintf(stderr, "unable to watch '%s' for changes\n", filename); - exit(1); - } - fcntl(inotify_fd, F_SETFL, fcntl(inotify_fd, F_GETFL)|O_NONBLOCK); + reset_watch(); #endif glewInit(); @@ -266,6 +279,9 @@ int main(int argc, char *argv[]) { #ifndef GLSLWRITE case SDLK_l: +#ifdef USE_INOTIFY + reset_watch(); +#endif load(); break; |