From 185e861b4975bf2e5505ac7237f6946ee4def608 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Fri, 11 May 2018 17:03:34 +0200
Subject: [PATCH] Show correct filelist position in windows opened from
 thumbnail mode

Addresses part of issue #75
---
 src/thumbnail.c | 15 ++++++++++++---
 src/winwidget.c |  2 --
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/thumbnail.c b/src/thumbnail.c
index 003c7b4..3e99bfb 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -766,17 +766,26 @@ int feh_thumbnail_get_generated(Imlib_Image * image, feh_file * file,
 void feh_thumbnail_show_fullsize(feh_file *thumbfile)
 {
 	winwidget thumbwin = NULL;
+	gib_list *l;
+
+	for (l = filelist; l; l = l->next) {
+		if (FEH_FILE(l->data) == thumbfile) {
+			break;
+		}
+	}
+	if (!l) {
+		eprintf("Cannot find %s in filelist, wtf", thumbfile->filename);
+	}
 
 	thumbwin = winwidget_get_first_window_of_type(WIN_TYPE_THUMBNAIL_VIEWER);
 	if (!thumbwin) {
 		thumbwin = winwidget_create_from_file(
-				gib_list_add_front(NULL, thumbfile),
+				l,
 				WIN_TYPE_THUMBNAIL_VIEWER);
 		if (thumbwin)
 			winwidget_show(thumbwin);
 	} else if (FEH_FILE(thumbwin->file->data) != thumbfile) {
-		free(thumbwin->file);
-		thumbwin->file = gib_list_add_front(NULL, thumbfile);
+		thumbwin->file = l;
 		feh_reload_image(thumbwin, 1, 1);
 	}
 }
diff --git a/src/winwidget.c b/src/winwidget.c
index beae9fa..7aae191 100644
--- a/src/winwidget.c
+++ b/src/winwidget.c
@@ -773,8 +773,6 @@ void winwidget_destroy(winwidget winwid)
 		free(winwid->name);
 	if (winwid->gc)
 		XFreeGC(disp, winwid->gc);
-	if ((winwid->type == WIN_TYPE_THUMBNAIL_VIEWER) && (winwid->file != NULL))
-		gib_list_free(winwid->file);
 	if (winwid->im)
 		gib_imlib_free_image_and_decache(winwid->im);
 	free(winwid);
-- 
GitLab