Skip to content

Commit f836421

Browse files
coditvabfredl
authored andcommitted
Send individual grids to UIs with event "grid_resize"
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 c896601 commit f836421

File tree

6 files changed

+53
-20
lines changed

6 files changed

+53
-20
lines changed

src/nvim/api/ui.c

+4
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ static void remote_ui_grid_resize(UI *ui, Integer grid,
270270
Array args = ARRAY_DICT_INIT;
271271
if (ui->ui_ext[kUINewgrid]) {
272272
ADD(args, INTEGER_OBJ(grid));
273+
} else if (grid != 1) {
274+
// calling grid_resize with a grid other than the global when
275+
// the remote ui is not managing grids should not send the event
276+
return;
273277
}
274278
ADD(args, INTEGER_OBJ(width));
275279
ADD(args, INTEGER_OBJ(height));

src/nvim/screen.c

+36-14
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
@@ -422,6 +430,7 @@ void update_screen(int type)
422430
win_redr_status(wp);
423431
}
424432
}
433+
send_grid_resize = false;
425434
end_search_hl();
426435
// May need to redraw the popup menu.
427436
if (pum_drawn()) {
@@ -656,7 +665,7 @@ static void win_update(win_T *wp)
656665

657666
type = wp->w_redr_type;
658667

659-
window_grid_alloc(wp, false);
668+
win_grid_alloc(wp, false);
660669

661670
if (type == NOT_VALID) {
662671
wp->w_redr_status = TRUE;
@@ -2223,7 +2232,7 @@ win_line (
22232232
row = startrow;
22242233

22252234
// allocate window grid if not already
2226-
window_grid_alloc(wp, true);
2235+
win_grid_alloc(wp, true);
22272236

22282237
/*
22292238
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5833,18 +5842,28 @@ int screen_valid(int doclear)
58335842
/// (re)allocate a window grid if size changed
58345843
/// If "doclear" is true, clear the screen if resized.
58355844
// TODO(utkarshme): Think of a better name, place
5836-
void window_grid_alloc(win_T *wp, int doclear)
5845+
void win_grid_alloc(win_T *wp, int doclear)
58375846
{
5838-
if (wp->w_grid.ScreenLines != NULL
5839-
&& wp->w_grid.Rows == wp->w_height
5840-
&& wp->w_grid.Columns == wp->w_width) {
5841-
return;
5842-
}
5847+
if (wp->w_grid.ScreenLines == NULL
5848+
|| wp->w_grid.Rows != wp->w_height
5849+
|| wp->w_grid.Columns != wp->w_width) {
5850+
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5851+
5852+
// only assign a grid handle if not already
5853+
if (wp->w_grid.handle == 0) {
5854+
wp->w_grid.handle = ++last_handle;
5855+
}
5856+
5857+
wp->w_grid.OffsetRow = wp->w_winrow;
5858+
wp->w_grid.OffsetColumn = wp->w_wincol;
58435859

5844-
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5860+
wp->w_grid.was_resized = true;
5861+
}
58455862

5846-
wp->w_grid.OffsetRow = wp->w_winrow;
5847-
wp->w_grid.OffsetColumn = wp->w_wincol;
5863+
if (send_grid_resize || wp->w_grid.was_resized) {
5864+
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
5865+
wp->w_grid.was_resized = false;
5866+
}
58485867
}
58495868

58505869
/*
@@ -5938,6 +5957,7 @@ void screenalloc(bool doclear)
59385957

59395958
default_grid.OffsetRow = 0;
59405959
default_grid.OffsetColumn = 0;
5960+
default_grid.handle = 1;
59415961

59425962
must_redraw = CLEAR; /* need to clear the screen later */
59435963
if (doclear)
@@ -5962,7 +5982,7 @@ void screenalloc(bool doclear)
59625982
void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy)
59635983
{
59645984
int new_row, old_row;
5965-
ScreenGrid new = { 0 };
5985+
ScreenGrid new = *grid;
59665986

59675987
size_t ncells = (size_t)((rows+1) * columns);
59685988
new.ScreenLines = xmalloc(ncells * sizeof(schar_T));
@@ -6249,7 +6269,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62496269
}
62506270
}
62516271

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

62546274
return OK;
62556275
}
@@ -6301,7 +6321,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
63016321
}
63026322
}
63036323

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

63066326
return OK;
63076327
}
@@ -7054,6 +7074,8 @@ void screen_resize(int width, int height)
70547074
default_grid.Rows = screen_Rows;
70557075
default_grid.Columns = screen_Columns;
70567076

7077+
send_grid_resize = true;
7078+
70577079
/* The window layout used to be adjusted here, but it now happens in
70587080
* screenalloc() (also invoked from screenclear()). That is because the
70597081
* "busy" check above may skip this, but not screenalloc(). */

src/nvim/types.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef struct {
3939
// offsets for the grid relative to the screen
4040
int OffsetRow;
4141
int OffsetColumn;
42+
43+
int was_resized;
4244
} ScreenGrid;
4345

4446
#endif // NVIM_TYPES_H

src/nvim/ui.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,13 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active)
317317
void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr)
318318
{
319319
size_t off = grid->LineOffset[row] + (size_t)startcol;
320-
UI_CALL(raw_line, 1, grid->OffsetRow + row, grid->OffsetColumn + startcol,
321-
grid->OffsetColumn + endcol, grid->OffsetColumn + clearcol,
322-
clearattr, (const schar_T *)grid->ScreenLines + off,
323-
(const schar_T *)grid->ScreenAttrs + off);
320+
int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetRow;
321+
int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetColumn;
322+
323+
UI_CALL(raw_line, grid->handle, row_off + row, col_off + startcol,
324+
col_off + endcol, col_off + clearcol, clearattr,
325+
(const schar_T *)grid->ScreenLines + off,
326+
(const sattr_T *)grid->ScreenAttrs + off);
324327

325328
if (p_wd) { // 'writedelay': flush & delay each time.
326329
int old_row = row, old_col = col;

src/nvim/ui.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef enum {
1616
kUIWildmenu,
1717
#define kUIGlobalCount (kUIWildmenu+1)
1818
kUINewgrid,
19+
kUIMultigrid,
1920
kUIHlState,
2021
kUIExtCount,
2122
} UIExtension;
@@ -26,6 +27,7 @@ EXTERN const char *ui_ext_names[] INIT(= {
2627
"ext_tabline",
2728
"ext_wildmenu",
2829
"ext_newgrid",
30+
"ext_multigrid",
2931
"ext_hlstate",
3032
});
3133

src/nvim/window.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,7 @@ void win_setheight_win(int height, win_T *win)
42224222
}
42234223

42244224
frame_setheight(win->w_frame, height + win->w_status_height);
4225-
window_grid_alloc(win, false);
4225+
win_grid_alloc(win, false);
42264226

42274227
/* recompute the window positions */
42284228
row = win_comp_pos();
@@ -4419,7 +4419,7 @@ void win_setwidth_win(int width, win_T *wp)
44194419
}
44204420

44214421
frame_setwidth(wp->w_frame, width + wp->w_vsep_width);
4422-
window_grid_alloc(wp, false);
4422+
win_grid_alloc(wp, false);
44234423

44244424
/* recompute the window positions */
44254425
(void)win_comp_pos();

0 commit comments

Comments
 (0)