multigrid: reorganize types and global varaibles

This commit is contained in:
Björn Linse 2018-12-23 14:35:23 +01:00
parent 820c81e638
commit 1cec5542a8
9 changed files with 82 additions and 70 deletions

View File

@ -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,

View File

@ -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().

View File

@ -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

View File

@ -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.

59
src/nvim/grid_defs.h Normal file
View File

@ -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

View File

@ -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) {

View File

@ -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 {

View File

@ -13,38 +13,9 @@ typedef unsigned char char_u;
// Can hold one decoded UTF-8 character.
typedef uint32_t u8char_T;
// Opaque handle used by API clients to refer to various objects in vim
typedef int handle_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;
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;
#endif // NVIM_TYPES_H

View File

@ -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);