Skip to content

Commit d6e265c

Browse files
committed
Externalize window grids in the basic architecture
The grids get allocated a handle (very naive at the moment) and these handles are sent with every event to the external UIs. Works for one window at the moment. Use neovim/python-gui#36 to test. It currently creates separate windows for each grid. `:sp` seems to work, but `:vs` crashes.
1 parent e3869f3 commit d6e265c

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

Diff for: src/nvim/api/ui.c

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ static void remote_ui_grid_resize(UI *ui, Integer grid,
267267
Array args = ARRAY_DICT_INIT;
268268
if (ui->ui_ext[kUINewgrid]) {
269269
ADD(args, INTEGER_OBJ(grid));
270+
} else if (grid != 1) {
271+
// calling grid_resize with a grid other than the global when
272+
// the remote ui is not managing grids should not send the event
273+
return;
270274
}
271275
ADD(args, INTEGER_OBJ(width));
272276
ADD(args, INTEGER_OBJ(height));

Diff for: src/nvim/screen.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ StlClickDefinition *tab_page_click_defs = NULL;
128128

129129
long tab_page_click_defs_size = 0;
130130

131+
/// The last handle that was assigned to a ScreenGrid. 1 is reserved for
132+
/// the default_grid.
133+
/// TODO(utkarshme): Numbers can be recycled after grid destruction.
134+
static int last_handle = 1;
135+
136+
/// Whether to call "ui_call_grid_resize" in win_grid_alloc
137+
static int send_grid_resize;
138+
131139
#ifdef INCLUDE_GENERATED_DECLARATIONS
132140
# include "screen.c.generated.h"
133141
#endif
@@ -5816,13 +5824,21 @@ int screen_valid(int doclear)
58165824
// TODO(utkarshme): Think of a better name, place
58175825
void window_grid_alloc(win_T *wp, int doclear)
58185826
{
5827+
int handle_saved = wp->w_grid.handle;
58195828
if (wp->w_grid.ScreenLines != NULL
58205829
&& wp->w_grid.Rows == wp->w_height
58215830
&& wp->w_grid.Columns == wp->w_width) {
58225831
return;
58235832
}
58245833

58255834
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5835+
wp->w_grid.handle = handle_saved;
5836+
5837+
// only assign a grid handle if not already
5838+
if (wp->w_grid.handle == 0) {
5839+
wp->w_grid.handle = ++last_handle;
5840+
}
5841+
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
58265842

58275843
wp->w_grid.OffsetRow = wp->w_winrow;
58285844
wp->w_grid.OffsetColumn = wp->w_wincol;
@@ -5919,6 +5935,7 @@ void screenalloc(bool doclear)
59195935

59205936
default_grid.OffsetRow = 0;
59215937
default_grid.OffsetColumn = 0;
5938+
default_grid.handle = 1;
59225939

59235940
must_redraw = CLEAR; /* need to clear the screen later */
59245941
if (doclear)
@@ -6230,7 +6247,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62306247
}
62316248
}
62326249

6233-
ui_call_grid_scroll(1, row, end, col, col+width, -line_count, 0);
6250+
ui_call_grid_scroll(grid->handle, row, end, col, col+width, -line_count, 0);
62346251

62356252
return OK;
62366253
}
@@ -6282,7 +6299,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62826299
}
62836300
}
62846301

6285-
ui_call_grid_scroll(1, row, end, col, col+width, line_count, 0);
6302+
ui_call_grid_scroll(grid->handle, row, end, col, col+width, line_count, 0);
62866303

62876304
return OK;
62886305
}

Diff for: src/nvim/types.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ typedef char_u schar_T[(MAX_MCO+1) * 4 + 1];
2323
typedef int16_t sattr_T;
2424

2525
// TODO(bfredl): find me a good home
26+
typedef unsigned int GridHandle;
2627
typedef struct {
28+
GridHandle handle;
29+
2730
schar_T *ScreenLines;
2831
sattr_T *ScreenAttrs;
2932
unsigned *LineOffset;

Diff for: src/nvim/ui.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,16 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active)
314314

315315
void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr)
316316
{
317-
size_t off = grid->LineOffset[row] + (size_t)startcol;
318-
319-
UI_CALL(raw_line, 1,
320-
grid->OffsetRow + row,
321-
grid->OffsetColumn + startcol,
322-
grid->OffsetColumn + endcol,
323-
grid->OffsetColumn + clearcol,
324-
clearattr,
325-
grid->ScreenLines + off,
326-
grid->ScreenAttrs + off);
327-
317+
size_t off = grid->LineOffset[row] + (size_t)startcol;
318+
int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetRow;
319+
int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetColumn;
320+
321+
UI_CALL(raw_line, grid->handle,
322+
row_off + row,
323+
col_off + startcol,
324+
col_off + endcol,
325+
col_off + clearcol,
326+
clearattr, grid->ScreenLines + off, grid->ScreenAttrs + off);
328327
if (p_wd) { // 'writedelay': flush & delay each time.
329328
ui_flush();
330329
uint64_t wd = (uint64_t)labs(p_wd);

Diff for: src/nvim/ui.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ EXTERN const char *ui_ext_names[] INIT(= {
2424
"ext_popupmenu",
2525
"ext_tabline",
2626
"ext_wildmenu",
27+
"ext_multigrid",
2728
"ext_newgrid",
2829
"ext_hlstate",
2930
});

0 commit comments

Comments
 (0)