diff options
author | Tiago Cunha <tcunha@gmx.com> | 2010-12-22 15:36:44 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2010-12-22 15:36:44 +0000 |
commit | a373235106d22fdead116d478087d8f8f11c150d (patch) | |
tree | 2f4aba9efa49f7855e918e095d13f6085f8d4d91 /cmd-choose-session.c | |
parent | 9f3399da001580aa8b2118bb38245c7c5f26e944 (diff) |
Sync OpenBSD patchset 806:
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.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/cmd-choose-session.c b/cmd-choose-session.c index 9dabf58e..200ed849 100644 --- a/cmd-choose-session.c +++ b/cmd-choose-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-choose-session.c,v 1.16 2010-12-22 15:25:07 tcunha Exp $ */ +/* $Id: cmd-choose-session.c,v 1.17 2010-12-22 15:36:44 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); |