diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2018-12-23 14:35:23 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2018-12-31 16:24:07 +0100 |
commit | 1cec5542a83baf04848e37475b9b0b7f50e47284 (patch) | |
tree | b3ce77a147675ea07f95d9a237ca591fd4e2a0ad /src | |
parent | 820c81e638768994f4e51fdb87eadf31664048ff (diff) | |
download | rneovim-1cec5542a83baf04848e37475b9b0b7f50e47284.tar.gz rneovim-1cec5542a83baf04848e37475b9b0b7f50e47284.tar.bz2 rneovim-1cec5542a83baf04848e37475b9b0b7f50e47284.zip |
multigrid: reorganize types and global varaibles
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/private/defs.h | 3 | ||||
-rw-r--r-- | src/nvim/api/ui.c | 2 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/globals.h | 32 | ||||
-rw-r--r-- | src/nvim/grid_defs.h | 59 | ||||
-rw-r--r-- | src/nvim/screen.c | 2 | ||||
-rw-r--r-- | src/nvim/screen.h | 13 | ||||
-rw-r--r-- | src/nvim/types.h | 35 | ||||
-rw-r--r-- | src/nvim/ui.c | 4 |
9 files changed, 82 insertions, 70 deletions
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 390b7e8363..feca140547 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -6,6 +6,7 @@ #include <string.h> #include "nvim/func_attr.h" +#include "nvim/types.h" #define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL} #define STRING_INIT {.data = NULL, .size = 0} @@ -20,8 +21,6 @@ # define DictionaryOf(...) Dictionary #endif -typedef int handle_T; - // Basic types typedef enum { kErrorTypeNone = -1, diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index c374bede99..4c55a56242 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -264,7 +264,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, return; } - ui_grid_resize((GridHandle)grid, (int)width, (int)height, error); + ui_grid_resize((handle_T)grid, (int)width, (int)height, error); } /// Pushes data into UI.UIData, to be consumed later by remote_ui_flush(). diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index ce83c4561d..05688790c2 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -18,6 +18,8 @@ typedef struct { // for garray_T #include "nvim/garray.h" +// for ScreenGrid +#include "nvim/grid_defs.h" // for HLF_COUNT #include "nvim/highlight_defs.h" // for pos_T, lpos_T and linenr_T diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 7f18262c3f..3447d9eb23 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -129,38 +129,6 @@ typedef off_t off_T; # endif #endif -/// ScreenLines[] contains a copy of the whole screen, as it currently is -/// displayed. It is a single block of screen cells, the size of the screen -/// plus one line. The extra line used as a buffer while redrawing a window -/// line, so it can be compared with the previous state of that line. This way -/// we can avoid sending bigger updates than neccessary to the Ul layer. -/// -/// Screen cells are stored as NUL-terminated UTF-8 strings, and a cell can -/// contain up to MAX_MCO composing characters after the base character. -/// The composing characters are to be drawn on top of the original character. -/// The content after the NUL is not defined (so comparison must be done a -/// single cell at a time). Double-width characters are stored in the left cell, -/// and the right cell should only contain the empty string. When a part of the -/// screen is cleared, the cells should be filled with a single whitespace char. -/// -/// ScreenAttrs[] contains the highlighting attribute for each cell. -/// LineOffset[n] is the offset from ScreenLines[] and ScreenAttrs[] for the -/// start of line 'n'. These offsets are in general not linear, as full screen -/// scrolling is implemented by rotating the offsets in the LineOffset array. -/// LineWraps[] is an array of boolean flags indicating if the screen line wraps -/// to the next line. It can only be true if a window occupies the entire screen -/// width. -/// -/// These, with other related attributes, are stored in a "ScreenGrid" -/// datastructure. -/// -/// Note: before the screen is initialized and when out of memory these can be -/// NULL. -EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, - 0, 0, 0 }); - -#define DEFAULT_GRID_HANDLE 1 // handle for the default_grid - /* * When vgetc() is called, it sets mod_mask to the set of modifiers that are * held down based on the MOD_MASK_* symbols that are read first. diff --git a/src/nvim/grid_defs.h b/src/nvim/grid_defs.h new file mode 100644 index 0000000000..964a71de62 --- /dev/null +++ b/src/nvim/grid_defs.h @@ -0,0 +1,59 @@ +#ifndef NVIM_GRID_DEFS_H +#define NVIM_GRID_DEFS_H + +#include <stdint.h> + +#include "nvim/types.h" + +#define MAX_MCO 6 // maximum value for 'maxcombine' + +// The characters and attributes drawn on grids. +typedef char_u schar_T[(MAX_MCO+1) * 4 + 1]; +typedef int16_t sattr_T; + +/// ScreenGrid represents a resizable rectuangular grid displayed by UI clients. +/// +/// ScreenLines contains the UTF-8 text that is currently displayed on the grid. +/// It is stored as a single block of cells. When redrawing a part of the grid, +/// the new state can be compared with the existing state of the grid. This way +/// we can avoid sending bigger updates than neccessary to the Ul layer. +/// +/// Screen cells are stored as NUL-terminated UTF-8 strings, and a cell can +/// contain up to MAX_MCO composing characters after the base character. +/// The composing characters are to be drawn on top of the original character. +/// The content after the NUL is not defined (so comparison must be done a +/// single cell at a time). Double-width characters are stored in the left cell, +/// and the right cell should only contain the empty string. When a part of the +/// screen is cleared, the cells should be filled with a single whitespace char. +/// +/// ScreenAttrs[] contains the highlighting attribute for each cell. +/// LineOffset[n] is the offset from ScreenLines[] and ScreenAttrs[] for the +/// start of line 'n'. These offsets are in general not linear, as full screen +/// scrolling is implemented by rotating the offsets in the LineOffset array. +/// LineWraps[] is an array of boolean flags indicating if the screen line wraps +/// to the next line. It can only be true if a window occupies the entire screen +/// width. +typedef struct { + handle_T handle; + + schar_T *ScreenLines; + sattr_T *ScreenAttrs; + unsigned *LineOffset; + char_u *LineWraps; + + // the size of the allocated grid + int Rows; + int Columns; + + // offsets for the grid relative to the global screen + int OffsetRow; + int OffsetColumn; + + // the size expected to be allocated to the internal grid + int internal_rows; + int internal_columns; + + int was_resized; +} ScreenGrid; + +#endif // NVIM_GRID_DEFS_H diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 079ed049e4..42c78e5a6a 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -7352,7 +7352,7 @@ void win_new_shellsize(void) } } -win_T * get_win_by_grid_handle(GridHandle handle) +win_T *get_win_by_grid_handle(handle_T handle) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_grid.handle == handle) { diff --git a/src/nvim/screen.h b/src/nvim/screen.h index 17515d4253..109541ef07 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -5,6 +5,7 @@ #include "nvim/types.h" #include "nvim/buffer_defs.h" +#include "nvim/grid_defs.h" #include "nvim/pos.h" /* @@ -20,6 +21,18 @@ #define NOT_VALID 40 /* buffer needs complete redraw */ #define CLEAR 50 /* screen messed up, clear it */ +/// By default, all widows are draw on a single rectangular grid, represented by +/// this ScreenGrid instance. In multigrid mode each window will have its own +/// grid, then this is only used for global screen elements that hasn't been +/// externalized. +/// +/// Note: before the screen is initialized and when out of memory these can be +/// NULL. +EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, + 0, 0, 0 }); + +#define DEFAULT_GRID_HANDLE 1 // handle for the default_grid + /// Status line click definition typedef struct { enum { diff --git a/src/nvim/types.h b/src/nvim/types.h index 6d39caab50..f803b45e27 100644 --- a/src/nvim/types.h +++ b/src/nvim/types.h @@ -13,38 +13,9 @@ typedef unsigned char char_u; // Can hold one decoded UTF-8 character. typedef uint32_t u8char_T; -typedef struct expand expand_T; - -#define MAX_MCO 6 // maximum value for 'maxcombine' - - -// The characters and attributes cached for the screen. -typedef char_u schar_T[(MAX_MCO+1) * 4 + 1]; -typedef int16_t sattr_T; - -// TODO(bfredl): find me a good home -typedef int GridHandle; -typedef struct { - GridHandle handle; +// Opaque handle used by API clients to refer to various objects in vim +typedef int handle_T; - schar_T *ScreenLines; - sattr_T *ScreenAttrs; - unsigned *LineOffset; - char_u *LineWraps; - - // the size of the allocated grid - int Rows; - int Columns; - - // offsets for the grid relative to the screen - int OffsetRow; - int OffsetColumn; - - // the size expected to be allocated to the internal grid - int internal_rows; - int internal_columns; - - int was_resized; -} ScreenGrid; +typedef struct expand expand_T; #endif // NVIM_TYPES_H diff --git a/src/nvim/ui.c b/src/nvim/ui.c index da6a1d0f2a..302aa555af 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -57,7 +57,7 @@ static int busy = 0; static int mode_idx = SHAPE_IDX_N; static bool pending_mode_info_update = false; static bool pending_mode_update = false; -static GridHandle cursor_grid_handle = DEFAULT_GRID_HANDLE; +static handle_T cursor_grid_handle = DEFAULT_GRID_HANDLE; #if MIN_LOG_LEVEL > DEBUG_LOG_LEVEL # define UI_LOG(funname, ...) @@ -443,7 +443,7 @@ Array ui_array(void) return all_uis; } -void ui_grid_resize(GridHandle grid_handle, int width, int height, Error *error) +void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error) { if (grid_handle == DEFAULT_GRID_HANDLE) { screen_resize(width, height); |