diff options
Diffstat (limited to 'usr.bin/tmux/session.c')
-rw-r--r-- | usr.bin/tmux/session.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 2476a9ae249..e4882e35dcf 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.33 2012/03/17 22:35:09 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.34 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -591,3 +591,49 @@ session_group_synchronize1(struct session *target, struct session *s) winlink_remove(&old_windows, wl); } } + +/* Renumber the windows across winlinks attached to a specific session. */ +void +session_renumber_windows(struct session *s) +{ + struct winlink *wl, *wl1, *wl_new; + struct winlinks old_wins; + struct winlink_stack old_lastw; + int new_idx, new_curw_idx; + + /* Save and replace old window list. */ + 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"); + new_curw_idx = 0; + + /* 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. */ + 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. */ + s->curw = winlink_find_by_index(&s->windows, new_curw_idx); + + /* Free the old winlinks (reducing window references too). */ + RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1) + winlink_remove(&old_wins, wl); +} |