diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-23 06:12:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-23 06:12:59 +0000 |
commit | f0935dc4d22d17994911925fa31450d1e56b9ed1 (patch) | |
tree | 2c6c89889467636119a9b28dcb7ac928c927d1f9 /usr.bin/tmux | |
parent | 2b84192e7b8eb93391d542663ddeb26ad4cec6d5 (diff) |
Trim some code by moving the ioctl(TIOCGWINSZ) after SIGWINCH from the client
into the server.
This is another (the second of four) protocol version changes coming this
morning, so again the server should be killed before upgrading.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/client.c | 27 | ||||
-rw-r--r-- | usr.bin/tmux/server-msg.c | 40 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 13 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 23 |
4 files changed, 37 insertions, 66 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index a152687f212..eda669fa41f 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.19 2009/09/23 06:05:02 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.20 2009/09/23 06:12:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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) @@ -100,8 +99,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'; @@ -169,8 +166,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); @@ -238,22 +237,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/usr.bin/tmux/server-msg.c b/usr.bin/tmux/server-msg.c index 922b733a158..26d7c5d0d26 100644 --- a/usr.bin/tmux/server-msg.c +++ b/usr.bin/tmux/server-msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-msg.c,v 1.18 2009/09/23 06:05:02 nicm Exp $ */ +/* $OpenBSD: server-msg.c,v 1.19 2009/09/23 06:12:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -17,6 +17,7 @@ */ #include <sys/types.h> +#include <sys/ioctl.h> #include <errno.h> #include <stdlib.h> @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index c150949e00a..acdbffaeada 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.113 2009/09/23 06:05:02 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.114 2009/09/23 06:12:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -19,7 +19,7 @@ #ifndef TMUX_H #define TMUX_H -#define PROTOCOL_VERSION 2 +#define PROTOCOL_VERSION 3 #include <sys/param.h> #include <sys/time.h> @@ -337,14 +337,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 { @@ -1199,6 +1191,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/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 9ec4b83e4d6..aa85f9e051a 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.30 2009/09/23 06:05:02 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.31 2009/09/23 06:12:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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) { |