From f3ea5c887e034f08d2735c7a32876f94ee9ef60a Mon Sep 17 00:00:00 2001
From: ulteq <ulteq@web.de>
Date: Mon, 1 Jan 2018 15:37:32 +0100
Subject: Add --no-cycle option

Closes: #124
---
 src/help.raw    | 1 +
 src/options.c   | 4 ++++
 src/options.h   | 1 +
 src/slideshow.c | 7 +++++++
 4 files changed, 13 insertions(+)

(limited to 'src')

diff --git a/src/help.raw b/src/help.raw
index 86bb617..52d06bf 100644
--- a/src/help.raw
+++ b/src/help.raw
@@ -38,6 +38,7 @@ OPTIONS
      --auto-rotate         Rotate images according to Exif info (if compiled with exif=1)
  -^, --title TITLE         Set window title (see FORMAT SPECIFIERS)
  -D, --slideshow-delay NUM Set delay between automatically changing slides
+     --no-cycle            Stop at both ends of the filelist 
      --cycle-once          Exit after one loop through the slideshow
  -R, --reload NUM          Reload images after NUM seconds
  -k, --keep-http           Keep local copies when viewing HTTP/FTP files
diff --git a/src/options.c b/src/options.c
index af0f07d..1a47a39 100644
--- a/src/options.c
+++ b/src/options.c
@@ -415,6 +415,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
 		{"insecure"      , 0, 0, 240},
 		{"no-recursive"  , 0, 0, 241},
 		{"cache-size"    , 1, 0, 243},
+		{"no-cycle"      , 0, 0, 244},
 		{"conversion-timeout" , 1, 0, 245},
 		{"version-sort"  , 0, 0, 246},
 		{"offset"        , 1, 0, 247},
@@ -785,6 +786,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
 			if (opt.cache_size > 2048)
 				opt.cache_size = 2048;
 			break;
+		case 244:
+			opt.no_cycle = 1;
+			break;
 		case 245:
 			opt.conversion_timeout = atoi(optarg);
 			break;
diff --git a/src/options.h b/src/options.h
index 936b4bd..122d39e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -69,6 +69,7 @@ struct __fehoptions {
 	unsigned char draw_info;
 	unsigned char cache_thumbnails;
 	unsigned char cycle_once;
+	unsigned char no_cycle;
 	unsigned char hold_actions[10];
 	unsigned char text_bg;
 	unsigned char no_fehbg;
diff --git a/src/slideshow.c b/src/slideshow.c
index b27a7e8..77f5a82 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -215,6 +215,7 @@ void feh_reload_image(winwidget w, int resize, int force_new)
 void slideshow_change_image(winwidget winwid, int change, int render)
 {
 	gib_list *last = NULL;
+	gib_list *previous_file = current_file;
 	int i = 0;
 	int jmp = 1;
 	/* We can't use filelist_len in the for loop, since that changes when we
@@ -332,6 +333,12 @@ void slideshow_change_image(winwidget winwid, int change, int render)
 			last = NULL;
 		}
 
+		if (opt.no_cycle &&
+			((current_file == filelist && change == SLIDE_NEXT) ||
+			(previous_file == filelist && change == SLIDE_PREV))) {
+				current_file = previous_file;
+		}
+
 		if (winwidget_loadimage(winwid, FEH_FILE(current_file->data))) {
 			int w = gib_imlib_image_get_width(winwid->im);
 			int h = gib_imlib_image_get_height(winwid->im);
-- 
cgit v1.2.3


From dbc8dc8ceabdab55c5c8c74708af7788ade1c151 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Sat, 18 Aug 2018 19:43:32 +0200
Subject: combine --no-cycle and --cycle-once into --on-last-slide={quit,hold}

---
 src/help.raw    |  4 ++--
 src/options.c   | 16 +++++++++++++---
 src/options.h   |  9 +++++++--
 src/slideshow.c | 10 +++++-----
 4 files changed, 27 insertions(+), 12 deletions(-)

(limited to 'src')

diff --git a/src/help.raw b/src/help.raw
index 52d06bf..ebffae3 100644
--- a/src/help.raw
+++ b/src/help.raw
@@ -38,8 +38,8 @@ OPTIONS
      --auto-rotate         Rotate images according to Exif info (if compiled with exif=1)
  -^, --title TITLE         Set window title (see FORMAT SPECIFIERS)
  -D, --slideshow-delay NUM Set delay between automatically changing slides
-     --no-cycle            Stop at both ends of the filelist 
-     --cycle-once          Exit after one loop through the slideshow
+     --on-last-slide quit  Exit after one loop through the slide show
+     --on-last-slide hold  Stop at both ends of the filelist
  -R, --reload NUM          Reload images after NUM seconds
  -k, --keep-http           Keep local copies when viewing HTTP/FTP files
      --insecure            Disable peer/host verification when using HTTPS.
diff --git a/src/options.c b/src/options.c
index 1a47a39..38d2568 100644
--- a/src/options.c
+++ b/src/options.c
@@ -415,7 +415,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
 		{"insecure"      , 0, 0, 240},
 		{"no-recursive"  , 0, 0, 241},
 		{"cache-size"    , 1, 0, 243},
-		{"no-cycle"      , 0, 0, 244},
+		{"on-last-slide" , 1, 0, 244},
 		{"conversion-timeout" , 1, 0, 245},
 		{"version-sort"  , 0, 0, 246},
 		{"offset"        , 1, 0, 247},
@@ -743,7 +743,8 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
 			break;
 #endif
 		case 224:
-			opt.cycle_once = 1;
+			weprintf("--cycle-once is deprecated, please use --on-last-slide=quit instead");
+			opt.on_last_slide = ON_LAST_SLIDE_QUIT;
 			break;
 		case 225:
 			opt.xinerama = 0;
@@ -787,7 +788,16 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
 				opt.cache_size = 2048;
 			break;
 		case 244:
-			opt.no_cycle = 1;
+			if (!strcmp(optarg, "quit")) {
+				opt.on_last_slide = ON_LAST_SLIDE_QUIT;
+			} else if (!strcmp(optarg, "hold")) {
+				opt.on_last_slide = ON_LAST_SLIDE_HOLD;
+			} else if (!strcmp(optarg, "resume")) {
+				opt.on_last_slide = ON_LAST_SLIDE_RESUME;
+			} else {
+				weprintf("Unrecognized on-last-slide action \"%s\"."
+						"Supported actions: hold, resume, quit\n", optarg);
+			}
 			break;
 		case 245:
 			opt.conversion_timeout = atoi(optarg);
diff --git a/src/options.h b/src/options.h
index 122d39e..606b8e6 100644
--- a/src/options.h
+++ b/src/options.h
@@ -27,6 +27,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef OPTIONS_H
 #define OPTIONS_H
 
+enum on_last_slide_action {
+	ON_LAST_SLIDE_RESUME = 0,
+	ON_LAST_SLIDE_QUIT,
+	ON_LAST_SLIDE_HOLD
+};
+
 struct __fehoptions {
 	unsigned char multiwindow;
 	unsigned char montage;
@@ -68,8 +74,7 @@ struct __fehoptions {
 	unsigned char draw_actions;
 	unsigned char draw_info;
 	unsigned char cache_thumbnails;
-	unsigned char cycle_once;
-	unsigned char no_cycle;
+	unsigned char on_last_slide;
 	unsigned char hold_actions[10];
 	unsigned char text_bg;
 	unsigned char no_fehbg;
diff --git a/src/slideshow.c b/src/slideshow.c
index 77f5a82..6f622b4 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -225,7 +225,7 @@ void slideshow_change_image(winwidget winwid, int change, int render)
 
 	/* Without this, clicking a one-image slideshow reloads it. Not very *
 	   intelligent behaviour :-) */
-	if (filelist_len < 2 && opt.cycle_once == 0)
+	if (filelist_len < 2 && opt.on_last_slide != ON_LAST_SLIDE_QUIT)
 		return;
 
 	/* Ok. I do this in such an odd way to ensure that if the last or first *
@@ -333,7 +333,7 @@ void slideshow_change_image(winwidget winwid, int change, int render)
 			last = NULL;
 		}
 
-		if (opt.no_cycle &&
+		if (opt.on_last_slide == ON_LAST_SLIDE_HOLD &&
 			((current_file == filelist && change == SLIDE_NEXT) ||
 			(previous_file == filelist && change == SLIDE_PREV))) {
 				current_file = previous_file;
@@ -574,10 +574,10 @@ void feh_filelist_image_remove(winwidget winwid, char do_delete)
 
 		doomed = current_file;
 		/*
-		 * work around feh_list_jump exiting if cycle_once is enabled
+		 * work around feh_list_jump exiting if ON_LAST_SLIDE_QUIT is set
 		 * and no further files are left (we need to delete first)
 		 */
-		if (opt.cycle_once && ! doomed->next && do_delete) {
+		if (opt.on_last_slide == ON_LAST_SLIDE_QUIT && ! doomed->next && do_delete) {
 			feh_file_rm_and_free(filelist, doomed);
 			exit(0);
 		}
@@ -653,7 +653,7 @@ gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num)
 			if (ret->next) {
 				ret = ret->next;
 			} else {
-				if (opt.cycle_once) {
+				if (opt.on_last_slide == ON_LAST_SLIDE_QUIT) {
 					exit(0);
 				}
 				if (opt.randomize) {
-- 
cgit v1.2.3