diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 16:00:26 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 16:00:26 +0000 |
commit | eaaeb28cda0ca1a31d1bf5662330388c585a0921 (patch) | |
tree | 965c7f6f7850e8b0c575bf5ffb1f70486c31699e /session.c | |
parent | 295d86911e7f7823785d138d96d94ccfa924e29d (diff) |
Add session_set_current helper function, extracted from a diff from
Aaron Jensen.
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -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; |