From fa3cf20e068ba3db172898d22f70c97c0fdc4c44 Mon Sep 17 00:00:00 2001 From: TheBlueCrystal Date: Tue, 15 Oct 2024 17:36:41 +0200 Subject: [PATCH 1/2] Implement ctime sorting --- src/filelist.c | 11 +++++++++++ src/filelist.h | 2 ++ src/options.c | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/filelist.c b/src/filelist.c index a5ad8901..8720efa9 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -367,6 +367,7 @@ int feh_file_stat(feh_file * file) } file->mtime = st.st_mtime; + file->ctime = st.st_ctime; file->size = st.st_size; @@ -457,6 +458,13 @@ int feh_cmp_mtime(void *file1, void *file2) return(FEH_FILE(file1)->mtime >= FEH_FILE(file2)->mtime ? -1 : 1); } +/* Return -1 if file1 is _newer_ than file2 */ +int feh_cmp_ctime(void *file1, void *file2) +{ + /* gib_list_sort is not stable, so explicitly return 0 as -1 */ + return(FEH_FILE(file1)->ctime >= FEH_FILE(file2)->ctime ? -1 : 1); +} + int feh_cmp_width(void *file1, void *file2) { return((FEH_FILE(file1)->info->width - FEH_FILE(file2)->info->width)); @@ -527,6 +535,9 @@ void feh_prepare_filelist(void) case SORT_DIRNAME: filelist = gib_list_sort(filelist, feh_cmp_dirname); break; + case SORT_CTIME: + filelist = gib_list_sort(filelist, feh_cmp_ctime); + break; case SORT_MTIME: filelist = gib_list_sort(filelist, feh_cmp_mtime); break; diff --git a/src/filelist.h b/src/filelist.h index e6482625..ece8d132 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -37,6 +37,7 @@ struct __feh_file { /* info stuff */ time_t mtime; + time_t ctime; int size; feh_file_info *info; /* only set when needed */ #ifdef HAVE_LIBEXIF @@ -73,6 +74,7 @@ enum sort_type { SORT_FILENAME, SORT_DIRNAME, SORT_SIZE, // everything after SORT_SIZE requires stat(2) information on the filelist + SORT_CTIME, SORT_MTIME, SORT_WIDTH, // everything after SORT_WIDTH requires preloading the images in the filelist SORT_HEIGHT, diff --git a/src/options.c b/src/options.c index 3f405faa..96f47219 100644 --- a/src/options.c +++ b/src/options.c @@ -544,6 +544,8 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) opt.sort = SORT_FILENAME; else if (!strcasecmp(optarg, "dirname")) opt.sort = SORT_DIRNAME; + else if (!strcasecmp(optarg, "ctime")) + opt.sort = SORT_CTIME; else if (!strcasecmp(optarg, "mtime")) opt.sort = SORT_MTIME; else if (!strcasecmp(optarg, "width")) From 8d1e644911a9e940d6516d659fbb3e0ecd739313 Mon Sep 17 00:00:00 2001 From: TheBlueCrystal Date: Tue, 15 Oct 2024 21:48:58 +0200 Subject: [PATCH 2/2] Make ctime sorting also available in menu --- src/filelist.h | 1 + src/menu.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/filelist.h b/src/filelist.h index ece8d132..e5455a83 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -106,6 +106,7 @@ char *feh_http_unescape(char * url); int feh_cmp_name(void *file1, void *file2); int feh_cmp_dirname(void *file1, void *file2); int feh_cmp_filename(void *file1, void *file2); +int feh_cmp_ctime(void *file1, void *file2); int feh_cmp_mtime(void *file1, void *file2); int feh_cmp_width(void *file1, void *file2); int feh_cmp_height(void *file1, void *file2); diff --git a/src/menu.c b/src/menu.c index 9c206928..6b7142a0 100644 --- a/src/menu.c +++ b/src/menu.c @@ -68,6 +68,7 @@ enum { CB_SORT_FILENAME, CB_SORT_IMAGENAME, CB_SORT_DIRNAME, + CB_SORT_CTIME, CB_SORT_MTIME, CB_SORT_FILESIZE, CB_SORT_RANDOMIZE, @@ -952,6 +953,7 @@ void feh_menu_init_common(void) feh_menu_add_entry(m, "By File Name", NULL, CB_SORT_FILENAME, 0, NULL); feh_menu_add_entry(m, "By Image Name", NULL, CB_SORT_IMAGENAME, 0, NULL); feh_menu_add_entry(m, "By Directory Name", NULL, CB_SORT_DIRNAME, 0, NULL); + feh_menu_add_entry(m, "By File Status Change Date", NULL, CB_SORT_CTIME, 0, NULL); feh_menu_add_entry(m, "By Modification Date", NULL, CB_SORT_MTIME, 0, NULL); if (opt.preload || (opt.sort > SORT_MTIME)) feh_menu_add_entry(m, "By File Size", NULL, CB_SORT_FILESIZE, 0, NULL); @@ -1290,6 +1292,12 @@ void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, unsigned short dat slideshow_change_image(m->fehwin, SLIDE_FIRST, 1); } break; + case CB_SORT_CTIME: + filelist = gib_list_sort(filelist, feh_cmp_ctime); + if (opt.jump_on_resort) { + slideshow_change_image(m->fehwin, SLIDE_FIRST, 1); + } + break; case CB_SORT_MTIME: filelist = gib_list_sort(filelist, feh_cmp_mtime); if (opt.jump_on_resort) {