diff --git a/client.c b/client.c index 326ca100..35cf2801 100644 --- a/client.c +++ b/client.c @@ -175,6 +175,13 @@ client_main(void) /* Set up signals. */ set_signals(client_signal); + /* + * Send a resize message immediately in case the terminal size has + * changed between the identify message to the server and the MSG_READY + * telling us to move into the client code. + */ + client_write_server(MSG_RESIZE, NULL, 0); + /* * imsg_read in the first client poll loop (before the terminal has * been initialised) may have read messages into the buffer after the diff --git a/server-client.c b/server-client.c index 9d550386..301c986a 100644 --- a/server-client.c +++ b/server-client.c @@ -561,9 +561,10 @@ server_client_msg_dispatch(struct client *c) if (datalen != 0) fatalx("bad MSG_RESIZE size"); - tty_resize(&c->tty); - recalculate_sizes(); - server_redraw_client(c); + if (tty_resize(&c->tty)) { + recalculate_sizes(); + server_redraw_client(c); + } break; case MSG_EXITING: if (datalen != 0) diff --git a/tmux.h b/tmux.h index 3069f89b..a9e41351 100644 --- a/tmux.h +++ b/tmux.h @@ -1351,7 +1351,7 @@ void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_pututf8(struct tty *, const struct grid_utf8 *); void tty_init(struct tty *, int, char *); -void tty_resize(struct tty *); +int tty_resize(struct tty *); void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); diff --git a/tty.c b/tty.c index 4fe946af..fa2cd552 100644 --- a/tty.c +++ b/tty.c @@ -73,34 +73,55 @@ tty_init(struct tty *tty, int fd, char *term) tty->term_flags = 0; } -void +int tty_resize(struct tty *tty) { struct winsize ws; + u_int sx, sy; if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) { - tty->sx = ws.ws_col; - tty->sy = ws.ws_row; + sx = ws.ws_col; + if (sx == 0) + sx = 80; + sy = ws.ws_row; + if (sy == 0) + sy = 24; + } else { + sx = 80; + sy = 24; } - if (tty->sx == 0) - tty->sx = 80; - if (tty->sy == 0) - tty->sy = 24; + if (sx == tty->sx && sy == tty->sy) + return (0); + tty->sx = sx; + tty->sy = sy; tty->cx = UINT_MAX; tty->cy = UINT_MAX; tty->rupper = UINT_MAX; tty->rlower = UINT_MAX; + + /* + * If the terminal has been started, reset the actual scroll region and + * cursor position, as this may not have happened. + */ + if (tty->flags & TTY_STARTED) { + tty_cursor(tty, 0, 0); + tty_region(tty, 0, tty->sy - 1); + } + + return (1); } int tty_open(struct tty *tty, const char *overrides, char **cause) { + char out[64]; int fd; if (debug_level > 3) { - fd = open("tmux.out", O_WRONLY|O_CREAT|O_TRUNC, 0644); + xsnprintf(out, sizeof out, "tmux-out-%ld.log", (long) getpid()); + fd = open(out, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd != -1 && fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) fatal("fcntl failed"); tty->log_fd = fd;