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 --- config.mk | 7 ++++++ man/Makefile | 1 + man/feh.pre | 8 ++++++- src/feh.h | 3 +++ src/filelist.c | 2 +- src/help.raw | 1 + src/main.c | 34 +++++++++++++++++++++++++++++ src/options.c | 12 +++++++++++ src/options.h | 4 ++++ src/winwidget.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/winwidget.h | 4 ++++ 11 files changed, 140 insertions(+), 3 deletions(-) diff --git a/config.mk b/config.mk index 93bb1c3..c133e46 100644 --- a/config.mk +++ b/config.mk @@ -73,6 +73,13 @@ else MAN_EXIF = disabled endif +ifeq (${inotify},1) + CFLAGS += -DHAVE_INOTIFY + MAN_INOTIFY = enabled +else + MAN_INOTIFY = disabled +endif + MAN_DATE ?= ${shell date '+%B %d, %Y'} # Uncomment this to use dmalloc diff --git a/man/Makefile b/man/Makefile index 65f2bc2..3be07e3 100644 --- a/man/Makefile +++ b/man/Makefile @@ -12,6 +12,7 @@ all: ${TARGETS} -e 's/\$$MAN_CURL\$$/${MAN_CURL}/' \ -e 's/\$$MAN_DEBUG\$$/${MAN_DEBUG}/' \ -e 's/\$$MAN_EXIF\$$/${MAN_EXIF}/' \ + -e 's/\$$MAN_INOTIFY\$$/${MAN_INOTIFY}/' \ -e 's/\$$MAN_XINERAMA\$$/${MAN_XINERAMA}/' \ < ${@:.1=.pre} > $@ diff --git a/man/feh.pre b/man/feh.pre index 4a8b0f8..19d6d6d 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -25,7 +25,8 @@ $VERSION$ .Pp . Compile-time switches: libcurl support $MAN_CURL$, Xinerama support -$MAN_XINERAMA$, builtin EXIF support $MAN_EXIF$$MAN_DEBUG$ +$MAN_XINERAMA$, builtin EXIF support $MAN_EXIF$, inotify support +$MAN_INOTIFY$$MAN_DEBUG$ . . .Sh DESCRIPTION @@ -396,6 +397,11 @@ is set to the output will not be displayed by default, but has to be enabled by the toggle_info key. . +.It Cm --inotify +. +.Pq only if compiled with inotify=1 +automatically reload shown image if file was changed +. .It Cm -k , --keep-http . When viewing files using HTTP, diff --git a/src/feh.h b/src/feh.h index 4572652..9778efb 100644 --- a/src/feh.h +++ b/src/feh.h @@ -173,6 +173,9 @@ void feh_edit_inplace_lossless(winwidget w, int orientation); gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style); char *build_caption_filename(feh_file * file, short create_dir); gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num); +#ifdef HAVE_INOTIFY +void feh_event_handle_inotify(void); +#endif /* Imlib stuff */ extern Display *disp; diff --git a/src/filelist.c b/src/filelist.c index b569b8a..162fd57 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -75,7 +75,7 @@ void feh_file_free(feh_file * file) #ifdef HAVE_LIBEXIF if (file->ed) exif_data_unref(file->ed); -#endif +#endif free(file); return; } diff --git a/src/help.raw b/src/help.raw index 067e35f..339e1f3 100644 --- a/src/help.raw +++ b/src/help.raw @@ -94,6 +94,7 @@ OPTIONS --min-dimension WxH Only show images with width >= W and height >= H --max-dimension WxH Only show images with width <= W and height <= H --scroll-step COUNT scroll COUNT pixels when movement key is pressed + --inotify automatically reload shown image if file was changed MONTAGE MODE OPTIONS -X, --ignore-aspect Set thumbnail to specified width/height without 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); diff --git a/src/options.c b/src/options.c index 56323a8..d06a4e7 100644 --- a/src/options.c +++ b/src/options.c @@ -409,6 +409,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) {"xinerama-index", 1, 0, 239}, {"insecure" , 0, 0, 240}, {"no-recursive" , 0, 0, 241}, +#ifdef HAVE_INOTIFY + {"inotify" , 0, 0, 243}, +#endif {0, 0, 0, 0} }; int optch = 0, cmdx = 0; @@ -734,6 +737,11 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) case 242: opt.auto_rotate = 1; break; +#endif +#ifdef HAVE_INOTIFY + case 243: + opt.inotify = 1; + break; #endif case 224: opt.cycle_once = 1; @@ -852,6 +860,10 @@ static void show_version(void) "exif " #endif +#ifdef HAVE_INOTIFY + "inotify " +#endif + #ifdef INCLUDE_HELP "help " #endif diff --git a/src/options.h b/src/options.h index 5a5ce84..19ff55c 100644 --- a/src/options.h +++ b/src/options.h @@ -52,6 +52,10 @@ struct __fehoptions { #ifdef HAVE_LIBEXIF unsigned char draw_exif; unsigned char auto_rotate; +#endif +#ifdef HAVE_INOTIFY + unsigned char inotify; + int inotify_fd; #endif unsigned char list; unsigned char quiet; diff --git a/src/winwidget.c b/src/winwidget.c index 6f64844..1a0bc7d 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -30,6 +30,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "options.h" #include "events.h" +#ifdef HAVE_INOTIFY +#include +#endif + static void winwidget_unregister(winwidget win); static void winwidget_register(winwidget win); static winwidget winwidget_allocate(void); @@ -78,6 +82,10 @@ static winwidget winwidget_allocate(void) ret->click_offset_y = 0; ret->has_rotated = 0; +#ifdef HAVE_INOTIFY + ret->inotify_wd = -1; +#endif + return(ret); } @@ -755,6 +763,14 @@ void winwidget_destroy_xwin(winwidget winwid) void winwidget_destroy(winwidget winwid) { +#ifdef HAVE_INOTIFY + if (winwid->inotify_wd >= 0) { + D(("Removing inotify watch\n")); + if (inotify_rm_watch(opt.inotify_fd, winwid->inotify_wd)) + eprintf("inotify_rm_watch failed"); + winwid->inotify_wd = -1; + } +#endif winwidget_destroy_xwin(winwid); if (winwid->name) free(winwid->name); @@ -768,6 +784,34 @@ void winwidget_destroy(winwidget winwid) return; } +#ifdef HAVE_INOTIFY +#define INOTIFY_BUFFER_LEN (1024 * (sizeof (struct inotify_event)) + 16) +void feh_event_handle_inotify(void) +{ + D(("Received inotify events\n")); + char buf[INOTIFY_BUFFER_LEN]; + int i = 0; + int len = read (opt.inotify_fd, buf, INOTIFY_BUFFER_LEN); + if (len < 0) { + if (errno != EINTR) + eprintf("inotify event read failed"); + } else if (!len) + eprintf("inotify event read failed"); + while (i < len) { + struct inotify_event *event; + event = (struct inotify_event *) &buf[i]; + for (int i = 0; i < window_num; i++) { + if(windows[i]->inotify_wd == event->wd) { + windows[i]->inotify_wd = -1; + feh_reload_image(windows[i], 0, 1); + break; + } + } + i += sizeof(struct inotify_event) + event->len; + } +} +#endif + void winwidget_destroy_all(void) { int i; @@ -801,7 +845,28 @@ winwidget winwidget_get_first_window_of_type(unsigned int type) int winwidget_loadimage(winwidget winwid, feh_file * file) { D(("filename %s\n", file->filename)); - return(feh_load_image(&(winwid->im), file)); +#ifdef HAVE_INOTIFY + if (winwid->inotify_wd >= 0) { + D(("Removing inotify watch\n")); + if (inotify_rm_watch(opt.inotify_fd, winwid->inotify_wd)) + eprintf("inotify_rm_watch failed"); + winwid->inotify_wd = -1; + } +#endif + int res = feh_load_image(&(winwid->im), file); +#ifdef HAVE_INOTIFY + if (res) { + if (opt.inotify) { + D(("Adding inotify watch for %s\n", file->filename)); + winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, + file->filename, + IN_CLOSE_WRITE); + if (winwid->inotify_wd < 0) + eprintf("inotify_add_watch failed"); + } + } +#endif + return(res); } void winwidget_show(winwidget winwid) diff --git a/src/winwidget.h b/src/winwidget.h index 6a794e7..0555201 100644 --- a/src/winwidget.h +++ b/src/winwidget.h @@ -116,6 +116,10 @@ struct __winwidget { time_t click_start_time; unsigned char has_rotated; + +#ifdef HAVE_INOTIFY + int inotify_wd; +#endif }; int winwidget_loadimage(winwidget winwid, feh_file * filename); -- cgit v1.2.3 From 177cbff6af7b9845d592fb0497464d70ee423418 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Fri, 1 Sep 2017 14:51:21 +0200 Subject: fixed inotify for thumbnail mode --- src/thumbnail.c | 6 ++++++ src/winwidget.c | 50 +++++++++++++++++++++++++++++--------------------- src/winwidget.h | 5 +++++ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/thumbnail.c b/src/thumbnail.c index edf0f4f..b7108c8 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -790,7 +790,13 @@ void feh_thumbnail_show_fullsize(feh_file *thumbfile) free(thumbwin->file); thumbwin->file = gib_list_add_front(NULL, thumbfile); winwidget_rename(thumbwin, s); +#ifdef HAVE_INOTIFY + winwidget_inotify_remove(thumbwin); +#endif feh_reload_image(thumbwin, 1, 1); +#ifdef HAVE_INOTIFY + winwidget_inotify_add(thumbwin, thumbfile->filename); +#endif } } diff --git a/src/winwidget.c b/src/winwidget.c index 1a0bc7d..039a582 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -764,12 +764,7 @@ void winwidget_destroy_xwin(winwidget winwid) void winwidget_destroy(winwidget winwid) { #ifdef HAVE_INOTIFY - if (winwid->inotify_wd >= 0) { - D(("Removing inotify watch\n")); - if (inotify_rm_watch(opt.inotify_fd, winwid->inotify_wd)) - eprintf("inotify_rm_watch failed"); - winwid->inotify_wd = -1; - } + winwidget_inotify_remove(winwid); #endif winwidget_destroy_xwin(winwid); if (winwid->name) @@ -784,6 +779,32 @@ void winwidget_destroy(winwidget winwid) return; } +#ifdef HAVE_INOTIFY +void winwidget_inotify_remove(winwidget winwid) +{ + if (winwid->inotify_wd >= 0) { + D(("Removing inotify watch\n")); + if (inotify_rm_watch(opt.inotify_fd, winwid->inotify_wd)) + eprintf("inotify_rm_watch failed"); + winwid->inotify_wd = -1; + } +} +#endif + +#ifdef HAVE_INOTIFY +void winwidget_inotify_add(winwidget winwid, char *filename) +{ + if (opt.inotify) { + D(("Adding inotify watch for %s\n", filename)); + winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, + filename, + IN_CLOSE_WRITE); + if (winwid->inotify_wd < 0) + eprintf("inotify_add_watch failed"); + } +} +#endif + #ifdef HAVE_INOTIFY #define INOTIFY_BUFFER_LEN (1024 * (sizeof (struct inotify_event)) + 16) void feh_event_handle_inotify(void) @@ -802,7 +823,6 @@ void feh_event_handle_inotify(void) event = (struct inotify_event *) &buf[i]; for (int i = 0; i < window_num; i++) { if(windows[i]->inotify_wd == event->wd) { - windows[i]->inotify_wd = -1; feh_reload_image(windows[i], 0, 1); break; } @@ -846,24 +866,12 @@ int winwidget_loadimage(winwidget winwid, feh_file * file) { D(("filename %s\n", file->filename)); #ifdef HAVE_INOTIFY - if (winwid->inotify_wd >= 0) { - D(("Removing inotify watch\n")); - if (inotify_rm_watch(opt.inotify_fd, winwid->inotify_wd)) - eprintf("inotify_rm_watch failed"); - winwid->inotify_wd = -1; - } + winwidget_inotify_remove(winwid); #endif int res = feh_load_image(&(winwid->im), file); #ifdef HAVE_INOTIFY if (res) { - if (opt.inotify) { - D(("Adding inotify watch for %s\n", file->filename)); - winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, - file->filename, - IN_CLOSE_WRITE); - if (winwid->inotify_wd < 0) - eprintf("inotify_add_watch failed"); - } + winwidget_inotify_add(winwid, file->filename); } #endif return(res); diff --git a/src/winwidget.h b/src/winwidget.h index 0555201..d6b9546 100644 --- a/src/winwidget.h +++ b/src/winwidget.h @@ -122,6 +122,11 @@ struct __winwidget { #endif }; +#ifdef HAVE_INOTIFY +void winwidget_inotify_remove(winwidget winwid); +void winwidget_inotify_add(winwidget winwid, char *filename); +#endif + int winwidget_loadimage(winwidget winwid, feh_file * filename); void winwidget_show(winwidget winwid); void winwidget_show_menu(winwidget winwid); -- cgit v1.2.3 From f5ce98d3f379a810103e37fa36baf241668387f1 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Fri, 1 Sep 2017 18:16:45 +0200 Subject: changed option from inotify to auto-reload --- man/feh.pre | 10 +++++----- src/help.raw | 2 +- src/main.c | 8 ++++---- src/options.c | 4 ++-- src/options.h | 2 +- src/winwidget.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/man/feh.pre b/man/feh.pre index 19d6d6d..b258b2b 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -192,6 +192,11 @@ for details. Example usage: . Extra actions which can be set and triggered using the appropriate number key. . +.It Cm --auto-reload +. +.Pq only if compiled with inotify=1 +automatically reload shown image if file was changed +. .It Cm --auto-rotate . .Pq only if compiled with exif=1 @@ -397,11 +402,6 @@ is set to the output will not be displayed by default, but has to be enabled by the toggle_info key. . -.It Cm --inotify -. -.Pq only if compiled with inotify=1 -automatically reload shown image if file was changed -. .It Cm -k , --keep-http . When viewing files using HTTP, diff --git a/src/help.raw b/src/help.raw index 339e1f3..997a259 100644 --- a/src/help.raw +++ b/src/help.raw @@ -94,7 +94,7 @@ OPTIONS --min-dimension WxH Only show images with width >= W and height >= H --max-dimension WxH Only show images with width <= W and height <= H --scroll-step COUNT scroll COUNT pixels when movement key is pressed - --inotify automatically reload shown image if file was changed + --auto-reload automatically reload shown image if file was changed MONTAGE MODE OPTIONS -X, --ignore-aspect Set thumbnail to specified width/height without diff --git a/src/main.c b/src/main.c index e8c30e2..b935e53 100644 --- a/src/main.c +++ b/src/main.c @@ -59,10 +59,10 @@ int main(int argc, char **argv) init_keyevents(); init_buttonbindings(); #ifdef HAVE_INOTIFY - if (opt.inotify) { + if (opt.auto_reload) { opt.inotify_fd = inotify_init(); if (opt.inotify_fd < 0) { - opt.inotify = 0; + opt.auto_reload = 0; eprintf("inotify_init failed"); } } @@ -162,7 +162,7 @@ int feh_main_iteration(int block) if (control_via_stdin) FD_SET(STDIN_FILENO, &fdset); #ifdef HAVE_INOTIFY - if (opt.inotify) { + if (opt.auto_reload) { FD_SET(opt.inotify_fd, &fdset); if (opt.inotify_fd >= fdsize) fdsize = opt.inotify_fd + 1; @@ -250,7 +250,7 @@ void feh_clean_exit(void) free(opt.menu_font); #ifdef HAVE_INOTIFY - if (opt.inotify) + if (opt.auto_reload) if (close(opt.inotify_fd)) eprintf("inotify close failed"); #endif diff --git a/src/options.c b/src/options.c index d06a4e7..20e6272 100644 --- a/src/options.c +++ b/src/options.c @@ -410,7 +410,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) {"insecure" , 0, 0, 240}, {"no-recursive" , 0, 0, 241}, #ifdef HAVE_INOTIFY - {"inotify" , 0, 0, 243}, + {"auto-reload" , 0, 0, 243}, #endif {0, 0, 0, 0} }; @@ -740,7 +740,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) #endif #ifdef HAVE_INOTIFY case 243: - opt.inotify = 1; + opt.auto_reload = 1; break; #endif case 224: diff --git a/src/options.h b/src/options.h index 19ff55c..2cfef2f 100644 --- a/src/options.h +++ b/src/options.h @@ -54,7 +54,7 @@ struct __fehoptions { unsigned char auto_rotate; #endif #ifdef HAVE_INOTIFY - unsigned char inotify; + unsigned char auto_reload; int inotify_fd; #endif unsigned char list; diff --git a/src/winwidget.c b/src/winwidget.c index 039a582..b2c340e 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -794,7 +794,7 @@ void winwidget_inotify_remove(winwidget winwid) #ifdef HAVE_INOTIFY void winwidget_inotify_add(winwidget winwid, char *filename) { - if (opt.inotify) { + if (opt.auto_reload) { D(("Adding inotify watch for %s\n", filename)); winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, filename, -- cgit v1.2.3 From c50d376d615e966cbb55ceeef57a204586f1e802 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Fri, 27 Oct 2017 17:42:02 +0200 Subject: fixed inotify for overwritten files --- src/winwidget.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/winwidget.c b/src/winwidget.c index b2c340e..9270d69 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -821,9 +821,16 @@ void feh_event_handle_inotify(void) while (i < len) { struct inotify_event *event; event = (struct inotify_event *) &buf[i]; - for (int i = 0; i < window_num; i++) { - if(windows[i]->inotify_wd == event->wd) { - feh_reload_image(windows[i], 0, 1); + for (int j = 0; j < window_num; j++) { + if(windows[j]->inotify_wd == event->wd) { + if (event->mask & IN_IGNORED) { + D(("Inotify watch was implicitely removed\n")); + feh_reload_image(windows[j], 0, 1); + winwidget_inotify_add(windows[j], FEH_FILE(windows[j]->file->data)->filename); + } else if (event->mask & IN_CLOSE_WRITE) { + D(("Inotify says file changed\n")); + feh_reload_image(windows[j], 0, 1); + } break; } } -- cgit v1.2.3 From dc3d387adf66790b2a9ab2a3b6a67bcb5e6c5a80 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Fri, 27 Oct 2017 17:42:13 +0200 Subject: added inotify option to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 328897a..63659c0 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Available flags are: | debug | 0 | debug build, enables `--debug` | | exif | 0 | Builtin EXIF tag display support | | help | 0 | include help text (refers to the manpage otherwise) | +| inotify | 0 | enable inotify, needed for `--auto-reload` | | stat64 | 0 | Support CIFS shares from 64bit hosts on 32bit machines | | xinerama | 1 | Support Xinerama/XRandR multiscreen setups | -- cgit v1.2.3 From 3671b53046afbeced26162fc413fcfb7971116b9 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Thu, 13 Sep 2018 15:29:57 +0200 Subject: Inotify: watch parent directory instead of just file --- src/thumbnail.c | 2 +- src/winwidget.c | 25 +++++++++++++------------ src/winwidget.h | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/thumbnail.c b/src/thumbnail.c index b7108c8..761162f 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -795,7 +795,7 @@ void feh_thumbnail_show_fullsize(feh_file *thumbfile) #endif feh_reload_image(thumbwin, 1, 1); #ifdef HAVE_INOTIFY - winwidget_inotify_add(thumbwin, thumbfile->filename); + winwidget_inotify_add(thumbwin, thumbfile); #endif } } diff --git a/src/winwidget.c b/src/winwidget.c index 9270d69..c012fc0 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -792,13 +792,13 @@ void winwidget_inotify_remove(winwidget winwid) #endif #ifdef HAVE_INOTIFY -void winwidget_inotify_add(winwidget winwid, char *filename) +void winwidget_inotify_add(winwidget winwid, feh_file * file) { if (opt.auto_reload) { - D(("Adding inotify watch for %s\n", filename)); - winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, - filename, - IN_CLOSE_WRITE); + D(("Adding inotify watch for %s\n", file->filename)); + char dir[PATH_MAX]; + feh_file_dirname(dir, file, PATH_MAX); + winwid->inotify_wd = inotify_add_watch(opt.inotify_fd, dir, IN_CLOSE_WRITE | IN_MOVED_TO); if (winwid->inotify_wd < 0) eprintf("inotify_add_watch failed"); } @@ -824,12 +824,13 @@ void feh_event_handle_inotify(void) for (int j = 0; j < window_num; j++) { if(windows[j]->inotify_wd == event->wd) { if (event->mask & IN_IGNORED) { - D(("Inotify watch was implicitely removed\n")); - feh_reload_image(windows[j], 0, 1); - winwidget_inotify_add(windows[j], FEH_FILE(windows[j]->file->data)->filename); - } else if (event->mask & IN_CLOSE_WRITE) { - D(("Inotify says file changed\n")); - feh_reload_image(windows[j], 0, 1); + D(("inotify watch was implicitely removed\n")); + windows[j]->inotify_wd = -1; + } else if (event->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) { + if (strcmp(event->name, FEH_FILE(windows[j]->file->data)->name) == 0) { + D(("inotify says file changed\n")); + feh_reload_image(windows[j], 0, 1); + } } break; } @@ -878,7 +879,7 @@ int winwidget_loadimage(winwidget winwid, feh_file * file) int res = feh_load_image(&(winwid->im), file); #ifdef HAVE_INOTIFY if (res) { - winwidget_inotify_add(winwid, file->filename); + winwidget_inotify_add(winwid, file); } #endif return(res); diff --git a/src/winwidget.h b/src/winwidget.h index d6b9546..b8d777e 100644 --- a/src/winwidget.h +++ b/src/winwidget.h @@ -124,7 +124,7 @@ struct __winwidget { #ifdef HAVE_INOTIFY void winwidget_inotify_remove(winwidget winwid); -void winwidget_inotify_add(winwidget winwid, char *filename); +void winwidget_inotify_add(winwidget winwid, feh_file * file); #endif int winwidget_loadimage(winwidget winwid, feh_file * filename); -- cgit v1.2.3 From 1d3d1259590c8a600c3d800942ab5566802d3499 Mon Sep 17 00:00:00 2001 From: Sven Willner Date: Thu, 13 Sep 2018 15:49:16 +0200 Subject: Add inotify option to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f59e68c..a12b97d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,4 @@ env: - stat64=1 - verscmp=0 - xinerama=0 + - inotify=1 -- cgit v1.2.3