1#ifndef NVIM_GRID_DEFS_H
2#define NVIM_GRID_DEFS_H
3
4#include <stdbool.h>
5#include <stddef.h>
6#include <stdint.h>
7
8#include "nvim/types.h"
9
10#define MAX_MCO 6 // maximum value for 'maxcombine'
11
12// The characters and attributes drawn on grids.
13typedef char_u schar_T[(MAX_MCO+1) * 4 + 1];
14typedef int16_t sattr_T;
15
16/// ScreenGrid represents a resizable rectuangular grid displayed by UI clients.
17///
18/// chars[] contains the UTF-8 text that is currently displayed on the grid.
19/// It is stored as a single block of cells. When redrawing a part of the grid,
20/// the new state can be compared with the existing state of the grid. This way
21/// we can avoid sending bigger updates than neccessary to the Ul layer.
22///
23/// Screen cells are stored as NUL-terminated UTF-8 strings, and a cell can
24/// contain up to MAX_MCO composing characters after the base character.
25/// The composing characters are to be drawn on top of the original character.
26/// The content after the NUL is not defined (so comparison must be done a
27/// single cell at a time). Double-width characters are stored in the left cell,
28/// and the right cell should only contain the empty string. When a part of the
29/// screen is cleared, the cells should be filled with a single whitespace char.
30///
31/// attrs[] contains the highlighting attribute for each cell.
32/// line_offset[n] is the offset from chars[] and attrs[] for the
33/// start of line 'n'. These offsets are in general not linear, as full screen
34/// scrolling is implemented by rotating the offsets in the line_offset array.
35/// line_wraps[] is an array of boolean flags indicating if the screen line
36/// wraps to the next line. It can only be true if a window occupies the entire
37/// screen width.
38typedef struct {
39 handle_T handle;
40
41 schar_T *chars;
42 sattr_T *attrs;
43 unsigned *line_offset;
44 char_u *line_wraps;
45
46 // last column that was drawn (not cleared with the default background).
47 // only used when "throttled" is set. Not allocated by grid_alloc!
48 int *dirty_col;
49
50 // the size of the allocated grid.
51 int Rows;
52 int Columns;
53
54 // The state of the grid is valid. Otherwise it needs to be redrawn.
55 bool valid;
56
57 // only draw internally and don't send updates yet to the compositor or
58 // external UI.
59 bool throttled;
60
61 // offsets for the grid relative to the global screen. Used by screen.c
62 // for windows that don't have w_grid->chars etc allocated
63 int row_offset;
64 int col_offset;
65
66 // whether the compositor should blend the grid with the background grid
67 bool blending;
68
69 // whether the grid can be focused with mouse clicks.
70 bool focusable;
71
72 // Below is state owned by the compositor. Should generally not be set/read
73 // outside this module, except for specific compatibilty hacks
74
75 // position of the grid on the composed screen.
76 int comp_row;
77 int comp_col;
78
79 // z-index of the grid. Grids with higher index is draw on top.
80 // default_grid.comp_index is always zero.
81 size_t comp_index;
82
83 // compositor should momentarily ignore the grid. Used internally when
84 // moving around grids etc.
85 bool comp_disabled;
86} ScreenGrid;
87
88#define SCREEN_GRID_INIT { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, false, \
89 false, 0, 0, false, true, 0, 0, 0, false }
90
91#endif // NVIM_GRID_DEFS_H
92