From 553d6f9060d867cf05bd21d8669751b31bbe11dd Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Fri, 8 Feb 2019 17:58:21 +0100
Subject: Fix ~/.fehbg creation when using --randomize or directory arguments

Closes #456

Note that --randomize and directory names are not saved in fehbg. It only
contains the command line needed to recreate the wallpaper setup which
resulted from its invocation, i.e., after randomization etc. have been
applied. This is intentional.
---
 src/wallpaper.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/wallpaper.c b/src/wallpaper.c
index ef7ecca..f0bf891 100644
--- a/src/wallpaper.c
+++ b/src/wallpaper.c
@@ -502,15 +502,16 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled,
 					}
 					fputc(' ', fp);
 					if (use_filelist) {
-						for (int i = 0; i < cmdargc; i++) {
-							if (filelist_pos && !strcmp(FEH_FILE(filelist_pos->data)->filename, cmdargv[i])) {
-								/* argument is a file */
-								absolute_path = feh_absolute_path(cmdargv[i]);
-								fputs(shell_escape(absolute_path), fp);
-								filelist_pos = filelist_pos->next;
-								free(absolute_path);
-								fputc(' ', fp);
-							}
+#ifdef HAVE_LIBXINERAMA
+						for (int i = 0; (i < num_xinerama_screens) && filelist_pos; i++) {
+#else
+						for (int i = 0; (i < 1                   ) && filelist_pos; i++) {
+#endif
+							absolute_path = feh_absolute_path(FEH_FILE(filelist_pos->data)->filename);
+							fputs(shell_escape(absolute_path), fp);
+							filelist_pos = filelist_pos->next;
+							free(absolute_path);
+							fputc(' ', fp);
 						}
 					} else if (fil) {
 						absolute_path = feh_absolute_path(fil);
-- 
cgit v1.2.3