diff options
author | real <real@jane.(none)> | 2012-12-25 09:34:21 +0100 |
---|---|---|
committer | real <real@jane.(none)> | 2012-12-25 09:34:21 +0100 |
commit | f14abbf23f66b835ef353b3f7616ea83cf501b9b (patch) | |
tree | 2a9015155e3da570f872e4ae433ede49740e8a04 /src/thumbnail.c | |
parent | 9fc4db4c054d7a4d69a77df1cc0be4c827f93391 (diff) | |
parent | 2acfecee31b8b4102210b79796604dc33bee864a (diff) |
Merge branch 'master' of git://github.com/derf/feh
Diffstat (limited to 'src/thumbnail.c')
-rw-r--r-- | src/thumbnail.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/thumbnail.c b/src/thumbnail.c index da14760..a77152a 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -786,36 +786,47 @@ void feh_thumbnail_select(winwidget winwid, feh_thumbnail *thumbnail) void feh_thumbnail_select_next(winwidget winwid, int jump) { - gib_list *l, *tmp; - int i; + gib_list *l; + feh_thumbnail *thumb; + int len = 0, cur = 0, target = 0; - for (l = thumbnails; l && l->next; l = l->next) { - tmp = l; - for (i = jump; (i > 0) && tmp->next; i--) - tmp = tmp->next; - if (tmp->data == td.selected) - break; + for (l = thumbnails; l; l = l->next) { + thumb = FEH_THUMB(l->data); + if (thumb == td.selected) + cur = len; + len++; } - feh_thumbnail_select(winwid, FEH_THUMB(l->data)); + target = (cur + len - jump) % len; + + for (l = thumbnails; l; l = l->next) { + if (target-- == 0) { + feh_thumbnail_select(winwid, FEH_THUMB(l->data)); + } + } } void feh_thumbnail_select_prev(winwidget winwid, int jump) { gib_list *l; feh_thumbnail *thumb; - int i; + int len = 0, cur = 0, target = 0; for (l = thumbnails; l; l = l->next) { thumb = FEH_THUMB(l->data); - if ((thumb == td.selected) && l->next) { - for (i = jump; (i > 0) && l->next; i--) - l = l->next; + if (thumb == td.selected) + cur = len; + len++; + } + + target = (cur + jump) % len; + + for (l = thumbnails; l; l = l->next) { + if (target-- == 0) { feh_thumbnail_select(winwid, FEH_THUMB(l->data)); - return; + break; } } - feh_thumbnail_select(winwid, FEH_THUMB(thumbnails->data)); } inline void feh_thumbnail_show_selected() |