ts.ts_lines = rows; ts.ts_cols = cols; code = ioctl(screen->respond, TIOCSSIZE, &ts); TRACE(("return %d from TIOCSSIZE %dx%d\n", code, rows, cols)); #ifdef SIGWINCH
TTYSIZE_ROWS(ts) = rows; TTYSIZE_COLS(ts) = cols; #ifdef USE_STRUCT_WINSIZE ts.ws_xpixel = width; ts.ws_ypixel = height; #endif code = SET_TTYSIZE(screen->respond, ts); TRACE(("return %d from SET_TTYSIZE %dx%d\n", code, rows, cols));  #if defined(SIGWINCH) && defined(USE_STRUCT_TTYSIZE)
ScreenResize(TScreen * screen,	     int width,	     int height,	     unsigned *flags){    int code;    int rows, cols;    int border = 2 * screen->border;    int move_down_by;#if defined(TIOCSSIZE) && (defined(sun) && !defined(SVR4))    struct ttysize ts;#elif defined(TIOCSWINSZ)    struct winsize ws;#endif /* sun vs TIOCSWINSZ */    Window tw = VWindow(screen);    TRACE(("ScreenResize %dx%d\n", height, width));    /* clear the right and bottom internal border because of NorthWest       gravity might have left junk on the right and bottom edges */    if (width >= FullWidth(screen)) {	XClearArea(screen->display, tw,		   FullWidth(screen), 0,	/* right edge */		   0, height,	/* from top to bottom */		   False);    }    if (height >= FullHeight(screen)) {	XClearArea(screen->display, tw,		   0, FullHeight(screen),	/* bottom */		   width, 0,	/* all across the bottom */		   False);    }    /* round so that it is unlikely the screen will change size on  */    /* small mouse movements.                                       */    rows = (height + FontHeight(screen) / 2 - border) /	FontHeight(screen);    cols = (width + FontWidth(screen) / 2 - border - ScrollbarWidth(screen)) /	FontWidth(screen);    if (rows < 1)	rows = 1;    if (cols < 1)	cols = 1;    /* update buffers if the screen has changed size */    if (screen->max_row != rows - 1 || screen->max_col != cols - 1) {	int savelines = screen->scrollWidget	? screen->savelines : 0;	int delta_rows = rows - (screen->max_row + 1);	TRACE(("...ScreenResize chars %dx%d\n", rows, cols));	if (screen->cursor_state)	    HideCursor();	if (screen->alternate	    && term->misc.resizeGravity == SouthWestGravity)	    /* swap buffer pointers back to make all this hair work */	    SwitchBufPtrs(screen);	if (screen->altbuf)	    (void) Reallocate(&screen->altbuf,			      &screen->abuf_address,			      rows,			      cols,			      screen->max_row + 1,			      screen->max_col + 1);	move_down_by = Reallocate(&screen->allbuf,				  &screen->sbuf_address,				  rows + savelines, cols,				  screen->max_row + 1 + savelines,				  screen->max_col + 1);	screen->visbuf = &screen->allbuf[MAX_PTRS * savelines];	screen->max_row += delta_rows;	screen->max_col = cols - 1;	if (term->misc.resizeGravity == SouthWestGravity) {	    screen->savedlines -= move_down_by;	    if (screen->savedlines < 0)		screen->savedlines = 0;	    if (screen->savedlines > screen->savelines)		screen->savedlines = screen->savelines;	    if (screen->topline < -screen->savedlines)		screen->topline = -screen->savedlines;	    screen->cur_row += move_down_by;	    screen->cursor_row += move_down_by;	    ScrollSelection(screen, move_down_by);	    if (screen->alternate)		SwitchBufPtrs(screen);	/* put the pointers back */	}	/* adjust scrolling region */	screen->top_marg = 0;	screen->bot_marg = screen->max_row;	*flags &= ~ORIGIN;	if (screen->cur_row > screen->max_row)	    screen->cur_row = screen->max_row;	if (screen->cur_col > screen->max_col)	    screen->cur_col = screen->max_col;	screen->fullVwin.height = height - border;	screen->fullVwin.width = width - border - screen->fullVwin.sb_info.width;    } else if (FullHeight(screen) == height && FullWidth(screen) == width)	return (0);		/* nothing has changed at all */    screen->fullVwin.fullheight = height;    screen->fullVwin.fullwidth = width;    if (screen->scrollWidget)	ResizeScrollBar(screen);    ResizeSelection(screen, rows, cols);#ifndef NO_ACTIVE_ICON    if (screen->iconVwin.window) {	XWindowChanges changes;	screen->iconVwin.width =	    (screen->max_col + 1) * screen->iconVwin.f_width;	screen->iconVwin.height =	    (screen->max_row + 1) * screen->iconVwin.f_height;	changes.width = screen->iconVwin.fullwidth =	    screen->iconVwin.width + 2 * screen->border;	changes.height = screen->iconVwin.fullheight =	    screen->iconVwin.height + 2 * screen->border;	XConfigureWindow(XtDisplay(term), screen->iconVwin.window,			 CWWidth | CWHeight, &changes);    }#endif /* NO_ACTIVE_ICON */#if defined(TIOCSSIZE) && (defined(sun) && !defined(SVR4))    /* Set tty's idea of window size */    ts.ts_lines = rows;    ts.ts_cols = cols;    code = ioctl(screen->respond, TIOCSSIZE, &ts);    TRACE(("return %d from TIOCSSIZE %dx%d\n", code, rows, cols));#ifdef SIGWINCH    if (screen->pid > 1) {	int pgrp;	if (ioctl(screen->respond, TIOCGPGRP, &pgrp) != -1)	    kill_process_group(pgrp, SIGWINCH);    }#endif /* SIGWINCH */#elif defined(TIOCSWINSZ)    /* Set tty's idea of window size */    ws.ws_row = rows;    ws.ws_col = cols;    ws.ws_xpixel = width;    ws.ws_ypixel = height;    code = ioctl(screen->respond, TIOCSWINSZ, (char *) &ws);    TRACE(("return %d from TIOCSWINSZ %dx%d\n", code, rows, cols));#ifdef notdef			/* change to SIGWINCH if this doesn't work for you */    if (screen->pid > 1) {	int pgrp;	if (ioctl(screen->respond, TIOCGPGRP, &pgrp) != -1)	    kill_process_group(pgrp, SIGWINCH);    }#endif /* SIGWINCH */#else    TRACE(("ScreenResize cannot do anything to pty\n"));#endif /* sun vs TIOCSWINSZ */    return (0);}