Implement some obvious missing sort orders, from Dane Jensen in GitHub

issue 4813.
This commit is contained in:
nicm
2026-02-10 09:55:53 +00:00
parent 5a33616e65
commit 25f6d8b1e9
4 changed files with 40 additions and 14 deletions

40
sort.c
View File

@@ -197,23 +197,25 @@ sort_pane_cmp(const void *a0, const void *b0)
case SORT_CREATION: case SORT_CREATION:
result = a->id - b->id; result = a->id - b->id;
break; break;
case SORT_INDEX:
case SORT_NAME:
case SORT_ORDER:
case SORT_SIZE: case SORT_SIZE:
case SORT_END: result = a->sx * a->sy - b->sx * b->sy;
break; break;
} case SORT_INDEX:
if (result == 0) {
/*
* Panes don't have names, so use number order for any other
* sort field.
*/
window_pane_index(a, &ai); window_pane_index(a, &ai);
window_pane_index(b, &bi); window_pane_index(b, &bi);
result = ai - bi; result = ai - bi;
break;
case SORT_NAME:
result = strcmp(a->screen->title, b->screen->title);
break;
case SORT_ORDER:
case SORT_END:
break;
} }
if (result == 0)
result = strcmp(a->screen->title, b->screen->title);
if (sort_crit->reversed) if (sort_crit->reversed)
result = -result; result = -result;
return (result); return (result);
@@ -235,6 +237,16 @@ sort_winlink_cmp(const void *a0, const void *b0)
case SORT_INDEX: case SORT_INDEX:
result = wla->idx - wlb->idx; result = wla->idx - wlb->idx;
break; break;
case SORT_CREATION:
if (timercmp(&wa->creation_time, &wb->creation_time, >)) {
result = -1;
break;
}
if (timercmp(&wa->creation_time, &wb->creation_time, <)) {
result = 1;
break;
}
break;
case SORT_ACTIVITY: case SORT_ACTIVITY:
if (timercmp(&wa->activity_time, &wb->activity_time, >)) { if (timercmp(&wa->activity_time, &wb->activity_time, >)) {
result = -1; result = -1;
@@ -248,9 +260,10 @@ sort_winlink_cmp(const void *a0, const void *b0)
case SORT_NAME: case SORT_NAME:
result = strcmp(wa->name, wb->name); result = strcmp(wa->name, wb->name);
break; break;
case SORT_CREATION:
case SORT_ORDER:
case SORT_SIZE: case SORT_SIZE:
result = wa->sx * wa->sy - wb->sx * wb->sy;
break;
case SORT_ORDER:
case SORT_END: case SORT_END:
break; break;
} }
@@ -295,7 +308,8 @@ sort_order_from_string(const char* order)
return (SORT_CREATION); return (SORT_CREATION);
if (strcasecmp(order, "index") == 0) if (strcasecmp(order, "index") == 0)
return (SORT_INDEX); return (SORT_INDEX);
if (strcasecmp(order, "name") == 0) if (strcasecmp(order, "name") == 0 ||
strcasecmp(order, "title") == 0)
return (SORT_NAME); return (SORT_NAME);
if (strcasecmp(order, "order") == 0) if (strcasecmp(order, "order") == 0)
return (SORT_ORDER); return (SORT_ORDER);

10
tmux.1
View File

@@ -3090,7 +3090,11 @@ See the
section. section.
.Fl O .Fl O
specifies the sort order: one of specifies the sort order: one of
.Ql name , .Ql name
(title),
.Ql index ,
.Ql size
(area),
.Ql creation .Ql creation
(time), or (time), or
.Ql activity .Ql activity
@@ -3123,6 +3127,10 @@ section.
specifies the sort order: one of specifies the sort order: one of
.Ql index , .Ql index ,
.Ql name , .Ql name ,
.Ql size
(area),
.Ql creation
(time),
or or
.Ql activity .Ql activity
(time). (time).

1
tmux.h
View File

@@ -1254,6 +1254,7 @@ struct window {
struct event offset_timer; struct event offset_timer;
struct timeval activity_time; struct timeval activity_time;
struct timeval creation_time;
struct window_pane *active; struct window_pane *active;
struct window_panes last_panes; struct window_panes last_panes;

View File

@@ -330,6 +330,9 @@ window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel)
RB_INSERT(windows, &windows, w); RB_INSERT(windows, &windows, w);
window_set_fill_character(w); window_set_fill_character(w);
if (gettimeofday(&w->creation_time, NULL) != 0)
fatal("gettimeofday failed");
window_update_activity(w); window_update_activity(w);
log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy, log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy,