diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-06-21 06:16:45 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-06-21 06:16:45 +0000 |
commit | 3c8087a0f912d3dae9d63fd6cfb4bb6c97cf7909 (patch) | |
tree | 19bcb197df9a9b3ec94788e5a3704d95e01b3643 | |
parent | 8d6e2fee0f96497dc1ced5c688a9a4d51995e2a4 (diff) |
o Resize nicely when we receive SIGWINCH
o Also change some 0-2 to *_FILENO
-rw-r--r-- | usr.bin/talk/get_names.c | 6 | ||||
-rw-r--r-- | usr.bin/talk/init_disp.c | 62 | ||||
-rw-r--r-- | usr.bin/talk/invite.c | 5 | ||||
-rw-r--r-- | usr.bin/talk/io.c | 10 | ||||
-rw-r--r-- | usr.bin/talk/msgs.c | 5 | ||||
-rw-r--r-- | usr.bin/talk/talk.h | 6 |
6 files changed, 78 insertions, 16 deletions
diff --git a/usr.bin/talk/get_names.c b/usr.bin/talk/get_names.c index bce79d964d4..b1720eb95f0 100644 --- a/usr.bin/talk/get_names.c +++ b/usr.bin/talk/get_names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: get_names.c,v 1.10 2002/06/20 19:25:55 millert Exp $ */ +/* $OpenBSD: get_names.c,v 1.11 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: get_names.c,v 1.4 1994/12/09 02:14:16 jtc Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)get_names.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: get_names.c,v 1.10 2002/06/20 19:25:55 millert Exp $"; +static char rcsid[] = "$OpenBSD: get_names.c,v 1.11 2002/06/21 06:16:44 millert Exp $"; #endif /* not lint */ #include "talk.h" @@ -82,7 +82,7 @@ get_names(argc, argv) " talk [-Hs] user@hostname [ttyname]\n"); exit(1); } - if (!isatty(0)) + if (!isatty(STDIN_FILENO)) errx(1, "standard input must be a tty, not a pipe or a file"); if ((my_name = getlogin()) == NULL) { diff --git a/usr.bin/talk/init_disp.c b/usr.bin/talk/init_disp.c index 5374d4c242a..0d31ba76e86 100644 --- a/usr.bin/talk/init_disp.c +++ b/usr.bin/talk/init_disp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_disp.c,v 1.14 2002/06/20 19:25:55 millert Exp $ */ +/* $OpenBSD: init_disp.c,v 1.15 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; #endif -static char rcsid[] = "$OpenBSD: init_disp.c,v 1.14 2002/06/20 19:25:55 millert Exp $"; +static char rcsid[] = "$OpenBSD: init_disp.c,v 1.15 2002/06/21 06:16:44 millert Exp $"; #endif /* not lint */ /* @@ -50,7 +50,6 @@ static char rcsid[] = "$OpenBSD: init_disp.c,v 1.14 2002/06/20 19:25:55 millert #include <sys/ioctl.h> #include <sys/ioctl_compat.h> #include <err.h> -#include <signal.h> #include <termios.h> #include <unistd.h> @@ -75,6 +74,7 @@ init_display() cbreak(); signal(SIGINT, sig_sent); signal(SIGPIPE, sig_sent); + signal(SIGWINCH, sig_winch); /* curses takes care of ^Z */ my_win.x_nlines = LINES / 2; my_win.x_ncols = COLS; @@ -112,7 +112,7 @@ set_edit_chars() int cc; struct termios tty; - tcgetattr(0, &tty); + tcgetattr(STDIN_FILENO, &tty); buf[0] = my_win.cerase = (tty.c_cc[VERASE] == (u_char)_POSIX_VDISABLE) ? CERASE : tty.c_cc[VERASE]; buf[1] = my_win.kill = (tty.c_cc[VKILL] == (u_char)_POSIX_VDISABLE) @@ -138,6 +138,14 @@ sig_sent(dummy) quit("Connection closing. Exiting", 0); } +void +sig_winch(dummy) + int dummy; +{ + + gotwinch = 1; +} + /* * All done talking...hang up the phone and reset terminal thingy's */ @@ -163,3 +171,49 @@ quit(warning, do_perror) } exit(0); } + +/* + * If we get SIGWINCH, recompute both window sizes and refresh things. + */ +void +resize_display() +{ + struct winsize ws; + + if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) < 0 || + (ws.ws_row == LINES && ws.ws_col == COLS)) + return; + + /* Update curses' internal state with new window size. */ + resizeterm(ws.ws_row, ws.ws_col); + + /* + * Resize each window but wait to refresh the screen until + * everything has been drawn so the cursor is in the right spot. + */ + my_win.x_nlines = LINES / 2; + my_win.x_ncols = COLS; + wresize(my_win.x_win, my_win.x_nlines, my_win.x_ncols); + mvwin(my_win.x_win, 0, 0); + clearok(my_win.x_win, TRUE); + + his_win.x_nlines = LINES / 2 - 1; + his_win.x_ncols = COLS; + wresize(his_win.x_win, his_win.x_nlines, his_win.x_ncols); + mvwin(his_win.x_win, my_win.x_nlines + 1, 0); + clearok(his_win.x_win, TRUE); + + wresize(line_win, 1, COLS); + mvwin(line_win, my_win.x_nlines, 0); +#if defined(NCURSES_VERSION) || defined(whline) + whline(line_win, '-', COLS); +#else + wmove(line_win, my_win.x_nlines, 0); + box(line_win, '-', '-'); +#endif + + /* Now redraw the screen. */ + wrefresh(his_win.x_win); + wrefresh(line_win); + wrefresh(my_win.x_win); +} diff --git a/usr.bin/talk/invite.c b/usr.bin/talk/invite.c index 0dd3fdce747..74157c20026 100644 --- a/usr.bin/talk/invite.c +++ b/usr.bin/talk/invite.c @@ -1,4 +1,4 @@ -/* $OpenBSD: invite.c,v 1.7 1999/03/03 20:43:30 millert Exp $ */ +/* $OpenBSD: invite.c,v 1.8 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: invite.c,v 1.3 1994/12/09 02:14:18 jtc Exp $ */ /* @@ -38,13 +38,12 @@ #if 0 static char sccsid[] = "@(#)invite.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: invite.c,v 1.7 1999/03/03 20:43:30 millert Exp $"; +static char rcsid[] = "$OpenBSD: invite.c,v 1.8 2002/06/21 06:16:44 millert Exp $"; #endif /* not lint */ #include "talk.h" #include <arpa/inet.h> #include <sys/time.h> -#include <signal.h> #include <netdb.h> #include <errno.h> #include <setjmp.h> diff --git a/usr.bin/talk/io.c b/usr.bin/talk/io.c index 40a3d730799..6181f5104be 100644 --- a/usr.bin/talk/io.c +++ b/usr.bin/talk/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.10 2001/09/05 00:29:20 deraadt Exp $ */ +/* $OpenBSD: io.c,v 1.11 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: io.c,v 1.4 1994/12/09 02:14:20 jtc Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: io.c,v 1.10 2001/09/05 00:29:20 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: io.c,v 1.11 2002/06/21 06:16:44 millert Exp $"; #endif /* not lint */ /* @@ -56,6 +56,8 @@ static char rcsid[] = "$OpenBSD: io.c,v 1.10 2001/09/05 00:29:20 deraadt Exp $"; #define A_LONG_TIME 10000000 +volatile sig_atomic_t gotwinch = 0; + /* * The routine to do the actual talking */ @@ -94,6 +96,10 @@ talk() wait.tv_sec = A_LONG_TIME; wait.tv_usec = 0; nb = select(maxfd + 1, &read_set, 0, 0, &wait); + if (gotwinch) { + resize_display(); + gotwinch = 0; + } if (nb <= 0) { if (errno == EINTR) { read_set = read_template; diff --git a/usr.bin/talk/msgs.c b/usr.bin/talk/msgs.c index 75028b4afdf..48da0e8951f 100644 --- a/usr.bin/talk/msgs.c +++ b/usr.bin/talk/msgs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msgs.c,v 1.4 1998/08/18 04:02:23 millert Exp $ */ +/* $OpenBSD: msgs.c,v 1.5 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: msgs.c,v 1.3 1994/12/09 02:14:22 jtc Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)msgs.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: msgs.c,v 1.4 1998/08/18 04:02:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: msgs.c,v 1.5 2002/06/21 06:16:44 millert Exp $"; #endif /* not lint */ /* @@ -48,7 +48,6 @@ static char rcsid[] = "$OpenBSD: msgs.c,v 1.4 1998/08/18 04:02:23 millert Exp $" #include "talk.h" #include <sys/time.h> -#include <signal.h> #include <stdio.h> #define MSG_INTERVAL 4 diff --git a/usr.bin/talk/talk.h b/usr.bin/talk/talk.h index c3dd045e59c..cdb93b5f014 100644 --- a/usr.bin/talk/talk.h +++ b/usr.bin/talk/talk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: talk.h,v 1.8 2002/06/20 19:25:55 millert Exp $ */ +/* $OpenBSD: talk.h,v 1.9 2002/06/21 06:16:44 millert Exp $ */ /* $NetBSD: talk.h,v 1.3 1994/12/09 02:14:27 jtc Exp $ */ /* @@ -41,6 +41,7 @@ #include <netinet/in.h> #include <protocols/talkd.h> #include <curses.h> +#include <signal.h> #include <string.h> #include <err.h> @@ -50,6 +51,7 @@ extern int invitation_waiting; extern int high_print; extern bool smooth_scroll; +extern volatile sig_atomic_t gotwinch; extern char *current_state; extern int current_line; @@ -91,6 +93,8 @@ void re_invite(int); void send_delete(void); void set_edit_chars(void); void sig_sent(int); +void sig_winch(int); void start_msgs(void); void talk(void); void xscroll(xwin_t *, int); +void resize_display(void); |