Fix terminal resizing when new postion of last modeline overlap top row of last window.

This commit is contained in:
Renaud 2021-08-30 18:09:58 +08:00
parent f010d63a95
commit f96ace997f
4 changed files with 53 additions and 51 deletions

View File

@ -1327,6 +1327,12 @@ static void sizesignal( int signr) {
static void newscreensize( int h, int w) { static void newscreensize( int h, int w) {
chg_width = chg_height = 0 ; chg_width = chg_height = 0 ;
vtfree() ; vtfree() ;
if( h < 3)
h = 3 ;
if( w < 10)
w = 10 ;
vtalloc( h, w) ; vtalloc( h, w) ;
if( h <= term.t_mrow) if( h <= term.t_mrow)
newsize( TRUE, h) ; newsize( TRUE, h) ;

View File

@ -50,7 +50,7 @@ const name_bind names[] = {
{"!case-word-lower", lowerword, META | 'L'} , {"!case-word-lower", lowerword, META | 'L'} ,
{"!case-word-upper", upperword, META | 'U'} , {"!case-word-upper", upperword, META | 'U'} ,
{" change-file-name", filename, CTLX | 'N'} , {" change-file-name", filename, CTLX | 'N'} ,
{" change-screen-size", newsize, META | CTL_ | 'D'} , /* M^S */ {" change-screen-size", (fnp_t) newsize, META | CTL_ | 'D'} , /* M^S */
{" change-screen-width", (fnp_t) newwidth, META | CTL_ | 'T'} , {" change-screen-width", (fnp_t) newwidth, META | CTL_ | 'T'} ,
{" clear-and-redraw", (fnp_t) redraw, CTL_ | 'L'} , {" clear-and-redraw", (fnp_t) redraw, CTL_ | 'L'} ,
{" clear-message-line", (fnp_t) clrmes, 0} , {" clear-message-line", (fnp_t) clrmes, 0} ,

View File

@ -566,11 +566,8 @@ BINDABLE( restwnd) {
* int f; default flag * int f; default flag
* int n; numeric argument * int n; numeric argument
*/ */
BINDABLE( newsize) { BBINDABLE( newsize) {
window_p wp ; /* current window being examined */ window_p wp ; /* current window being examined */
window_p nextwp; /* next window to scan */
window_p lastwp; /* last window scanned */
int lastline; /* screen line of last line of current window */
/* if the command defaults, assume the largest */ /* if the command defaults, assume the largest */
if( f == FALSE) if( f == FALSE)
@ -581,32 +578,33 @@ BINDABLE( newsize) {
return mloutfail( "%%Screen size out of range") ; return mloutfail( "%%Screen size out of range") ;
if( term.t_nrow == n - 1) if( term.t_nrow == n - 1)
/* no change */
return TRUE ; return TRUE ;
else if( term.t_nrow < n - 1) { else if( term.t_nrow < n - 1) {
/* new size is bigger */
/* go to the last window */ /* go to the last window */
wp = wheadp; for( wp = wheadp ; wp->w_wndp != NULL ; wp = wp->w_wndp)
while (wp->w_wndp != NULL) ;
wp = wp->w_wndp;
/* and enlarge it as needed */ /* and enlarge it as needed */
wp->w_ntrows = n - wp->w_toprow - 2 ; wp->w_ntrows = n - wp->w_toprow - 2 ;
wp->w_flag |= WFHARD | WFMODE ; wp->w_flag |= WFHARD | WFMODE ;
} else { } else {
/* new size is smaller */
/* rebuild the window structure */ /* rebuild the window structure */
assert( wheadp->w_toprow == 0) ; /* proves coverity wrong */ assert( wheadp->w_toprow == 0) ; /* proves coverity wrong */
nextwp = wheadp; window_p lastwp = NULL ;
wp = NULL; for( window_p nextwp = wheadp ; nextwp != NULL ; ) {
lastwp = NULL;
while (nextwp != NULL) {
wp = nextwp ; wp = nextwp ;
nextwp = wp->w_wndp ; nextwp = wp->w_wndp ;
/* get rid of it if it is too low */ if( wp->w_toprow == n - 2) {
if (wp->w_toprow > n - 2) { lastwp->w_ntrows = n - lastwp->w_toprow - 2 ;
lastwp->w_flag |= WFHARD | WFMODE ;
}
/* get rid of it if it is too low */
if( wp->w_toprow >= n - 2) {
/* save the point/mark if needed */ /* save the point/mark if needed */
if( --wp->w_bufp->b_nwnd == 0) { if( --wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp ; wp->w_bufp->b_dotp = wp->w_dotp ;
@ -616,29 +614,27 @@ BINDABLE( newsize) {
} }
/* update curwp and lastwp if needed */ /* update curwp and lastwp if needed */
if (wp == curwp) if( wp == curwp) {
curwp = wheadp ; curwp = wheadp ;
curbp = curwp->w_bufp ; curbp = curwp->w_bufp ;
if (lastwp != NULL) }
lastwp->w_wndp = NULL;
/* free the structure */ /* free the structure */
free((char *) wp); free( wp) ;
wp = NULL; lastwp->w_wndp = NULL ;
} else { } else {
/* need to change this window size? */ /* need to change this window size? */
lastline = wp->w_toprow + wp->w_ntrows - 1; int lastline = wp->w_toprow + wp->w_ntrows - 1 ;
if( lastline >= n - 2) { if( lastline >= n - 2) {
wp->w_ntrows = wp->w_ntrows = n - wp->w_toprow - 2 ;
n - wp->w_toprow - 2; assert( wp->w_ntrows) ;
wp->w_flag |= WFHARD | WFMODE ; wp->w_flag |= WFHARD | WFMODE ;
} }
}
lastwp = wp ; lastwp = wp ;
} }
} }
}
/* screen is garbage */ /* screen is garbage */
term.t_nrow = n - 1 ; term.t_nrow = n - 1 ;

View File

@ -55,7 +55,7 @@ extern window_p wheadp ; /* Head of list of windows */
BINDABLE( enlargewind) ; BINDABLE( enlargewind) ;
BINDABLE( mvdnwind) ; BINDABLE( mvdnwind) ;
BINDABLE( mvupwind) ; BINDABLE( mvupwind) ;
BINDABLE( newsize) ; BBINDABLE( newsize) ;
BBINDABLE( newwidth) ; BBINDABLE( newwidth) ;
BINDABLE( nextwind) ; BINDABLE( nextwind) ;
BINDABLE( onlywind) ; BINDABLE( onlywind) ;