summaryrefslogtreecommitdiffstats
path: root/cmd-choose-session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2010-12-21 22:37:59 +0000
committerNicholas Marriott <nicm@openbsd.org>2010-12-21 22:37:59 +0000
commitacf13ce9784111ca1e42ffc8206e752668476859 (patch)
tree49ccd47b2e589a27dab8657d516133205f07f393 /cmd-choose-session.c
parent1b8488ee75458c4561089bf056c0e911de958428 (diff)
Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists (list-sessions/choose-sessions). Keep a session index which is used in a couple of places internally but make it an ever-increasing number rather than filling in gaps with new sessions.
Diffstat (limited to 'cmd-choose-session.c')
-rw-r--r--cmd-choose-session.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index 7cd56f5d..cf36fe98 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -55,7 +55,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct winlink *wl;
struct session *s;
struct session_group *sg;
- u_int i, idx, sgidx, cur;
+ u_int idx, sgidx, cur;
char tmp[64];
if (ctx->curclient == NULL) {
@@ -70,10 +70,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
cur = idx = 0;
- for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
- s = ARRAY_ITEM(&sessions, i);
- if (s == NULL)
- continue;
+ RB_FOREACH(s, sessions, &sessions) {
if (s == ctx->curclient->session)
cur = idx;
idx++;
@@ -86,7 +83,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
}
- window_choose_add(wl->window->active, i,
+ window_choose_add(wl->window->active, s->idx,
"%s: %u windows [%ux%u]%s%s", s->name,
winlink_count(&s->windows), s->sx, s->sy,
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
@@ -120,9 +117,7 @@ cmd_choose_session_callback(void *data, int idx)
if (cdata->client->flags & CLIENT_DEAD)
return;
- if ((u_int) idx > ARRAY_LENGTH(&sessions) - 1)
- return;
- s = ARRAY_ITEM(&sessions, idx);
+ s = session_find_by_index(idx);
if (s == NULL)
return;
template = cmd_template_replace(cdata->template, s->name, 1);