diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-11-15 14:09:05 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-11-15 14:09:05 +0000 |
commit | 86ae353066e692bce701fc2d2b6ae6251e51969b (patch) | |
tree | b2da3b4597a3150ba296d6149706e239e014eca4 /usr.bin/tmux | |
parent | ae58853c01a2c1ba5f25057625b07899fb2645e7 (diff) |
Add no-detach-on-destroy client option (useful for control mode
clients). From laur dot aliste at gmail dot com, GitHub issue 4242.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/server-client.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 23 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 5 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
4 files changed, 28 insertions, 9 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index d76a867135c..3f2a5fbd8c5 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.418 2024/11/15 13:12:20 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.419 2024/11/15 14:09:04 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -3683,6 +3683,8 @@ server_client_set_flags(struct client *c, const char *flags) flag = CLIENT_IGNORESIZE; else if (strcmp(next, "active-pane") == 0) flag = CLIENT_ACTIVEPANE; + else if (strcmp(next, "no-detach-on-destroy") == 0) + flag = CLIENT_NO_DETACH_ON_DESTROY; if (flag == 0) continue; @@ -3716,6 +3718,8 @@ server_client_get_flags(struct client *c) strlcat(s, "control-mode,", sizeof s); if (c->flags & CLIENT_IGNORESIZE) strlcat(s, "ignore-size,", sizeof s); + if (c->flags & CLIENT_NO_DETACH_ON_DESTROY) + strlcat(s, "no-detach-on-destroy,", sizeof s); if (c->flags & CLIENT_CONTROL_NOOUTPUT) strlcat(s, "no-output,", sizeof s); if (c->flags & CLIENT_CONTROL_WAITEXIT) diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index e3cd2186cf7..0587897ab9a 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.137 2024/04/04 22:44:40 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.138 2024/11/15 14:09:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -425,7 +425,7 @@ void server_destroy_session(struct session *s) { struct client *c; - struct session *s_new = NULL; + struct session *s_new = NULL, *cs_new, *use_s; int detach_on_destroy; detach_on_destroy = options_get_number(s->options, "detach-on-destroy"); @@ -437,15 +437,26 @@ server_destroy_session(struct session *s) s_new = session_previous_session(s); else if (detach_on_destroy == 4) s_new = session_next_session(s); - if (s_new == s) - s_new = NULL; + + /* + * If no suitable new session was found above, then look for any + * session as an alternative in case a client needs it. + */ + if (s_new == NULL && + (detach_on_destroy == 1 || detach_on_destroy == 2)) + cs_new = server_find_session(s, server_newer_session); + TAILQ_FOREACH(c, &clients, entry) { if (c->session != s) continue; + use_s = s_new; + if (use_s == NULL && (c->flags & CLIENT_NO_DETACH_ON_DESTROY)) + use_s = cs_new; + c->session = NULL; c->last_session = NULL; - server_client_set_session(c, s_new); - if (s_new == NULL) + server_client_set_session(c, use_s); + if (use_s == NULL) c->flags |= CLIENT_EXIT; } recalculate_sizes(); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 3c50e851917..64bec7eb84c 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.972 2024/11/15 13:12:20 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.973 2024/11/15 14:09:04 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -1066,6 +1066,9 @@ The flags are: the client has an independent active pane .It ignore-size the client does not affect the size of other clients +.It no-detach-on-destroy +do not detach the client when the session it is attached to is destroyed if +there are any other sessions .It no-output the client does not receive pane output in control mode .It pause-after=seconds diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ef2cc1d0532..73985b8f8de 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1242 2024/11/15 13:12:20 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1243 2024/11/15 14:09:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1924,6 +1924,7 @@ struct client { #define CLIENT_BRACKETPASTING 0x1000000000ULL #define CLIENT_ASSUMEPASTING 0x2000000000ULL #define CLIENT_REDRAWSCROLLBARS 0x4000000000ULL +#define CLIENT_NO_DETACH_ON_DESTROY 0x8000000000ULL #define CLIENT_ALLREDRAWFLAGS \ (CLIENT_REDRAWWINDOW| \ CLIENT_REDRAWSTATUS| \ |