Fix resizing bug where the values of LINES and/or COLS changed while we

were resizing windows, leading to inconsistencies between the sizes of
stdscr and curscr.

Should fix the curses part of PR lib/36702.
This commit is contained in:
jdc 2007-08-27 19:54:29 +00:00
parent b504fee486
commit 34bea28655
2 changed files with 31 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: resize.c,v 1.14 2007/05/28 15:01:57 blymn Exp $ */
/* $NetBSD: resize.c,v 1.15 2007/08/27 19:54:29 jdc Exp $ */
/*
* Copyright (c) 2001
@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)resize.c blymn 2001/08/26";
#else
__RCSID("$NetBSD: resize.c,v 1.14 2007/05/28 15:01:57 blymn Exp $");
__RCSID("$NetBSD: resize.c,v 1.15 2007/08/27 19:54:29 jdc Exp $");
#endif
#endif /* not lint */
@ -64,6 +64,10 @@ wresize(WINDOW *win, int req_nlines, int req_ncols)
if (win == NULL)
return ERR;
#ifdef DEBUG
__CTRACE(__CTRACE_WINDOW, "wresize: (%p, %d, %d)\n",
win, nlines, ncols);
#endif
nlines = req_nlines;
ncols = req_ncols;
if (win->orig == NULL) {
@ -94,12 +98,20 @@ wresize(WINDOW *win, int req_nlines, int req_ncols)
win->reqy = req_nlines;
win->reqx = req_ncols;
/* If someone resizes curscr, we must also resize __virtscr */
if (win == curscr) {
if ((__resizewin(__virtscr, nlines, ncols)) == ERR)
return ERR;
__virtscr->reqy = req_nlines;
__virtscr->reqx = req_ncols;
}
return OK;
}
/*
* resizeterm --
* Resize the terminal window, resizing the dependent windows.
* Resize the terminal window, resizing the dependent windows.
*/
int
resizeterm(int nlines, int ncols)
@ -162,7 +174,7 @@ __resizewin(WINDOW *win, int nlines, int ncols)
{
__LINE *lp, *olp, **newlines, *newlspace;
__LDATA *sp;
__LDATA *newwspace;
__LDATA *newwspace;
int i, j;
int y, x;
WINDOW *swin;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tstp.c,v 1.35 2007/01/21 13:25:36 jdc Exp $ */
/* $NetBSD: tstp.c,v 1.36 2007/08/27 19:54:29 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: tstp.c,v 1.35 2007/01/21 13:25:36 jdc Exp $");
__RCSID("$NetBSD: tstp.c,v 1.36 2007/08/27 19:54:29 jdc Exp $");
#endif
#endif /* not lint */
@ -253,6 +253,7 @@ void
__restartwin(void)
{
struct winsize win;
int lines, cols;
#ifdef DEBUG
__CTRACE(__CTRACE_MISC, "__restartwin\n");
@ -268,7 +269,8 @@ __restartwin(void)
* Check to see if the window size has changed.
* If the application didn't update LINES and COLS,
* set the * resized flag to tell getch() to push KEY_RESIZE.
* Update curscr, stdscr and __virtscr to match the new size.
* Update curscr (which also updates __virtscr) and stdscr
* to match the new size.
*/
if (ioctl(fileno(_cursesi_screen->outfd), TIOCGWINSZ, &win) != -1 &&
win.ws_row != 0 && win.ws_col != 0) {
@ -281,12 +283,16 @@ __restartwin(void)
_cursesi_screen->resized = 1;
}
}
if (curscr->maxy != LINES || curscr->maxx != COLS)
wresize(curscr, LINES, COLS);
if (stdscr->maxy != LINES || stdscr->maxx != COLS)
wresize(stdscr, LINES, COLS);
if (__virtscr->maxy != LINES || __virtscr->maxx != COLS)
wresize(__virtscr, LINES, COLS);
/*
* We need to make local copies of LINES and COLS, otherwise we
* could lose if they are changed between wresize() calls.
*/
lines = LINES;
cols = COLS;
if (curscr->maxy != lines || curscr->maxx != cols)
wresize(curscr, lines, cols);
if (stdscr->maxy != lines || stdscr->maxx != cols)
wresize(stdscr, lines, cols);
/* save the new "default" terminal state */
(void) tcgetattr(fileno(_cursesi_screen->infd),