summaryrefslogtreecommitdiffstats
path: root/usr.bin/talk
diff options
context:
space:
mode:
authorcognet <cognet@FreeBSD.org>2004-04-19 21:37:29 +0000
committercognet <cognet@FreeBSD.org>2004-04-19 21:37:29 +0000
commit7968cd95a05e7029bae9f50c976cced97ef9314a (patch)
tree84894fe75723e7e9104306214c3aeabe3bf2a336 /usr.bin/talk
parent281173de4aed6c4075d7e6e74d23aa99a1f88a1d (diff)
downloadFreeBSD-src-7968cd95a05e7029bae9f50c976cced97ef9314a.zip
FreeBSD-src-7968cd95a05e7029bae9f50c976cced97ef9314a.tar.gz
Handle window resizing better.
Submitted by: Cyril Nguyen Huu Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/talk')
-rw-r--r--usr.bin/talk/init_disp.c56
-rw-r--r--usr.bin/talk/io.c7
-rw-r--r--usr.bin/talk/talk.h2
3 files changed, 65 insertions, 0 deletions
diff --git a/usr.bin/talk/init_disp.c b/usr.bin/talk/init_disp.c
index 547164f..f391b76 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 6cfa7f1..00b2548 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 <sys/filio.h>
#include <errno.h>
+#include <signal.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
@@ -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 010e5f0..2a81a53 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);
OpenPOWER on IntegriCloud