diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-06-05 16:47:12 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-06-05 16:47:12 +0000 |
commit | 572c74a383c5ffb081f4ebc1a63f1a8476bb240b (patch) | |
tree | 7f0b9a49ba660dbeba70d00cfc76997268777f08 /usr.bin/tmux | |
parent | e49bc863c4403dfec710ad3a15977a979c956b02 (diff) |
Fix problems with window sizing seen by Raghavendra D Prabhu when
starting tmux from .xinitrc.
One of the very few things the server relies on the client for now is to
pass through a message on SIGWINCH, but there is a condition where
potentially a SIGWINCH may be lost during the transition from unattached
(main.c) to attached (client.c). So trigger a size change immediately
after the client installs its SIGWINCH handler.
Also, when the terminal is resized, reset the scroll region and cursor
position. Previously, we were clearing our saved idea of these, but in
fact some terminals do not reset them on resize, so this caused problems
during redraw.
While here make a resize to the same size not cause a redraw and rename
the tmux.out output log file to include the tmux PID.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/client.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 39 |
4 files changed, 45 insertions, 16 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index 8fd03ac6f49..66a85dcd8f8 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.40 2010/06/05 16:29:45 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.41 2010/06/05 16:47:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -176,6 +176,13 @@ client_main(void) 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 * MSG_READY switched to here. Process anything outstanding now to diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 622b93f9432..3271d9f37bb 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.31 2010/05/23 19:42:19 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.32 2010/06/05 16:47:11 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index a367166da40..905e018dd88 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.223 2010/05/31 19:51:29 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.224 2010/06/05 16:47:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index ae950f6a3a8..1d64d2555ea 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.87 2010/06/05 16:32:22 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.88 2010/06/05 16:47:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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; |