From 709e22459b6de9c28c4b4c10fde1b129b0558cd1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 2 Feb 2016 08:37:39 +0100 Subject: Make explicit reload also reset the inotify watch --- glslview.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'glslview.c') diff --git a/glslview.c b/glslview.c index 251a13b..b443522 100644 --- a/glslview.c +++ b/glslview.c @@ -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; -- cgit v1.2.3