-/* $OpenBSD: options-table.c,v 1.138 2021/01/20 07:16:54 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.139 2021/02/01 08:01:14 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
static const char *options_table_remain_on_exit_list[] = {
"off", "on", "failed", NULL
};
+static const char *options_table_detach_on_destroy_list[] = {
+ "off", "on", "no-detached", NULL
+};
/* Status line format. */
#define OPTIONS_TABLE_STATUS_FORMAT1 \
},
{ .name = "detach-on-destroy",
- .type = OPTIONS_TABLE_FLAG,
+ .type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SESSION,
+ .choices = options_table_detach_on_destroy_list,
.default_num = 1,
.text = "Whether to detach when a session is destroyed, or switch "
"the client to another session if any exist."
-/* $OpenBSD: server-fn.c,v 1.129 2021/01/04 08:43:16 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.130 2021/02/01 08:01:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
static struct session *
server_next_session(struct session *s)
{
- struct session *s_loop, *s_out;
+ struct session *s_loop, *s_out = NULL;
- s_out = NULL;
RB_FOREACH(s_loop, sessions, &sessions) {
if (s_loop == s)
continue;
return (s_out);
}
+static struct session *
+server_next_detached_session(struct session *s)
+{
+ struct session *s_loop, *s_out = NULL;
+
+ RB_FOREACH(s_loop, sessions, &sessions) {
+ if (s_loop == s || s_loop->attached)
+ continue;
+ if (s_out == NULL ||
+ timercmp(&s_loop->activity_time, &s_out->activity_time, <))
+ s_out = s_loop;
+ }
+ return (s_out);
+}
+
void
server_destroy_session(struct session *s)
{
struct client *c;
struct session *s_new;
+ int detach_on_destroy;
- if (!options_get_number(s->options, "detach-on-destroy"))
+ detach_on_destroy = options_get_number(s->options, "detach-on-destroy");
+ if (detach_on_destroy == 0)
s_new = server_next_session(s);
+ else if (detach_on_destroy == 2)
+ s_new = server_next_detached_session(s);
else
s_new = NULL;
-
TAILQ_FOREACH(c, &clients, entry) {
if (c->session != s)
continue;
-.\" $OpenBSD: tmux.1,v 1.814 2021/01/29 09:48:43 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.815 2021/02/01 08:01:14 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 29 2021 $
+.Dd $Mdocdate: February 1 2021 $
.Dt TMUX 1
.Os
.Sh NAME
If enabled and the session is no longer attached to any clients, it is
destroyed.
.It Xo Ic detach-on-destroy
-.Op Ic on | off
+.Op Ic off | on | no-detached
.Xc
If on (the default), the client is detached when the session it is attached to
is destroyed.
If off, the client is switched to the most recently active of the remaining
sessions.
+If
+.Ic no-detached ,
+the client is detached only if there are no detached sessions; if detached
+sessions exist, the client is switched to the most recently active.
.It Ic display-panes-active-colour Ar colour
Set the colour used by the
.Ic display-panes