=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.51 retrieving revision 1.52 diff -c -r1.51 -r1.52 *** src/usr.bin/tmux/cmd.c 2011/03/27 20:27:26 1.51 --- src/usr.bin/tmux/cmd.c 2011/04/05 19:37:01 1.52 *************** *** 1,4 **** ! /* $OpenBSD: cmd.c,v 1.51 2011/03/27 20:27:26 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd.c,v 1.52 2011/04/05 19:37:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 112,118 **** }; struct session *cmd_choose_session_list(struct sessionslist *); ! struct session *cmd_choose_session(void); struct client *cmd_choose_client(struct clients *); struct client *cmd_lookup_client(const char *); struct session *cmd_lookup_session(const char *, int *); --- 112,118 ---- }; struct session *cmd_choose_session_list(struct sessionslist *); ! struct session *cmd_choose_session(int); struct client *cmd_choose_client(struct clients *); struct client *cmd_lookup_client(const char *); struct session *cmd_lookup_session(const char *, int *); *************** *** 316,322 **** * session from all sessions. */ struct session * ! cmd_current_session(struct cmd_ctx *ctx) { struct msg_command_data *data = ctx->msgdata; struct client *c = ctx->cmdclient; --- 316,322 ---- * session from all sessions. */ struct session * ! cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached) { struct msg_command_data *data = ctx->msgdata; struct client *c = ctx->cmdclient; *************** *** 365,383 **** return (s); } ! return (cmd_choose_session()); } ! /* Find the most recently used session. */ struct session * ! cmd_choose_session(void) { struct session *s, *sbest; struct timeval *tv = NULL; sbest = NULL; RB_FOREACH(s, sessions, &sessions) { ! if (tv == NULL || timercmp(&s->activity_time, tv, >)) { sbest = s; tv = &s->activity_time; } --- 365,389 ---- return (s); } ! return (cmd_choose_session(prefer_unattached)); } ! /* ! * Find the most recently used session, preferring unattached if the flag is ! * set. ! */ struct session * ! cmd_choose_session(int prefer_unattached) { struct session *s, *sbest; struct timeval *tv = NULL; sbest = NULL; RB_FOREACH(s, sessions, &sessions) { ! if (tv == NULL || timercmp(&s->activity_time, tv, >) || ! (prefer_unattached && ! !(sbest->flags & SESSION_UNATTACHED) && ! (s->flags & SESSION_UNATTACHED))) { sbest = s; tv = &s->activity_time; } *************** *** 428,434 **** * No current client set. Find the current session and return the * newest of its clients. */ ! s = cmd_current_session(ctx); if (s != NULL && !(s->flags & SESSION_UNATTACHED)) { ARRAY_INIT(&cc); for (i = 0; i < ARRAY_LENGTH(&clients); i++) { --- 434,440 ---- * No current client set. Find the current session and return the * newest of its clients. */ ! s = cmd_current_session(ctx, 0); if (s != NULL && !(s->flags & SESSION_UNATTACHED)) { ARRAY_INIT(&cc); for (i = 0; i < ARRAY_LENGTH(&clients); i++) { *************** *** 671,677 **** struct winlink *wl; /* If this pane is in the current session, return that winlink. */ ! s = cmd_current_session(ctx); if (s != NULL) { wl = winlink_find_by_window(&s->windows, wp->window); if (wl != NULL) { --- 677,683 ---- struct winlink *wl; /* If this pane is in the current session, return that winlink. */ ! s = cmd_current_session(ctx, 0); if (s != NULL) { wl = winlink_find_by_window(&s->windows, wp->window); if (wl != NULL) { *************** *** 696,702 **** /* Find the target session or report an error and return NULL. */ struct session * ! cmd_find_session(struct cmd_ctx *ctx, const char *arg) { struct session *s; struct window_pane *wp; --- 702,708 ---- /* Find the target session or report an error and return NULL. */ struct session * ! cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached) { struct session *s; struct window_pane *wp; *************** *** 707,713 **** /* A NULL argument means the current session. */ if (arg == NULL) ! return (cmd_current_session(ctx)); tmparg = xstrdup(arg); /* Lookup as pane id. */ --- 713,719 ---- /* A NULL argument means the current session. */ if (arg == NULL) ! return (cmd_current_session(ctx, prefer_unattached)); tmparg = xstrdup(arg); /* Lookup as pane id. */ *************** *** 753,759 **** * Find the current session. There must always be a current session, if * it can't be found, report an error. */ ! if ((s = cmd_current_session(ctx)) == NULL) { ctx->error(ctx, "can't establish current session"); return (NULL); } --- 759,765 ---- * Find the current session. There must always be a current session, if * it can't be found, report an error. */ ! if ((s = cmd_current_session(ctx, 0)) == NULL) { ctx->error(ctx, "can't establish current session"); return (NULL); } *************** *** 900,906 **** * Find the current session. There must always be a current session, if * it can't be found, report an error. */ ! if ((s = cmd_current_session(ctx)) == NULL) { ctx->error(ctx, "can't establish current session"); return (-2); } --- 906,912 ---- * Find the current session. There must always be a current session, if * it can't be found, report an error. */ ! if ((s = cmd_current_session(ctx, 0)) == NULL) { ctx->error(ctx, "can't establish current session"); return (-2); } *************** *** 1054,1060 **** u_int idx; /* Get the current session. */ ! if ((s = cmd_current_session(ctx)) == NULL) { ctx->error(ctx, "can't establish current session"); return (NULL); } --- 1060,1066 ---- u_int idx; /* Get the current session. */ ! if ((s = cmd_current_session(ctx, 0)) == NULL) { ctx->error(ctx, "can't establish current session"); return (NULL); }