diff --git a/sort.c b/sort.c index a1d85891..fb3f89ee 100644 --- a/sort.c +++ b/sort.c @@ -197,23 +197,25 @@ sort_pane_cmp(const void *a0, const void *b0) case SORT_CREATION: result = a->id - b->id; break; - case SORT_INDEX: - case SORT_NAME: - case SORT_ORDER: case SORT_SIZE: - case SORT_END: + result = a->sx * a->sy - b->sx * b->sy; break; - } - if (result == 0) { - /* - * Panes don't have names, so use number order for any other - * sort field. - */ + case SORT_INDEX: window_pane_index(a, &ai); window_pane_index(b, &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) result = -result; return (result); @@ -235,6 +237,16 @@ sort_winlink_cmp(const void *a0, const void *b0) case SORT_INDEX: result = wla->idx - wlb->idx; 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: if (timercmp(&wa->activity_time, &wb->activity_time, >)) { result = -1; @@ -248,9 +260,10 @@ sort_winlink_cmp(const void *a0, const void *b0) case SORT_NAME: result = strcmp(wa->name, wb->name); break; - case SORT_CREATION: - case SORT_ORDER: case SORT_SIZE: + result = wa->sx * wa->sy - wb->sx * wb->sy; + break; + case SORT_ORDER: case SORT_END: break; } @@ -295,7 +308,8 @@ sort_order_from_string(const char* order) return (SORT_CREATION); if (strcasecmp(order, "index") == 0) return (SORT_INDEX); - if (strcasecmp(order, "name") == 0) + if (strcasecmp(order, "name") == 0 || + strcasecmp(order, "title") == 0) return (SORT_NAME); if (strcasecmp(order, "order") == 0) return (SORT_ORDER); diff --git a/tmux.1 b/tmux.1 index 48751888..2229fc95 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3090,7 +3090,11 @@ See the section. .Fl O specifies the sort order: one of -.Ql name , +.Ql name +(title), +.Ql index , +.Ql size +(area), .Ql creation (time), or .Ql activity @@ -3123,6 +3127,10 @@ section. specifies the sort order: one of .Ql index , .Ql name , +.Ql size +(area), +.Ql creation +(time), or .Ql activity (time). diff --git a/tmux.h b/tmux.h index 0f84398b..fdbf55c1 100644 --- a/tmux.h +++ b/tmux.h @@ -1254,6 +1254,7 @@ struct window { struct event offset_timer; struct timeval activity_time; + struct timeval creation_time; struct window_pane *active; struct window_panes last_panes; diff --git a/window.c b/window.c index 31a8a8ee..60f2204a 100644 --- a/window.c +++ b/window.c @@ -330,6 +330,9 @@ window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel) RB_INSERT(windows, &windows, w); window_set_fill_character(w); + + if (gettimeofday(&w->creation_time, NULL) != 0) + fatal("gettimeofday failed"); window_update_activity(w); log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy,