From ec8ffccbdcd830918d91c765f507fa2034cde2ac Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 19 Apr 2004 21:37:29 +0000 Subject: Handle window resizing better. Submitted by: Cyril Nguyen Huu Obtained from: OpenBSD --- usr.bin/talk/init_disp.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ usr.bin/talk/io.c | 7 ++++++ usr.bin/talk/talk.h | 2 ++ 3 files changed, 65 insertions(+) (limited to 'usr.bin') diff --git a/usr.bin/talk/init_disp.c b/usr.bin/talk/init_disp.c index 547164f6a648..f391b76a5e0b 100644 --- a/usr.bin/talk/init_disp.c +++ b/usr.bin/talk/init_disp.c @@ -54,6 +54,8 @@ static const char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; #include "talk.h" +extern volatile sig_atomic_t gotwinch; + /* * Make sure the callee can write to the screen */ @@ -92,6 +94,7 @@ init_display() crmode(); 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; @@ -165,6 +168,13 @@ sig_sent(signo) quit(); } +void +sig_winch(int dummy) +{ + + gotwinch = 1; +} + /* * All done talking...hang up the phone and reset terminal thingy's */ @@ -182,3 +192,49 @@ quit() send_delete(); exit(0); } + +/* + * If we get SIGWINCH, recompute both window sizes and refresh things. + */ +void +resize_display(void) +{ + 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/io.c b/usr.bin/talk/io.c index 6cfa7f16a4a7..00b2548f29c1 100644 --- a/usr.bin/talk/io.c +++ b/usr.bin/talk/io.c @@ -48,6 +48,7 @@ static const char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #include #include +#include #include #include #include @@ -58,6 +59,8 @@ static const char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #define A_LONG_TIME 10000000 +volatile sig_atomic_t gotwinch = 0; + /* * The routine to do the actual talking */ @@ -106,6 +109,10 @@ talk() wait.tv_sec = A_LONG_TIME; wait.tv_usec = 0; nb = select(32, &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/talk.h b/usr.bin/talk/talk.h index 010e5f0e854f..2a81a53bca9b 100644 --- a/usr.bin/talk/talk.h +++ b/usr.bin/talk/talk.h @@ -91,5 +91,7 @@ extern void re_invite(int); extern void send_delete(void); extern void set_edit_chars(void); extern void sig_sent(int); +extern void sig_winch(int); extern void start_msgs(void); extern void talk(void); +extern void resize_display(void); -- cgit v1.2.3