summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSven Willner <sven.willner@gmail.com>2017-08-24 20:28:24 +0200
committerSven Willner <sven.willner@gmail.com>2017-08-24 20:28:24 +0200
commit2a981df18167cf8dd0a1310b03061010c8ef71dd (patch)
tree497849fe61e54db9f8fd028c654c7ef1cb50b22b /src/main.c
parent3b53d965289346b73a6af42225175768e5e202fc (diff)
added inotify support
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 57b7a7b..e8c30e2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,6 +34,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "wallpaper.h"
#include <termios.h>
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
+
char **cmdargv = NULL;
int cmdargc = 0;
char *mode = NULL;
@@ -54,6 +58,15 @@ int main(int argc, char **argv)
init_x_and_imlib();
init_keyevents();
init_buttonbindings();
+#ifdef HAVE_INOTIFY
+ if (opt.inotify) {
+ opt.inotify_fd = inotify_init();
+ if (opt.inotify_fd < 0) {
+ opt.inotify = 0;
+ eprintf("inotify_init failed");
+ }
+ }
+#endif
}
feh_event_init();
@@ -148,6 +161,13 @@ int feh_main_iteration(int block)
FD_SET(xfd, &fdset);
if (control_via_stdin)
FD_SET(STDIN_FILENO, &fdset);
+#ifdef HAVE_INOTIFY
+ if (opt.inotify) {
+ FD_SET(opt.inotify_fd, &fdset);
+ if (opt.inotify_fd >= fdsize)
+ fdsize = opt.inotify_fd + 1;
+ }
+#endif
/* Timers */
ft = first_timer;
@@ -193,6 +213,10 @@ int feh_main_iteration(int block)
}
else if (count && (FD_ISSET(0, &fdset)))
feh_event_handle_stdin();
+#ifdef HAVE_INOTIFY
+ else if (count && (FD_ISSET(opt.inotify_fd, &fdset)))
+ feh_event_handle_inotify();
+#endif
}
} else {
/* Don't block if there are events in the queue. That's a bit rude ;-) */
@@ -206,6 +230,10 @@ int feh_main_iteration(int block)
eprintf("Connection to X display lost");
else if (count && (FD_ISSET(0, &fdset)))
feh_event_handle_stdin();
+#ifdef HAVE_INOTIFY
+ else if (count && (FD_ISSET(opt.inotify_fd, &fdset)))
+ feh_event_handle_inotify();
+#endif
}
}
if (window_num == 0)
@@ -221,6 +249,12 @@ void feh_clean_exit(void)
free(opt.menu_bg);
free(opt.menu_font);
+#ifdef HAVE_INOTIFY
+ if (opt.inotify)
+ if (close(opt.inotify_fd))
+ eprintf("inotify close failed");
+#endif
+
if(disp)
XCloseDisplay(disp);