When a control mode client attaches, the client size is unknown. A control
mode client's tty is initialized to 80x24. When attaching,
recalculate_sizes gets called, which changes pane layouts.

Unlike regular clients, control mode clients should always set the client
size explicitly with refresh-client -C, but they don't get a chance to do
so early enough.

To avoid corrupting the existing layouts when detaching and reattaching,
this patch sets a control mode client's tty size when attaching for the
first time based on the existing window sizes in the session.

One issue: Behavior in aggressive-resize isn't great. I'm not sure how much
it matters in practice. iTerm2 refuses to attach when aggressive-resize is
enabled.

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 81ed4a8..4cc84c7 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -58,6 +58,8 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, 
int dflag,
        struct winlink          *wl;
        struct window_pane      *wp;
        char                    *cause;
+       int                      of = c->flags;
+       u_int                    sx, sy;
 
        if (RB_EMPTY(&sessions)) {
                cmdq_error(item, "no sessions");
@@ -153,6 +155,16 @@ cmd_attach_session(struct cmdq_item *item, const char 
*tflag, int dflag,
                notify_client("client-attached", c);
                c->flags |= CLIENT_ATTACHED;
        }
+       if (!(of & CLIENT_ATTACHED) && (c->flags & CLIENT_CONTROL)) {
+               sx = sy = 0;
+               RB_FOREACH(wl, winlinks, &s->windows) {
+                       if (wl->window->sx > sx) sx = wl->window->sx;
+                       if (wl->window->sy > sy) sy = wl->window->sy;
+               }
+               if (sx > 0 && sy > 0) {
+                       tty_set_size(&c->tty, sx, sy);
+               }
+       }
        recalculate_sizes();
        alerts_check_session(s);
        server_update_socket();

Reply via email to