src/nvim/screen.c
/// (Re)allocates a window grid if size changed while in ext_multigrid mode.
/// Updates size, offsets and handle for the grid regardless.
///
/// If "doclear" is true, don't try to copy from the old grid rather clear the
/// resized grid.
(Re)allocates a window grid if size changed while in ext_multigrid mode.
Updates size, offsets and handle for the grid regardless.

If "doclear" is true, don't try to copy from the old grid rather clear the
resized grid.
( Re ) allocates a window grid if size changed while in ext_multigrid mode . Updates size offsets and handle for the grid regardless . If " doclear " is true don ' t try to copy from the old grid rather clear the resized grid .
void win_grid_alloc(win_T *wp)
{
  ScreenGrid *grid = &wp->w_grid;
  int rows = wp->w_height_inner;
  int cols = wp->w_width_inner;
  bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating;
  bool has_allocation = (grid->chars != NULL);
  if (grid->Rows != rows) {
    wp->w_lines_valid = 0;
    xfree(wp->w_lines);
    wp->w_lines = xcalloc(rows+1, sizeof(wline_T));
  }
  int was_resized = false;
  if ((has_allocation != want_allocation)
      || grid->Rows != rows
      || grid->Columns != cols) {
    if (want_allocation) {
      grid_alloc(grid, rows, cols, wp->w_grid.valid, wp->w_grid.valid);
      grid->valid = true;
    } else {
      grid_free(grid);
      grid->Rows = rows;
      grid->Columns = cols;
      grid->valid = false;
    }
    was_resized = true;
  } else if (want_allocation && has_allocation && !wp->w_grid.valid) {
    grid_invalidate(grid);
    grid->valid = true;
  }
  grid->row_offset = wp->w_winrow;
  grid->col_offset = wp->w_wincol;
  if ((send_grid_resize || was_resized) && want_allocation) {
    ui_call_grid_resize(grid->handle, grid->Columns, grid->Rows);
  }
}
void win_grid_alloc ( win_T * wp ) { ScreenGrid * grid = & wp -> w_grid ; int rows = wp -> w_height_inner ; int cols = wp -> w_width_inner ; bool want_allocation = ui_has ( kUIMultigrid ) || wp -> w_floating ; bool has_allocation = ( grid -> chars != NULL ) ; if ( grid -> Rows != rows ) { wp -> w_lines_valid = 0 ; xfree ( wp -> w_lines ) ; wp -> w_lines = xcalloc ( rows + 1 , sizeof ( wline_T ) ) ; } int was_resized = false ; if ( ( has_allocation != want_allocation ) || grid -> Rows != rows || grid -> Columns != cols ) { if ( want_allocation ) { grid_alloc ( grid , rows , cols , wp -> w_grid . valid , wp -> w_grid . valid ) ; grid -> valid = true ; } else { grid_free ( grid ) ; grid -> Rows = rows ; grid -> Columns = cols ; grid -> valid = false ; } was_resized = true ; } else if ( want_allocation && has_allocation && ! wp -> w_grid . valid ) { grid_invalidate ( grid ) ; grid -> valid = true ; } grid -> row_offset = wp -> w_winrow ; grid -> col_offset = wp -> w_wincol ; if ( ( send_grid_resize || was_resized ) && want_allocation ) { ui_call_grid_resize ( grid -> handle , grid -> Columns , grid -> Rows ) ; } }
(Re)allocates a window grid if size changed while in ext_multigrid mode.
( Re ) allocates a window grid if size changed while in ext_multigrid mode .
// Single grid mode, all rendering will be redirected to default_grid. // Only keep track of the size and offset of the window. // send grid resize event if: // - a grid was just resized // - screen_resize was called and all grid sizes must be sent // - the UI wants multigrid event (necessary)