Skip to content

Commit 5a857b6

Browse files
committed
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 03a79e1 commit 5a857b6

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

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));

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()) {
@@ -654,7 +663,7 @@ static void win_update(win_T *wp)
654663

655664
type = wp->w_redr_type;
656665

657-
window_grid_alloc(wp, false);
666+
win_grid_alloc(wp, false);
658667

659668
if (type == NOT_VALID) {
660669
wp->w_redr_status = TRUE;
@@ -2221,7 +2230,7 @@ win_line (
22212230
row = startrow;
22222231

22232232
// allocate window grid if not already
2224-
window_grid_alloc(wp, true);
2233+
win_grid_alloc(wp, true);
22252234

22262235
/*
22272236
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5821,18 +5830,28 @@ int screen_valid(int doclear)
58215830
/// (re)allocate a window grid if size changed
58225831
/// If "doclear" is true, clear the screen if resized.
58235832
// TODO(utkarshme): Think of a better name, place
5824-
void window_grid_alloc(win_T *wp, int doclear)
5833+
void win_grid_alloc(win_T *wp, int doclear)
58255834
{
5826-
if (wp->w_grid.ScreenLines != NULL
5827-
&& wp->w_grid.Rows == wp->w_height
5828-
&& wp->w_grid.Columns == wp->w_width) {
5829-
return;
5830-
}
5835+
if (wp->w_grid.ScreenLines == NULL
5836+
|| wp->w_grid.Rows != wp->w_height
5837+
|| wp->w_grid.Columns != wp->w_width) {
5838+
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5839+
5840+
// only assign a grid handle if not already
5841+
if (wp->w_grid.handle == 0) {
5842+
wp->w_grid.handle = ++last_handle;
5843+
}
5844+
5845+
wp->w_grid.OffsetRow = wp->w_winrow;
5846+
wp->w_grid.OffsetColumn = wp->w_wincol;
58315847

5832-
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5848+
wp->w_grid.was_resized = true;
5849+
}
58335850

5834-
wp->w_grid.OffsetRow = wp->w_winrow;
5835-
wp->w_grid.OffsetColumn = wp->w_wincol;
5851+
if (send_grid_resize || wp->w_grid.was_resized) {
5852+
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
5853+
wp->w_grid.was_resized = false;
5854+
}
58365855
}
58375856

58385857
/*
@@ -5926,6 +5945,7 @@ void screenalloc(bool doclear)
59265945

59275946
default_grid.OffsetRow = 0;
59285947
default_grid.OffsetColumn = 0;
5948+
default_grid.handle = 1;
59295949

59305950
must_redraw = CLEAR; /* need to clear the screen later */
59315951
if (doclear)
@@ -5950,7 +5970,7 @@ void screenalloc(bool doclear)
59505970
void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy)
59515971
{
59525972
int new_row, old_row;
5953-
ScreenGrid new = { 0 };
5973+
ScreenGrid new = *grid;
59545974

59555975
size_t ncells = (size_t)((rows+1) * columns);
59565976
new.ScreenLines = xmalloc(ncells * sizeof(schar_T));
@@ -6237,7 +6257,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62376257
}
62386258
}
62396259

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

62426262
return OK;
62436263
}
@@ -6289,7 +6309,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62896309
}
62906310
}
62916311

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

62946314
return OK;
62956315
}
@@ -7032,6 +7052,8 @@ void screen_resize(int width, int height)
70327052
default_grid.Rows = screen_Rows;
70337053
default_grid.Columns = screen_Columns;
70347054

7055+
send_grid_resize = true;
7056+
70357057
/* The window layout used to be adjusted here, but it now happens in
70367058
* screenalloc() (also invoked from screenclear()). That is because the
70377059
* "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

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

317317
void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr)
318318
{
319-
size_t off = grid->LineOffset[row] + (size_t)startcol;
320-
321-
UI_CALL(raw_line, 1,
322-
grid->OffsetRow + row,
323-
grid->OffsetColumn + startcol,
324-
grid->OffsetColumn + endcol,
325-
grid->OffsetColumn + clearcol,
326-
clearattr,
327-
grid->ScreenLines + off,
328-
grid->ScreenAttrs + off);
329-
319+
size_t off = grid->LineOffset[row] + (size_t)startcol;
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,
324+
row_off + row,
325+
col_off + startcol,
326+
col_off + endcol,
327+
col_off + clearcol,
328+
clearattr, grid->ScreenLines + off, grid->ScreenAttrs + off);
330329
if (p_wd) { // 'writedelay': flush & delay each time.
331330
int old_row = row, old_col = col;
332331
// If'writedelay is active, we set the cursor to highlight what was drawn

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)