This is responsible for reassigning new index numbers to the winlinks in a given session. --- trunk/tmux.h | 2 ++ trunk/window.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
diff --git a/trunk/tmux.h b/trunk/tmux.h index 23352d6..7f21754 100644 --- a/trunk/tmux.h +++ b/trunk/tmux.h @@ -1995,6 +1995,8 @@ int window_pane_visible(struct window_pane *); char *window_pane_search( struct window_pane *, const char *, u_int *); char *window_printable_flags(struct session *, struct winlink *); +int window_renumber_windows(struct session *); + struct window_pane *window_pane_find_up(struct window_pane *); struct window_pane *window_pane_find_down(struct window_pane *); struct window_pane *window_pane_find_left(struct window_pane *); diff --git a/trunk/window.c b/trunk/window.c index fac56dc..445a02f 100644 --- a/trunk/window.c +++ b/trunk/window.c @@ -1173,3 +1173,48 @@ window_pane_find_right(struct window_pane *wp) } return (NULL); } + +/* Renumber the windows across winlinks attached to a specific session. */ +int +window_renumber_windows(struct session *s) +{ + struct winlink *wl, *wl_new; + struct winlinks old_wins; + struct winlink_stack old_lastw; + int new_idx = 0, new_curw_idx = 0; + + if (s == NULL) + return (-1); + + memcpy(&old_wins, &s->windows, sizeof old_wins); + RB_INIT(&s->windows); + + /* Start renumbering from the base-index if it's set. */ + new_idx = options_get_number(&s->options, "base-index"); + + /* Go through the winlinks and assign new indexes. */ + RB_FOREACH(wl, winlinks, &old_wins) { + wl_new = winlink_add(&s->windows, new_idx); + winlink_set_window(wl_new, wl->window); + wl_new->flags |= wl->flags & WINLINK_ALERTFLAGS; + + if (wl == s->curw) + new_curw_idx = wl_new->idx; + + new_idx++; + } + + /* Fix the stack of last windows now that the IDs have changed. */ + memcpy(&old_lastw, &s->lastw, sizeof old_lastw); + TAILQ_INIT(&s->lastw); + TAILQ_FOREACH(wl, &old_lastw, sentry) { + wl_new = winlink_find_by_index(&s->windows, wl->idx); + if (wl_new != NULL) + TAILQ_INSERT_TAIL(&s->lastw, wl_new, sentry); + } + + /* Set the current window per the new id. */ + s->curw = winlink_find_by_index(&s->windows, new_curw_idx); + + return (0); +} -- 1.7.10 ------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2 _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users