mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +00:00
Add a no-detached choice to detach-on-destroy which detaches only if
there are no other detached sessions to switch to, from Sencer Selcuk in GitHub issue 2553.
This commit is contained in:
@ -72,6 +72,9 @@ static const char *options_table_window_size_list[] = {
|
|||||||
static const char *options_table_remain_on_exit_list[] = {
|
static const char *options_table_remain_on_exit_list[] = {
|
||||||
"off", "on", "failed", NULL
|
"off", "on", "failed", NULL
|
||||||
};
|
};
|
||||||
|
static const char *options_table_detach_on_destroy_list[] = {
|
||||||
|
"off", "on", "no-detached", NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* Status line format. */
|
/* Status line format. */
|
||||||
#define OPTIONS_TABLE_STATUS_FORMAT1 \
|
#define OPTIONS_TABLE_STATUS_FORMAT1 \
|
||||||
@ -405,8 +408,9 @@ const struct options_table_entry options_table[] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "detach-on-destroy",
|
{ .name = "detach-on-destroy",
|
||||||
.type = OPTIONS_TABLE_FLAG,
|
.type = OPTIONS_TABLE_CHOICE,
|
||||||
.scope = OPTIONS_TABLE_SESSION,
|
.scope = OPTIONS_TABLE_SESSION,
|
||||||
|
.choices = options_table_detach_on_destroy_list,
|
||||||
.default_num = 1,
|
.default_num = 1,
|
||||||
.text = "Whether to detach when a session is destroyed, or switch "
|
.text = "Whether to detach when a session is destroyed, or switch "
|
||||||
"the client to another session if any exist."
|
"the client to another session if any exist."
|
||||||
|
25
server-fn.c
25
server-fn.c
@ -401,9 +401,8 @@ server_destroy_session_group(struct session *s)
|
|||||||
static struct session *
|
static struct session *
|
||||||
server_next_session(struct session *s)
|
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) {
|
RB_FOREACH(s_loop, sessions, &sessions) {
|
||||||
if (s_loop == s)
|
if (s_loop == s)
|
||||||
continue;
|
continue;
|
||||||
@ -414,17 +413,35 @@ server_next_session(struct session *s)
|
|||||||
return (s_out);
|
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
|
void
|
||||||
server_destroy_session(struct session *s)
|
server_destroy_session(struct session *s)
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct session *s_new;
|
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);
|
s_new = server_next_session(s);
|
||||||
|
else if (detach_on_destroy == 2)
|
||||||
|
s_new = server_next_detached_session(s);
|
||||||
else
|
else
|
||||||
s_new = NULL;
|
s_new = NULL;
|
||||||
|
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
if (c->session != s)
|
if (c->session != s)
|
||||||
continue;
|
continue;
|
||||||
|
6
tmux.1
6
tmux.1
@ -3575,12 +3575,16 @@ The default is 80x24.
|
|||||||
If enabled and the session is no longer attached to any clients, it is
|
If enabled and the session is no longer attached to any clients, it is
|
||||||
destroyed.
|
destroyed.
|
||||||
.It Xo Ic detach-on-destroy
|
.It Xo Ic detach-on-destroy
|
||||||
.Op Ic on | off
|
.Op Ic off | on | no-detached
|
||||||
.Xc
|
.Xc
|
||||||
If on (the default), the client is detached when the session it is attached to
|
If on (the default), the client is detached when the session it is attached to
|
||||||
is destroyed.
|
is destroyed.
|
||||||
If off, the client is switched to the most recently active of the remaining
|
If off, the client is switched to the most recently active of the remaining
|
||||||
sessions.
|
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
|
.It Ic display-panes-active-colour Ar colour
|
||||||
Set the colour used by the
|
Set the colour used by the
|
||||||
.Ic display-panes
|
.Ic display-panes
|
||||||
|
Reference in New Issue
Block a user