From edb117e3bdb4d6bef4a4749d94144df8472c0a4d Mon Sep 17 00:00:00 2001 From: Max Voit Date: Thu, 26 Jan 2017 22:18:32 +0100 Subject: Add autoreload support by inotify (and dummy backend nop) --- autoreload.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 autoreload.h (limited to 'autoreload.h') diff --git a/autoreload.h b/autoreload.h new file mode 100644 index 0000000..439b695 --- /dev/null +++ b/autoreload.h @@ -0,0 +1,43 @@ +/* Copyright 2017 Max Voit + * + * This file is part of sxiv. + * + * sxiv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * sxiv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with sxiv. If not, see . + */ + +#ifndef AUTORELOAD_H +#define AUTORELOAD_H + +#include "types.h" + +void arl_cleanup(void); +void arl_handle(void); +void arl_init(void); +void arl_setup(void); +void arl_setup_dir(void); + +typedef struct { + int fd; + int wd; + bool watching_dir; +} autoreload_t; + +extern autoreload_t autoreload; +extern int fileidx; +extern fileinfo_t *files; + +void load_image(int); +void redraw(void); + +#endif /* AUTORELOAD_H */ -- cgit v1.2.3 From 3724d3fc17dc6135a05608cab5bdf00c6978282d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 17 May 2017 20:07:32 +0200 Subject: Revised autoreload interface Make the header only contain the public interface and nothing from the implementation. All functions get a handle to their self object, like the img_ and tns_ and win_ functions. All necessary data (file path) is also passed as an argument, so that no extern redeclarations are needed. Make arl_setup_dir() private, it's not called outside the module. Make arl_handle() return true if the file has changed, so that the reloading of the file can be done by the caller. --- autoreload.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'autoreload.h') diff --git a/autoreload.h b/autoreload.h index 439b695..6a3053c 100644 --- a/autoreload.h +++ b/autoreload.h @@ -21,23 +21,15 @@ #include "types.h" -void arl_cleanup(void); -void arl_handle(void); -void arl_init(void); -void arl_setup(void); -void arl_setup_dir(void); - typedef struct { int fd; int wd; bool watching_dir; -} autoreload_t; - -extern autoreload_t autoreload; -extern int fileidx; -extern fileinfo_t *files; +} arl_t; -void load_image(int); -void redraw(void); +void arl_cleanup(arl_t*); +bool arl_handle(arl_t*, const char*); +void arl_init(arl_t*); +void arl_setup(arl_t*, const char*); #endif /* AUTORELOAD_H */ -- cgit v1.2.3 From a20173a42df64515c0a5d1c5fba0c056a633a441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 17 May 2017 20:16:16 +0200 Subject: Detect all file overwrites in autoreload_inotify mv(1) inside the same filesystem was not detected. Supporting this case made it necessary to always watch the directory. Turns out the logic and state keeping between arl_setup() and arl_handle() is easier, when using different watch descriptors for the file and the directory and not using a oneshot descriptor for the file. Requiring an absolute canonical path for arl_setup() simplifies dir and base name splitting. No need for dirname(3) and basename(3) anymore. --- autoreload.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'autoreload.h') diff --git a/autoreload.h b/autoreload.h index 6a3053c..bb30eb6 100644 --- a/autoreload.h +++ b/autoreload.h @@ -23,13 +23,14 @@ typedef struct { int fd; - int wd; - bool watching_dir; + int wd_dir; + int wd_file; + char *filename; } arl_t; -void arl_cleanup(arl_t*); -bool arl_handle(arl_t*, const char*); void arl_init(arl_t*); -void arl_setup(arl_t*, const char*); +void arl_cleanup(arl_t*); +void arl_setup(arl_t*, const char* /* result of realpath(3) */); +bool arl_handle(arl_t*); #endif /* AUTORELOAD_H */ -- cgit v1.2.3