mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor: move more grid functions to grid.c. Clean up some variables
This commit is contained in:
parent
028329850e
commit
c28192e6f9
@ -349,8 +349,12 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, I
|
||||
return;
|
||||
}
|
||||
|
||||
if (grid == DEFAULT_GRID_HANDLE) {
|
||||
nvim_ui_try_resize(channel_id, width, height, err);
|
||||
} else {
|
||||
ui_grid_resize((handle_T)grid, (int)width, (int)height, err);
|
||||
}
|
||||
}
|
||||
|
||||
/// Tells Nvim the number of elements displaying in the popumenu, to decide
|
||||
/// <PageUp> and <PageDown> movement.
|
||||
|
@ -421,10 +421,6 @@ EXTERN vimmenu_T *root_menu INIT(= NULL);
|
||||
// overruling of menus that the user already defined.
|
||||
EXTERN int sys_menu INIT(= false);
|
||||
|
||||
// While redrawing the screen this flag is set. It means the screen size
|
||||
// ('lines' and 'rows') must not be changed.
|
||||
EXTERN int updating_screen INIT(= 0);
|
||||
|
||||
// All windows are linked in a list. firstwin points to the first entry,
|
||||
// lastwin to the last entry (can be the same as firstwin) and curwin to the
|
||||
// currently active window.
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "nvim/highlight.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/screen.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "grid.c.generated.h"
|
||||
@ -705,3 +706,83 @@ void grid_free_all_mem(void)
|
||||
xfree(linebuf_char);
|
||||
xfree(linebuf_attr);
|
||||
}
|
||||
|
||||
/// (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;
|
||||
ScreenGrid *grid_allocated = &wp->w_grid_alloc;
|
||||
|
||||
int rows = wp->w_height_inner;
|
||||
int cols = wp->w_width_inner;
|
||||
int total_rows = wp->w_height_outer;
|
||||
int total_cols = wp->w_width_outer;
|
||||
|
||||
bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating;
|
||||
bool has_allocation = (grid_allocated->chars != NULL);
|
||||
|
||||
if (grid->rows != rows) {
|
||||
wp->w_lines_valid = 0;
|
||||
xfree(wp->w_lines);
|
||||
wp->w_lines = xcalloc((size_t)rows + 1, sizeof(wline_T));
|
||||
}
|
||||
|
||||
int was_resized = false;
|
||||
if (want_allocation && (!has_allocation
|
||||
|| grid_allocated->rows != total_rows
|
||||
|| grid_allocated->cols != total_cols)) {
|
||||
grid_alloc(grid_allocated, total_rows, total_cols,
|
||||
wp->w_grid_alloc.valid, false);
|
||||
grid_allocated->valid = true;
|
||||
if (wp->w_floating && wp->w_float_config.border) {
|
||||
wp->w_redr_border = true;
|
||||
}
|
||||
was_resized = true;
|
||||
} else if (!want_allocation && has_allocation) {
|
||||
// Single grid mode, all rendering will be redirected to default_grid.
|
||||
// Only keep track of the size and offset of the window.
|
||||
grid_free(grid_allocated);
|
||||
grid_allocated->valid = false;
|
||||
was_resized = true;
|
||||
} else if (want_allocation && has_allocation && !wp->w_grid_alloc.valid) {
|
||||
grid_invalidate(grid_allocated);
|
||||
grid_allocated->valid = true;
|
||||
}
|
||||
|
||||
grid->rows = rows;
|
||||
grid->cols = cols;
|
||||
|
||||
if (want_allocation) {
|
||||
grid->target = grid_allocated;
|
||||
grid->row_offset = wp->w_winrow_off;
|
||||
grid->col_offset = wp->w_wincol_off;
|
||||
} else {
|
||||
grid->target = &default_grid;
|
||||
grid->row_offset = wp->w_winrow + wp->w_winrow_off;
|
||||
grid->col_offset = wp->w_wincol + wp->w_wincol_off;
|
||||
}
|
||||
|
||||
// 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)
|
||||
if ((resizing_screen || was_resized) && want_allocation) {
|
||||
ui_call_grid_resize(grid_allocated->handle,
|
||||
grid_allocated->cols, grid_allocated->rows);
|
||||
}
|
||||
}
|
||||
|
||||
/// assign a handle to the grid. The grid need not be allocated.
|
||||
void grid_assign_handle(ScreenGrid *grid)
|
||||
{
|
||||
static int last_grid_handle = DEFAULT_GRID_HANDLE;
|
||||
|
||||
// only assign a grid handle if not already
|
||||
if (grid->handle == 0) {
|
||||
grid->handle = ++last_grid_handle;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/msgpack_rpc/channel.h"
|
||||
#include "nvim/os/input.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/vim.h"
|
||||
|
@ -132,10 +132,6 @@
|
||||
|
||||
static match_T search_hl; // used for 'hlsearch' highlight matching
|
||||
|
||||
StlClickDefinition *tab_page_click_defs = NULL;
|
||||
|
||||
long tab_page_click_defs_size = 0;
|
||||
|
||||
// for line_putchar. Contains the state that needs to be remembered from
|
||||
// putting one character to the next.
|
||||
typedef struct {
|
||||
@ -607,8 +603,6 @@ int update_screen(int type)
|
||||
pum_redraw();
|
||||
}
|
||||
|
||||
send_grid_resize = false;
|
||||
|
||||
/* Reset b_mod_set flags. Going through all windows is probably faster
|
||||
* than going through all buffers (there could be many buffers). */
|
||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||
@ -5571,88 +5565,6 @@ void check_for_delay(bool check_msg_scroll)
|
||||
}
|
||||
}
|
||||
|
||||
/// (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;
|
||||
ScreenGrid *grid_allocated = &wp->w_grid_alloc;
|
||||
|
||||
int rows = wp->w_height_inner;
|
||||
int cols = wp->w_width_inner;
|
||||
int total_rows = wp->w_height_outer;
|
||||
int total_cols = wp->w_width_outer;
|
||||
|
||||
bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating;
|
||||
bool has_allocation = (grid_allocated->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 (want_allocation && (!has_allocation
|
||||
|| grid_allocated->rows != total_rows
|
||||
|| grid_allocated->cols != total_cols)) {
|
||||
grid_alloc(grid_allocated, total_rows, total_cols,
|
||||
wp->w_grid_alloc.valid, false);
|
||||
grid_allocated->valid = true;
|
||||
if (wp->w_floating && wp->w_float_config.border) {
|
||||
wp->w_redr_border = true;
|
||||
}
|
||||
was_resized = true;
|
||||
} else if (!want_allocation && has_allocation) {
|
||||
// Single grid mode, all rendering will be redirected to default_grid.
|
||||
// Only keep track of the size and offset of the window.
|
||||
grid_free(grid_allocated);
|
||||
grid_allocated->valid = false;
|
||||
was_resized = true;
|
||||
} else if (want_allocation && has_allocation && !wp->w_grid_alloc.valid) {
|
||||
grid_invalidate(grid_allocated);
|
||||
grid_allocated->valid = true;
|
||||
}
|
||||
|
||||
grid->rows = rows;
|
||||
grid->cols = cols;
|
||||
|
||||
wp->w_winrow_off = wp->w_border_adj[0] + wp->w_winbar_height;
|
||||
wp->w_wincol_off = wp->w_border_adj[3];
|
||||
|
||||
if (want_allocation) {
|
||||
grid->target = grid_allocated;
|
||||
grid->row_offset = wp->w_winrow_off;
|
||||
grid->col_offset = wp->w_wincol_off;
|
||||
} else {
|
||||
grid->target = &default_grid;
|
||||
grid->row_offset = wp->w_winrow + wp->w_winrow_off;
|
||||
grid->col_offset = wp->w_wincol + wp->w_wincol_off;
|
||||
}
|
||||
|
||||
// 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)
|
||||
if ((send_grid_resize || was_resized) && want_allocation) {
|
||||
ui_call_grid_resize(grid_allocated->handle,
|
||||
grid_allocated->cols, grid_allocated->rows);
|
||||
}
|
||||
}
|
||||
|
||||
/// assign a handle to the grid. The grid need not be allocated.
|
||||
void grid_assign_handle(ScreenGrid *grid)
|
||||
{
|
||||
static int last_grid_handle = DEFAULT_GRID_HANDLE;
|
||||
|
||||
// only assign a grid handle if not already
|
||||
if (grid->handle == 0) {
|
||||
grid->handle = ++last_grid_handle;
|
||||
}
|
||||
}
|
||||
|
||||
/// Resize the screen to Rows and Columns.
|
||||
///
|
||||
@ -6824,11 +6736,9 @@ static void margin_columns_win(win_T *wp, int *left_col, int *right_col)
|
||||
/// Set dimensions of the Nvim application "shell".
|
||||
void screen_resize(int width, int height)
|
||||
{
|
||||
static bool recursive = false;
|
||||
|
||||
// Avoid recursiveness, can happen when setting the window size causes
|
||||
// another window-changed signal.
|
||||
if (updating_screen || recursive) {
|
||||
if (updating_screen || resizing_screen) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -6850,7 +6760,7 @@ void screen_resize(int width, int height)
|
||||
return;
|
||||
}
|
||||
|
||||
recursive = true;
|
||||
resizing_screen = true;
|
||||
|
||||
Rows = height;
|
||||
Columns = width;
|
||||
@ -6867,9 +6777,9 @@ void screen_resize(int width, int height)
|
||||
|
||||
send_grid_resize = true;
|
||||
|
||||
/* The window layout used to be adjusted here, but it now happens in
|
||||
* screenalloc() (also invoked from screenclear()). That is because the
|
||||
* "recursive" check above may skip this, but not screenalloc(). */
|
||||
/// The window layout used to be adjusted here, but it now happens in
|
||||
/// screenalloc() (also invoked from screenclear()). That is because the
|
||||
/// recursize "resizing_screen" check above may skip this, but not screenalloc().
|
||||
|
||||
if (State != MODE_ASKMORE && State != MODE_EXTERNCMD && State != MODE_CONFIRM) {
|
||||
screenclear();
|
||||
@ -6928,7 +6838,7 @@ void screen_resize(int width, int height)
|
||||
}
|
||||
ui_flush();
|
||||
}
|
||||
recursive = false;
|
||||
resizing_screen = false;
|
||||
}
|
||||
|
||||
/// Check if the new Nvim application "shell" dimensions are valid.
|
||||
|
@ -49,14 +49,22 @@ typedef struct {
|
||||
} StlClickRecord;
|
||||
|
||||
/// Array defining what should be done when tabline is clicked
|
||||
extern StlClickDefinition *tab_page_click_defs;
|
||||
EXTERN StlClickDefinition *tab_page_click_defs INIT(= NULL);
|
||||
|
||||
/// Size of the tab_page_click_defs array
|
||||
extern long tab_page_click_defs_size;
|
||||
EXTERN long tab_page_click_defs_size INIT(= 0);
|
||||
|
||||
#define W_ENDCOL(wp) ((wp)->w_wincol + (wp)->w_width)
|
||||
#define W_ENDROW(wp) ((wp)->w_winrow + (wp)->w_height)
|
||||
|
||||
// While redrawing the screen this flag is set. It means the screen size
|
||||
// ('lines' and 'rows') must not be changed.
|
||||
EXTERN bool updating_screen INIT(= 0);
|
||||
|
||||
// While resizing the screen this flag is set.
|
||||
EXTERN bool resizing_screen INIT(= 0);
|
||||
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "screen.h.generated.h"
|
||||
#endif
|
||||
|
@ -6263,7 +6263,6 @@ void win_set_inner_size(win_T *wp)
|
||||
}
|
||||
wp->w_skipcol = 0;
|
||||
wp->w_height_inner = height;
|
||||
wp->w_winrow_off = wp->w_border_adj[0] + wp->w_winbar_height;
|
||||
|
||||
// There is no point in adjusting the scroll position when exiting. Some
|
||||
// values might be invalid.
|
||||
@ -6291,6 +6290,8 @@ void win_set_inner_size(win_T *wp)
|
||||
|
||||
wp->w_height_outer = (wp->w_height_inner + win_extra_height(wp));
|
||||
wp->w_width_outer = (wp->w_width_inner + win_extra_width(wp));
|
||||
wp->w_winrow_off = wp->w_border_adj[0] + wp->w_winbar_height;
|
||||
wp->w_wincol_off = wp->w_border_adj[3];
|
||||
}
|
||||
|
||||
static int win_extra_height(win_T *wp)
|
||||
|
Loading…
Reference in New Issue
Block a user