summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 08:37:39 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 08:37:39 +0100
commit709e22459b6de9c28c4b4c10fde1b129b0558cd1 (patch)
tree0d74903927b0f2f183d3e3d56175a6eca38fcfee
parentdf096b4b4e15ac150fd582baa0521eacdf8d86e8 (diff)
downloadglslview-709e22459b6de9c28c4b4c10fde1b129b0558cd1.tar
glslview-709e22459b6de9c28c4b4c10fde1b129b0558cd1.zip
Make explicit reload also reset the inotify watch
-rw-r--r--glslview.c28
1 files changed, 22 insertions, 6 deletions
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;