diff options
author | Thomas Adam <thomas@xteddy.org> | 2021-02-01 10:01:20 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2021-02-01 10:01:20 +0000 |
commit | 0242513ce7ce3632fc7b30f8eac2c89bb77064ee (patch) | |
tree | 3c18ef664117260acc056d26b69104a70bbbb59d | |
parent | 545a610c6b14af2db02eb40866654f0df7ad2b6a (diff) | |
parent | 509221520c87510016f5c90aeea0d4dcc4b74a98 (diff) |
Merge branch 'obsd-master' into master
-rw-r--r-- | options-table.c | 6 | ||||
-rw-r--r-- | server-fn.c | 25 | ||||
-rw-r--r-- | tmux.1 | 6 |
3 files changed, 31 insertions, 6 deletions
diff --git a/options-table.c b/options-table.c index 4f7a6f34..a6f07cf9 100644 --- a/options-table.c +++ b/options-table.c @@ -71,6 +71,9 @@ static const char *options_table_window_size_list[] = { 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 \ @@ -404,8 +407,9 @@ const struct options_table_entry options_table[] = { }, { .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." diff --git a/server-fn.c b/server-fn.c index 0bda8198..656de08e 100644 --- a/server-fn.c +++ b/server-fn.c @@ -402,9 +402,8 @@ server_destroy_session_group(struct session *s) 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; @@ -415,17 +414,35 @@ server_next_session(struct session *s) 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; @@ -3575,12 +3575,16 @@ The default is 80x24. 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 |