From 743939ec84f4652f1d3288e70a4c1aca327a0e07 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Thu, 28 Nov 2019 12:30:36 +0000 Subject: [PATCH 1/4] add missing definition --- server-client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/server-client.c b/server-client.c index 2cfd8838..a1a51b5f 100644 --- a/server-client.c +++ b/server-client.c @@ -1320,6 +1320,7 @@ static int server_client_resize_force(struct window_pane *wp) { struct timeval tv = { .tv_usec = 100000 }; + struct winsize ws; /* * If we are resizing to the same size as when we entered the loop From 3bb11ec4843e1cd942e703bb386369e42466acd8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 28 Nov 2019 14:36:32 +0000 Subject: [PATCH 2/4] Revert "add missing definition" This reverts commit 743939ec84f4652f1d3288e70a4c1aca327a0e07. --- server-client.c | 1 - 1 file changed, 1 deletion(-) diff --git a/server-client.c b/server-client.c index a1a51b5f..2cfd8838 100644 --- a/server-client.c +++ b/server-client.c @@ -1320,7 +1320,6 @@ static int server_client_resize_force(struct window_pane *wp) { struct timeval tv = { .tv_usec = 100000 }; - struct winsize ws; /* * If we are resizing to the same size as when we entered the loop From c5d74b1debc404340dd2049c708f9eb599be706e Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 28 Nov 2019 21:18:38 +0000 Subject: [PATCH 3/4] Do not crash when a format doesn't exist, reported by Thomas Sattler. --- format.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/format.c b/format.c index 86878cda..e74de9c1 100644 --- a/format.c +++ b/format.c @@ -1112,11 +1112,10 @@ format_find(struct format_tree *ft, const char *key, int modifiers) xasprintf(&found, "%lld", (long long)fe->t); goto found; } - if (fe->value == NULL && fe->cb != NULL) { + if (fe->value == NULL && fe->cb != NULL) fe->cb(ft, fe); - if (fe->value == NULL) - fe->value = xstrdup(""); - } + if (fe->value == NULL) + fe->value = xstrdup(""); found = xstrdup(fe->value); goto found; } From 67d995d1003ef215b292f772a8e5394eb50569c4 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 29 Nov 2019 16:04:07 +0000 Subject: [PATCH 4/4] If a window appears in only one attached session, there is no point in worrying about which is the latest client (there is only one). --- cmd-attach-session.c | 2 ++ resize.c | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 6de734e5..477d3517 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -127,6 +127,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, gettimeofday(&s->last_attached_time, NULL); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; + s->curw->window->latest = c; } else { if (server_client_open(c, &cause) != 0) { cmdq_error(item, "open terminal failed: %s", cause); @@ -159,6 +160,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, gettimeofday(&s->last_attached_time, NULL); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; + s->curw->window->latest = c; if (~c->flags & CLIENT_CONTROL) proc_send(c->peer, MSG_READY, -1, NULL, 0); diff --git a/resize.c b/resize.c index 9f74b33e..054b025f 100644 --- a/resize.c +++ b/resize.c @@ -80,7 +80,7 @@ default_window_size(struct client *c, struct session *s, struct window *w, u_int *sx, u_int *sy, u_int *xpixel, u_int *ypixel, int type) { struct client *loop; - u_int cx, cy; + u_int cx, cy, n; const char *value; if (type == -1) @@ -149,12 +149,22 @@ default_window_size(struct client *c, struct session *s, struct window *w, *xpixel = c->tty.xpixel; *ypixel = c->tty.ypixel; } else { + if (w == NULL) + goto manual; + n = 0; + TAILQ_FOREACH(loop, &clients, entry) { + if (!ignore_client_size(loop) && + session_has(loop->session, w)) { + if (++n > 1) + break; + } + } *sx = *sy = UINT_MAX; *xpixel = *ypixel = 0; TAILQ_FOREACH(loop, &clients, entry) { if (ignore_client_size(loop)) continue; - if (w != NULL && loop != w->latest) + if (n > 1 && loop != w->latest) continue; s = loop->session; @@ -204,7 +214,7 @@ recalculate_size(struct window *w) { struct session *s; struct client *c; - u_int sx, sy, cx, cy, xpixel = 0, ypixel = 0; + u_int sx, sy, cx, cy, xpixel = 0, ypixel = 0, n; int type, current, has, changed; if (w->active == NULL) @@ -277,11 +287,19 @@ recalculate_size(struct window *w) changed = 0; break; case WINDOW_SIZE_LATEST: + n = 0; + TAILQ_FOREACH(c, &clients, entry) { + if (!ignore_client_size(c) && + session_has(c->session, w)) { + if (++n > 1) + break; + } + } sx = sy = UINT_MAX; TAILQ_FOREACH(c, &clients, entry) { if (ignore_client_size(c)) continue; - if (c != w->latest) + if (n > 1 && c != w->latest) continue; s = c->session;