summaryrefslogtreecommitdiff
path: root/src/slideshow.c
diff options
context:
space:
mode:
authorguns <self@sungpae.com>2016-05-28 00:45:33 -0500
committerguns <self@sungpae.com>2016-05-28 00:45:33 -0500
commit36b09fa038a8b7996a12e45419c28821c5596308 (patch)
tree36e759b0bd5d94fa4ef8817a746f43b6e6e9d5c4 /src/slideshow.c
parent7db8895f8cfb3d58b8e9b4c7a5a64a4df9bb1af0 (diff)
Add prev_dir and next_dir navigation actions
Many image collections are organized by directory, so it is nice to have jump-to-adjacent-directory navigation. e.g. Given the following file hierarchy: . ├── A │   ├── 1.jpg │   ├── 2.jpg │   └── C │   ├── 1.jpg │   ├── 2.jpg │   └── 3.jpg └── B ├── 1.jpg ├── 2.jpg └── 3.jpg `feh --recursive` creates the following filelist: A/1.jpg <---- current_file A/2.jpg A/C/1.jpg A/C/2.jpg A/C/3.jpg B/1.jpg B/2.jpg B/3.jpg If we press [next_dir], we move the current_file pointer to: A/1.jpg A/2.jpg A/C/1.jpg <-- current_file A/C/2.jpg A/C/3.jpg B/1.jpg B/2.jpg B/3.jpg Pressing [next_dir] again moves the pointer to: A/1.jpg A/2.jpg A/C/1.jpg A/C/2.jpg A/C/3.jpg B/1.jpg <---- current_file B/2.jpg B/3.jpg [next_dir] now moves the pointer back to the top of the list: A/1.jpg <---- current_file A/2.jpg A/C/1.jpg A/C/2.jpg A/C/3.jpg B/1.jpg B/2.jpg B/3.jpg Pressing [prev_dir] from here moves backwards to the first image of the previous directory: A/1.jpg A/2.jpg A/C/1.jpg A/C/2.jpg A/C/3.jpg B/1.jpg <---- current_file B/2.jpg B/3.jpg When starting from an position that is not the first image of a directory, [prev_dir] moves the pointer to the first image of the current directory. These actions combine well with `--sort dirname` since all regular files in a directory will be sorted before any subdirectories, avoiding a filelist like the following: A/1.jpg A/SUBDIR/2.jpg A/SUBDIR/3.jpg A/4.jpg With `--sort dirname` that filelist becomes: A/1.jpg A/4.jpg A/SUBDIR/2.jpg A/SUBDIR/3.jpg
Diffstat (limited to 'src/slideshow.c')
-rw-r--r--src/slideshow.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/slideshow.c b/src/slideshow.c
index 7636d31..2af78c9 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -322,6 +322,44 @@ void slideshow_change_image(winwidget winwid, int change, int render)
try the previous file, not another jmp */
change = SLIDE_NEXT;
break;
+ case SLIDE_JUMP_NEXT_DIR:
+ {
+ char old_dir[FEH_MAX_DIRNAME_LEN], new_dir[FEH_MAX_DIRNAME_LEN];
+ int j;
+
+ feh_file_dirname(old_dir, FEH_FILE(current_file->data), FEH_MAX_DIRNAME_LEN);
+
+ for (j = 0; j < our_filelist_len; j++) {
+ current_file = feh_list_jump(filelist, current_file, FORWARD, 1);
+ feh_file_dirname(new_dir, FEH_FILE(current_file->data), FEH_MAX_DIRNAME_LEN);
+ if (strcmp(old_dir, new_dir) != 0)
+ break;
+ }
+ }
+ change = SLIDE_NEXT;
+ break;
+ case SLIDE_JUMP_PREV_DIR:
+ {
+ char old_dir[FEH_MAX_DIRNAME_LEN], new_dir[FEH_MAX_DIRNAME_LEN];
+ int j;
+
+ /* Start the search from the previous file in case we are on
+ the first file of a directory */
+ current_file = feh_list_jump(filelist, current_file, BACK, 1);
+ feh_file_dirname(old_dir, FEH_FILE(current_file->data), FEH_MAX_DIRNAME_LEN);
+
+ for (j = 0; j < our_filelist_len; j++) {
+ current_file = feh_list_jump(filelist, current_file, BACK, 1);
+ feh_file_dirname(new_dir, FEH_FILE(current_file->data), FEH_MAX_DIRNAME_LEN);
+ if (strcmp(old_dir, new_dir) != 0)
+ break;
+ }
+
+ /* Next file is the first entry of prev_dir */
+ current_file = feh_list_jump(filelist, current_file, FORWARD, 1);
+ }
+ change = SLIDE_NEXT;
+ break;
default:
eprintf("BUG!\n");
break;