diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2021-04-16 11:59:08 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2021-04-16 11:59:08 +0100 |
commit | 9af78c8e694dd3c05859c228856621a5a746de58 (patch) | |
tree | 98017bd8fbbc905aa5e9b8feb764811aa99a09cb /server-client.c | |
parent | dda3bf896be9ce87b4066636cc7f94ab8030133a (diff) | |
download | rtmux-9af78c8e694dd3c05859c228856621a5a746de58.tar.gz rtmux-9af78c8e694dd3c05859c228856621a5a746de58.tar.bz2 rtmux-9af78c8e694dd3c05859c228856621a5a746de58.zip |
Adjust latest client when a client detaches, GitHub issue 2657.
Diffstat (limited to 'server-client.c')
-rw-r--r-- | server-client.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/server-client.c b/server-client.c index d3ffd682..0f8ad687 100644 --- a/server-client.c +++ b/server-client.c @@ -43,6 +43,7 @@ static void server_client_check_modes(struct client *); static void server_client_set_title(struct client *); static void server_client_reset_state(struct client *); static int server_client_assume_paste(struct session *); +static void server_client_update_latest(struct client *); static void server_client_dispatch(struct imsg *, void *); static void server_client_dispatch_command(struct client *, struct imsg *); @@ -271,6 +272,40 @@ server_client_open(struct client *c, char **cause) return (0); } +/* Lost an attached client. */ +static void +server_client_attached_lost(struct client *c) +{ + struct session *s = c->session; + struct window *w; + struct client *loop; + struct client *found; + + log_debug("lost attached client %p", c); + + /* + * By this point the session in the client has been cleared so walk all + * windows to find any with this client as the latest. + */ + RB_FOREACH(w, windows, &windows) { + if (w->latest != c) + continue; + + found = NULL; + TAILQ_FOREACH(loop, &clients, entry) { + s = loop->session; + if (loop == c || s == NULL || s->curw->window != w) + continue; + if (found == NULL || + timercmp(&loop->activity_time, &found->activity_time, + >)) + found = loop; + } + if (found != NULL) + server_client_update_latest(found); + } +} + /* Lost a client. */ void server_client_lost(struct client *c) @@ -296,8 +331,10 @@ server_client_lost(struct client *c) TAILQ_REMOVE(&clients, c, entry); log_debug("lost client %p", c); - if (c->flags & CLIENT_ATTACHED) + if (c->flags & CLIENT_ATTACHED) { + server_client_attached_lost(c); notify_client("client-detached", c); + } if (c->flags & CLIENT_CONTROL) control_stop(c); |