Skip to content

Commit

Permalink
Add no-detach-on-destroy client option (useful for control mode
Browse files Browse the repository at this point in the history
clients). From laur dot aliste at gmail dot com, GitHub issue 4242.
  • Loading branch information
nicm committed Nov 15, 2024
1 parent 350a151 commit c66628e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions server-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 16 additions & 5 deletions server-fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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| \
Expand Down

0 comments on commit c66628e

Please sign in to comment.