From 2a981df18167cf8dd0a1310b03061010c8ef71dd Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Thu, 24 Aug 2017 20:28:24 +0200 Subject: added inotify support --- src/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/main.c') 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 +#ifdef HAVE_INOTIFY +#include +#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); -- cgit v1.2.3