Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/filelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/filelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -104,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);
Expand Down
8 changes: 8 additions & 0 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down