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  // fixed value for 'maxcombine'
11 
12 // The characters and attributes drawn on grids.
13 typedef char_u schar_T[(MAX_MCO+1) * 4 + 1];
14 typedef int sattr_T;
15 
16 enum {
17   kZIndexDefaultGrid = 0,
18   kZIndexFloatDefault = 50,
19   kZIndexPopupMenu = 100,
20   kZIndexMessages = 200,
21   kZIndexCmdlinePopupMenu = 250,
22 };
23 
24 
25 /// ScreenGrid represents a resizable rectuangular grid displayed by UI clients.
26 ///
27 /// chars[] contains the UTF-8 text that is currently displayed on the grid.
28 /// It is stored as a single block of cells. When redrawing a part of the grid,
29 /// the new state can be compared with the existing state of the grid. This way
30 /// we can avoid sending bigger updates than necessary to the Ul layer.
31 ///
32 /// Screen cells are stored as NUL-terminated UTF-8 strings, and a cell can
33 /// contain up to MAX_MCO composing characters after the base character.
34 /// The composing characters are to be drawn on top of the original character.
35 /// The content after the NUL is not defined (so comparison must be done a
36 /// single cell at a time). Double-width characters are stored in the left cell,
37 /// and the right cell should only contain the empty string. When a part of the
38 /// screen is cleared, the cells should be filled with a single whitespace char.
39 ///
40 /// attrs[] contains the highlighting attribute for each cell.
41 /// line_offset[n] is the offset from chars[] and attrs[] for the
42 /// start of line 'n'. These offsets are in general not linear, as full screen
43 /// scrolling is implemented by rotating the offsets in the line_offset array.
44 /// line_wraps[] is an array of boolean flags indicating if the screen line
45 /// wraps to the next line. It can only be true if a window occupies the entire
46 /// screen width.
47 typedef struct ScreenGrid ScreenGrid;
48 struct ScreenGrid {
49   handle_T handle;
50 
51   schar_T *chars;
52   sattr_T *attrs;
53   unsigned *line_offset;
54   char_u *line_wraps;
55 
56   // last column that was drawn (not cleared with the default background).
57   // only used when "throttled" is set. Not allocated by grid_alloc!
58   int *dirty_col;
59 
60   // the size of the allocated grid.
61   int Rows;
62   int Columns;
63 
64   // The state of the grid is valid. Otherwise it needs to be redrawn.
65   bool valid;
66 
67   // only draw internally and don't send updates yet to the compositor or
68   // external UI.
69   bool throttled;
70 
71   // TODO(bfredl): maybe physical grids and "views" (i e drawing
72   // specifications) should be two separate types?
73   // offsets for the grid relative to another grid. Used for grids
74   // that are views into another, actually allocated grid 'target'
75   int row_offset;
76   int col_offset;
77   ScreenGrid *target;
78 
79   // whether the compositor should blend the grid with the background grid
80   bool blending;
81 
82   // whether the grid can be focused with mouse clicks.
83   bool focusable;
84 
85   // z-index: the order in the stack of grids.
86   int zindex;
87 
88   // Below is state owned by the compositor. Should generally not be set/read
89   // outside this module, except for specific compatibility hacks
90 
91   // position of the grid on the composed screen.
92   int comp_row;
93   int comp_col;
94 
95   // Requested width and height of the grid upon resize. Used by
96   // `ui_compositor` to correctly determine which regions need to
97   // be redrawn.
98   int comp_width;
99   int comp_height;
100 
101   // z-index of the grid. Grids with higher index is draw on top.
102   // default_grid.comp_index is always zero.
103   size_t comp_index;
104 
105   // compositor should momentarily ignore the grid. Used internally when
106   // moving around grids etc.
107   bool comp_disabled;
108 };
109 
110 #define SCREEN_GRID_INIT { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, false, \
111                            false, 0, 0, NULL, false, true, 0, \
112                            0, 0, 0, 0, 0,  false }
113 
114 #endif  // NVIM_GRID_DEFS_H
115