summaryrefslogtreecommitdiff
path: root/usr.bin/talk/init_disp.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-06-21 06:16:45 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-06-21 06:16:45 +0000
commit3c8087a0f912d3dae9d63fd6cfb4bb6c97cf7909 (patch)
tree19bcb197df9a9b3ec94788e5a3704d95e01b3643 /usr.bin/talk/init_disp.c
parent8d6e2fee0f96497dc1ced5c688a9a4d51995e2a4 (diff)
o Resize nicely when we receive SIGWINCH
o Also change some 0-2 to *_FILENO
Diffstat (limited to 'usr.bin/talk/init_disp.c')
-rw-r--r--usr.bin/talk/init_disp.c62
1 files changed, 58 insertions, 4 deletions
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);
+}