From 89c07dedd9159e45c81a490a68f953b569d72f48 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Fri, 10 Sep 2010 13:36:17 +0000 Subject: Sync OpenBSD patchset 759: Add -n and -p flags to switch-client to move to the next and previous session (yes, it doesn't match window/pane, but so what, nor does switch-client). Based on a diff long ago from "edsouza". --- session.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'session.c') diff --git a/session.c b/session.c index 4b469e5b..1cd2d584 100644 --- a/session.c +++ b/session.c @@ -1,4 +1,4 @@ -/* $Id: session.c,v 1.77 2010-07-02 02:49:19 tcunha Exp $ */ +/* $Id: session.c,v 1.78 2010-09-10 13:36:17 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -168,6 +168,48 @@ session_index(struct session *s, u_int *i) return (-1); } +/* Find the next usable session. */ +struct session * +session_next_session(struct session *s) +{ + struct session *s2; + u_int i; + + if (ARRAY_LENGTH(&sessions) == 0 || session_index(s, &i) != 0) + return (NULL); + + do { + if (i == ARRAY_LENGTH(&sessions) - 1) + i = 0; + else + i++; + s2 = ARRAY_ITEM(&sessions, i); + } while (s2 == NULL || s2->flags & SESSION_DEAD); + + return (s2); +} + +/* Find the previous usable session. */ +struct session * +session_previous_session(struct session *s) +{ + struct session *s2; + u_int i; + + if (ARRAY_LENGTH(&sessions) == 0 || session_index(s, &i) != 0) + return (NULL); + + do { + if (i == 0) + i = ARRAY_LENGTH(&sessions) - 1; + else + i--; + s2 = ARRAY_ITEM(&sessions, i); + } while (s2 == NULL || s2->flags & SESSION_DEAD); + + return (s2); +} + /* Create a new window on a session. */ struct winlink * session_new(struct session *s, -- cgit