diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-18 13:29:02 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-05-18 20:16:18 +0200 |
commit | c28192e6f9c16de3add78c5ecf8e732c241f945a (patch) | |
tree | 7c104332bbe454f4d764cc23005c0e41def42ca8 | |
parent | 028329850e4a4fc9171518566ba7947d9e435f83 (diff) | |
download | rneovim-c28192e6f9c16de3add78c5ecf8e732c241f945a.tar.gz rneovim-c28192e6f9c16de3add78c5ecf8e732c241f945a.tar.bz2 rneovim-c28192e6f9c16de3add78c5ecf8e732c241f945a.zip |
refactor: move more grid functions to grid.c. Clean up some variables
-rw-r--r-- | src/nvim/api/ui.c | 6 | ||||
-rw-r--r-- | src/nvim/globals.h | 4 | ||||
-rw-r--r-- | src/nvim/grid.c | 81 | ||||
-rw-r--r-- | src/nvim/os/input.c | 1 | ||||
-rw-r--r-- | src/nvim/screen.c | 102 | ||||
-rw-r--r-- | src/nvim/screen.h | 12 | ||||
-rw-r--r-- | src/nvim/window.c | 3 |
7 files changed, 105 insertions, 104 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b4d20ed975..52f76f4650 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -349,7 +349,11 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, I return; } - ui_grid_resize((handle_T)grid, (int)width, (int)height, err); + 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 diff --git a/src/nvim/globals.h b/src/nvim/globals.h index fecb1adee4..1819af7ee4 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -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. diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 5ed76c8998..fa5c193fe0 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -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; + } +} diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index c99d2869da..e4a91d1416 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -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" diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 15594ac1d3..8ca8c7985a 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -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. diff --git a/src/nvim/screen.h b/src/nvim/screen.h index 3afbaa5eb6..f3beeff8a9 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -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 diff --git a/src/nvim/window.c b/src/nvim/window.c index 51208e7178..7e7c639a15 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -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) |