diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-22 16:00:27 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-22 16:00:27 +0000 |
commit | 06c0c5104a3dd63d4a1aa2076570f6d451aed9b5 (patch) | |
tree | 2a730dbea89013831f16dffcde792cf7b0793982 | |
parent | e08a225662b8b3b2b32642694124a5f1d54d8861 (diff) |
Add session_set_current helper function, extracted from a diff from
Aaron Jensen.
-rw-r--r-- | usr.bin/tmux/session.c | 40 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
2 files changed, 18 insertions, 25 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 1511ebf4169..c3bd592bb4a 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.36 2012/07/10 11:53:01 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.37 2013/03/22 16:00:26 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -346,13 +346,7 @@ session_next(struct session *s, int alert) if (alert && ((wl = session_next_alert(wl)) == NULL)) return (-1); } - if (wl == s->curw) - return (1); - winlink_stack_remove(&s->lastw, wl); - winlink_stack_push(&s->lastw, s->curw); - s->curw = wl; - winlink_clear_flags(wl); - return (0); + return (session_set_current(s, wl)); } struct winlink * @@ -383,13 +377,7 @@ session_previous(struct session *s, int alert) if (alert && (wl = session_previous_alert(wl)) == NULL) return (-1); } - if (wl == s->curw) - return (1); - winlink_stack_remove(&s->lastw, wl); - winlink_stack_push(&s->lastw, s->curw); - s->curw = wl; - winlink_clear_flags(wl); - return (0); + return (session_set_current(s, wl)); } /* Move session to specific window. */ @@ -399,15 +387,7 @@ session_select(struct session *s, int idx) struct winlink *wl; wl = winlink_find_by_index(&s->windows, idx); - if (wl == NULL) - return (-1); - if (wl == s->curw) - return (1); - winlink_stack_remove(&s->lastw, wl); - winlink_stack_push(&s->lastw, s->curw); - s->curw = wl; - winlink_clear_flags(wl); - return (0); + return (session_set_current(s, wl)); } /* Move session to last used window. */ @@ -422,6 +402,18 @@ session_last(struct session *s) if (wl == s->curw) return (1); + return (session_set_current(s, wl)); +} + +/* Set current winlink to wl .*/ +int +session_set_current(struct session *s, struct winlink *wl) +{ + if (wl == NULL) + return (-1); + if (wl == s->curw) + return (1); + winlink_stack_remove(&s->lastw, wl); winlink_stack_push(&s->lastw, s->curw); s->curw = wl; diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 805afc525e1..8c210c98281 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.391 2013/03/22 15:56:11 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.392 2013/03/22 16:00:26 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -2280,6 +2280,7 @@ int session_next(struct session *, int); int session_previous(struct session *, int); int session_select(struct session *, int); int session_last(struct session *); +int session_set_current(struct session *, struct winlink *); struct session_group *session_group_find(struct session *); u_int session_group_index(struct session_group *); void session_group_add(struct session *, struct session *); |