Skip to content

Commit e9c4f02

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 466bbc8 commit e9c4f02

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

src/nvim/api/ui.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ static void remote_ui_grid_resize(UI *ui, Integer grid,
262262
Array args = ARRAY_DICT_INIT;
263263
if (ui->ui_ext[kUIMultigrid]) {
264264
ADD(args, INTEGER_OBJ(grid));
265+
} else if (grid != 1) {
266+
// calling grid_resize with a grid other than the global when
267+
// the remote ui is not managing grids should not send the event
268+
return;
265269
}
266270
ADD(args, INTEGER_OBJ(width));
267271
ADD(args, INTEGER_OBJ(height));

src/nvim/screen.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ 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+
131136
#ifdef INCLUDE_GENERATED_DECLARATIONS
132137
# include "screen.c.generated.h"
133138
#endif
@@ -5824,6 +5829,12 @@ void window_grid_alloc(win_T *wp, int doclear)
58245829

58255830
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
58265831

5832+
// only assign a grid handle if not already
5833+
if (wp->w_grid.handle == 0) {
5834+
wp->w_grid.handle = ++last_handle;
5835+
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
5836+
}
5837+
58275838
wp->w_grid.OffsetRow = wp->w_winrow;
58285839
wp->w_grid.OffsetColumn = wp->w_wincol;
58295840
}
@@ -5919,6 +5930,7 @@ void screenalloc(bool doclear)
59195930

59205931
default_grid.OffsetRow = 0;
59215932
default_grid.OffsetColumn = 0;
5933+
default_grid.handle = 1;
59225934

59235935
must_redraw = CLEAR; /* need to clear the screen later */
59245936
if (doclear)
@@ -6230,7 +6242,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62306242
}
62316243
}
62326244

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

62356247
return OK;
62366248
}
@@ -6282,7 +6294,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62826294
}
62836295
}
62846296

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

62876299
return OK;
62886300
}

src/nvim/types.h

Lines changed: 3 additions & 0 deletions
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;

src/nvim/ui.c

Lines changed: 10 additions & 11 deletions
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);

0 commit comments

Comments
 (0)