mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-11 17:04:19 +01:00
Handle window resizing better.
Submitted by: Cyril Nguyen Huu Obtained from: OpenBSD
This commit is contained in:
parent
45804124ae
commit
ec8ffccbdc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=128445
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user