=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/talk/init_disp.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- src/usr.bin/talk/init_disp.c 2002/06/20 19:25:55 1.14 +++ src/usr.bin/talk/init_disp.c 2002/06/21 06:16:44 1.15 @@ -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 @@ #include #include #include -#include #include #include @@ -75,6 +74,7 @@ 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 @@ 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 @@ 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 */ @@ -162,4 +170,50 @@ warnx("%s", warning); } 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); }