summaryrefslogtreecommitdiffstats
path: root/session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-04-29 17:20:01 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-04-29 17:20:01 +0000
commita6c22d650b2d9fba8eb069b488555ab71e5096d6 (patch)
treeaf123a415df233978b44eda9bbb7dbad6290bd44 /session.c
parente60f48ab09f75c622f45718797f83964a28769c0 (diff)
Add a flag to move-window to renumber the windows in a session (closing
any gaps) and add an option to do this automatically each time a window is killed. From Thomas Adam.
Diffstat (limited to 'session.c')
-rw-r--r--session.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/session.c b/session.c
index 0109fd5d..b3f03541 100644
--- a/session.c
+++ b/session.c
@@ -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);
+}