diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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); |