Skip to content

Commit

Permalink
Externalize window grids in the basic architecture
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coditva committed Jun 14, 2018
1 parent e3869f3 commit d6e265c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/nvim/api/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ static void remote_ui_grid_resize(UI *ui, Integer grid,
Array args = ARRAY_DICT_INIT;
if (ui->ui_ext[kUINewgrid]) {
ADD(args, INTEGER_OBJ(grid));
} else if (grid != 1) {
// calling grid_resize with a grid other than the global when
// the remote ui is not managing grids should not send the event
return;
}
ADD(args, INTEGER_OBJ(width));
ADD(args, INTEGER_OBJ(height));
Expand Down
21 changes: 19 additions & 2 deletions src/nvim/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ StlClickDefinition *tab_page_click_defs = NULL;

long tab_page_click_defs_size = 0;

/// The last handle that was assigned to a ScreenGrid. 1 is reserved for
/// the default_grid.
/// TODO(utkarshme): Numbers can be recycled after grid destruction.
static int last_handle = 1;

/// Whether to call "ui_call_grid_resize" in win_grid_alloc
static int send_grid_resize;

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "screen.c.generated.h"
#endif
Expand Down Expand Up @@ -5816,13 +5824,21 @@ int screen_valid(int doclear)
// TODO(utkarshme): Think of a better name, place
void window_grid_alloc(win_T *wp, int doclear)
{
int handle_saved = wp->w_grid.handle;
if (wp->w_grid.ScreenLines != NULL
&& wp->w_grid.Rows == wp->w_height
&& wp->w_grid.Columns == wp->w_width) {
return;
}

grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
wp->w_grid.handle = handle_saved;

// only assign a grid handle if not already
if (wp->w_grid.handle == 0) {
wp->w_grid.handle = ++last_handle;
}
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);

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

default_grid.OffsetRow = 0;
default_grid.OffsetColumn = 0;
default_grid.handle = 1;

must_redraw = CLEAR; /* need to clear the screen later */
if (doclear)
Expand Down Expand Up @@ -6230,7 +6247,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
}
}

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

return OK;
}
Expand Down Expand Up @@ -6282,7 +6299,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
}
}

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

return OK;
}
Expand Down
3 changes: 3 additions & 0 deletions src/nvim/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ typedef char_u schar_T[(MAX_MCO+1) * 4 + 1];
typedef int16_t sattr_T;

// TODO(bfredl): find me a good home
typedef unsigned int GridHandle;
typedef struct {
GridHandle handle;

schar_T *ScreenLines;
sattr_T *ScreenAttrs;
unsigned *LineOffset;
Expand Down
21 changes: 10 additions & 11 deletions src/nvim/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,16 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active)

void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr)
{
size_t off = grid->LineOffset[row] + (size_t)startcol;

UI_CALL(raw_line, 1,
grid->OffsetRow + row,
grid->OffsetColumn + startcol,
grid->OffsetColumn + endcol,
grid->OffsetColumn + clearcol,
clearattr,
grid->ScreenLines + off,
grid->ScreenAttrs + off);

size_t off = grid->LineOffset[row] + (size_t)startcol;
int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetRow;
int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetColumn;

UI_CALL(raw_line, grid->handle,
row_off + row,
col_off + startcol,
col_off + endcol,
col_off + clearcol,
clearattr, grid->ScreenLines + off, grid->ScreenAttrs + off);
if (p_wd) { // 'writedelay': flush & delay each time.
ui_flush();
uint64_t wd = (uint64_t)labs(p_wd);
Expand Down
1 change: 1 addition & 0 deletions src/nvim/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ EXTERN const char *ui_ext_names[] INIT(= {
"ext_popupmenu",
"ext_tabline",
"ext_wildmenu",
"ext_multigrid",
"ext_newgrid",
"ext_hlstate",
});
Expand Down

0 comments on commit d6e265c

Please sign in to comment.