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) {
chg_width = chg_height = 0 ;
vtfree() ;
if( h < 3)
h = 3 ;
if( w < 10)
w = 10 ;
vtalloc( h, w) ;
if( h <= term.t_mrow)
newsize( TRUE, h) ;

View File

@ -50,7 +50,7 @@ const name_bind names[] = {
{"!case-word-lower", lowerword, META | 'L'} ,
{"!case-word-upper", upperword, META | 'U'} ,
{" 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'} ,
{" clear-and-redraw", (fnp_t) redraw, CTL_ | 'L'} ,
{" clear-message-line", (fnp_t) clrmes, 0} ,

View File

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

View File

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