diff --git a/client.c b/client.c index ffaded72..aebf7784 100644 --- a/client.c +++ b/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.72 2009-09-23 14:39:30 tcunha Exp $ */ +/* $Id: client.c,v 1.73 2009-09-23 14:44:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -34,7 +34,6 @@ #include "tmux.h" void client_send_environ(struct client_ctx *); -void client_handle_winch(struct client_ctx *); int client_init(char *path, struct client_ctx *cctx, int cmdflags, int flags) @@ -104,8 +103,6 @@ server_started: if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) fatal("ioctl(TIOCGWINSZ)"); data.flags = flags; - data.sx = ws.ws_col; - data.sy = ws.ws_row; if (getcwd(data.cwd, sizeof data.cwd) == NULL) *data.cwd = '\0'; @@ -173,8 +170,10 @@ client_main(struct client_ctx *cctx) waitpid(WAIT_ANY, NULL, WNOHANG); sigchld = 0; } - if (sigwinch) - client_handle_winch(cctx); + if (sigwinch) { + client_write_server(cctx, MSG_RESIZE, NULL, 0); + sigwinch = 0; + } if (sigcont) { siginit(); client_write_server(cctx, MSG_WAKEUP, NULL, 0); @@ -242,22 +241,6 @@ out: } } -void -client_handle_winch(struct client_ctx *cctx) -{ - struct msg_resize_data data; - struct winsize ws; - - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) - fatal("ioctl failed"); - - data.sx = ws.ws_col; - data.sy = ws.ws_row; - client_write_server(cctx, MSG_RESIZE, &data, sizeof data); - - sigwinch = 0; -} - int client_msg_dispatch(struct client_ctx *cctx) { diff --git a/server-msg.c b/server-msg.c index 5ed956ac..cecf9aa9 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.85 2009-09-23 14:39:30 tcunha Exp $ */ +/* $Id: server-msg.c,v 1.86 2009-09-23 14:44:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -28,7 +29,6 @@ void server_msg_command(struct client *, struct msg_command_data *); void server_msg_identify(struct client *, struct msg_identify_data *, int); -void server_msg_resize(struct client *, struct msg_resize_data *); void printflike2 server_msg_command_error(struct cmd_ctx *, const char *, ...); void printflike2 server_msg_command_print(struct cmd_ctx *, const char *, ...); @@ -40,7 +40,6 @@ server_msg_dispatch(struct client *c) struct imsg imsg; struct msg_command_data commanddata; struct msg_identify_data identifydata; - struct msg_resize_data resizedata; struct msg_unlock_data unlockdata; struct msg_environ_data environdata; ssize_t n, datalen; @@ -81,11 +80,12 @@ server_msg_dispatch(struct client *c) server_msg_identify(c, &identifydata, imsg.fd); break; case MSG_RESIZE: - if (datalen != sizeof resizedata) + if (datalen != 0) fatalx("bad MSG_RESIZE size"); - memcpy(&resizedata, imsg.data, sizeof resizedata); - server_msg_resize(c, &resizedata); + tty_resize(&c->tty); + recalculate_sizes(); + server_redraw_client(c); break; case MSG_EXITING: if (datalen != 0) @@ -261,33 +261,7 @@ server_msg_identify(struct client *c, struct msg_identify_data *data, int fd) if (data->flags & IDENTIFY_HASDEFAULTS) c->tty.term_flags |= TERM_HASDEFAULTS; - c->tty.sx = data->sx; - if (c->tty.sx == 0) - c->tty.sx = 80; - c->tty.sy = data->sy; - if (c->tty.sy == 0) - c->tty.sy = 24; + tty_resize(&c->tty); c->flags |= CLIENT_TERMINAL; } - -void -server_msg_resize(struct client *c, struct msg_resize_data *data) -{ - c->tty.sx = data->sx; - if (c->tty.sx == 0) - c->tty.sx = 80; - c->tty.sy = data->sy; - if (c->tty.sy == 0) - c->tty.sy = 24; - - c->tty.cx = UINT_MAX; - c->tty.cy = UINT_MAX; - c->tty.rupper = UINT_MAX; - c->tty.rlower = UINT_MAX; - - recalculate_sizes(); - - /* Always redraw this client. */ - server_redraw_client(c); -} diff --git a/tmux.h b/tmux.h index 50b306d4..93fbca9d 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.451 2009-09-23 14:39:30 tcunha Exp $ */ +/* $Id: tmux.h,v 1.452 2009-09-23 14:44:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -21,7 +21,7 @@ #include "config.h" -#define PROTOCOL_VERSION 2 +#define PROTOCOL_VERSION 3 #include #include @@ -335,14 +335,6 @@ struct msg_identify_data { #define IDENTIFY_88COLOURS 0x4 #define IDENTIFY_HASDEFAULTS 0x8 int flags; - - u_int sx; - u_int sy; -}; - -struct msg_resize_data { - u_int sx; - u_int sy; }; struct msg_unlock_data { @@ -1197,6 +1189,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 *); void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_detect_utf8(struct tty *); diff --git a/tty.c b/tty.c index 98c25ccf..68d1eef4 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.134 2009-09-23 14:39:30 tcunha Exp $ */ +/* $Id: tty.c,v 1.135 2009-09-23 14:44:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -73,6 +73,27 @@ tty_init(struct tty *tty, int fd, char *term) tty->term_flags = 0; } +void +tty_resize(struct tty *tty) +{ + struct winsize ws; + + if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) { + tty->sx = ws.ws_col; + tty->sy = ws.ws_row; + } + if (tty->sx == 0) + tty->sx = 80; + if (tty->sy == 0) + tty->sy = 24; + + tty->cx = UINT_MAX; + tty->cy = UINT_MAX; + + tty->rupper = UINT_MAX; + tty->rlower = UINT_MAX; +} + int tty_open(struct tty *tty, const char *overrides, char **cause) {