Skip to content

Commit 736564a

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 eb3d69f commit 736564a

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

src/nvim/api/ui.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ static void remote_ui_grid_resize(UI *ui, Integer grid,
268268
Integer width, Integer height)
269269
{
270270
Array args = ARRAY_DICT_INIT;
271-
if (ui->ui_ext[kUINewgrid]) {
271+
if (ui->ui_ext[kUIMultigrid]) {
272272
ADD(args, INTEGER_OBJ(grid));
273273
}
274274
ADD(args, INTEGER_OBJ(width));
275275
ADD(args, INTEGER_OBJ(height));
276-
const char *name = ui->ui_ext[kUINewgrid] ? "grid_resize" : "resize";
276+
const char *name = ui->ui_ext[kUIMultigrid] ? "grid_resize" : "resize";
277277
push_call(ui, name, args);
278278
}
279279

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, true); // any popup menu will be redrawn below
423431
}
424432
}
433+
send_grid_resize = false;
425434
end_search_hl();
426435
// May need to redraw the popup menu.
427436
if (pum_drawn()) {
@@ -661,7 +670,7 @@ static void win_update(win_T *wp)
661670

662671
type = wp->w_redr_type;
663672

664-
window_grid_alloc(wp, false);
673+
win_grid_alloc(wp, false);
665674

666675
if (type == NOT_VALID) {
667676
wp->w_redr_status = TRUE;
@@ -2240,7 +2249,7 @@ win_line (
22402249
row = startrow;
22412250

22422251
// allocate window grid if not already
2243-
window_grid_alloc(wp, true);
2252+
win_grid_alloc(wp, true);
22442253

22452254
/*
22462255
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5844,18 +5853,28 @@ int screen_valid(int doclear)
58445853
/// (re)allocate a window grid if size changed
58455854
/// If "doclear" is true, clear the screen if resized.
58465855
// TODO(utkarshme): Think of a better name, place
5847-
void window_grid_alloc(win_T *wp, int doclear)
5856+
void win_grid_alloc(win_T *wp, int doclear)
58485857
{
5849-
if (wp->w_grid.ScreenLines != NULL
5850-
&& wp->w_grid.Rows == wp->w_height
5851-
&& wp->w_grid.Columns == wp->w_width) {
5852-
return;
5853-
}
5858+
if (wp->w_grid.ScreenLines == NULL
5859+
|| wp->w_grid.Rows != wp->w_height
5860+
|| wp->w_grid.Columns != wp->w_width) {
5861+
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5862+
5863+
// only assign a grid handle if not already
5864+
if (wp->w_grid.handle == 0) {
5865+
wp->w_grid.handle = ++last_handle;
5866+
}
5867+
5868+
wp->w_grid.OffsetRow = wp->w_winrow;
5869+
wp->w_grid.OffsetColumn = wp->w_wincol;
58545870

5855-
grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
5871+
wp->w_grid.was_resized = true;
5872+
}
58565873

5857-
wp->w_grid.OffsetRow = wp->w_winrow;
5858-
wp->w_grid.OffsetColumn = wp->w_wincol;
5874+
if (send_grid_resize || wp->w_grid.was_resized) {
5875+
ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
5876+
wp->w_grid.was_resized = false;
5877+
}
58595878
}
58605879

58615880
/*
@@ -5949,6 +5968,7 @@ void screenalloc(bool doclear)
59495968

59505969
default_grid.OffsetRow = 0;
59515970
default_grid.OffsetColumn = 0;
5971+
default_grid.handle = 1;
59525972

59535973
must_redraw = CLEAR; /* need to clear the screen later */
59545974
if (doclear)
@@ -5973,7 +5993,7 @@ void screenalloc(bool doclear)
59735993
void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy)
59745994
{
59755995
int new_row, old_row;
5976-
ScreenGrid new = { 0 };
5996+
ScreenGrid new = *grid;
59775997

59785998
size_t ncells = (size_t)((rows+1) * columns);
59795999
new.ScreenLines = xmalloc(ncells * sizeof(schar_T));
@@ -6260,7 +6280,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62606280
}
62616281
}
62626282

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

62656285
return OK;
62666286
}
@@ -6312,7 +6332,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
63126332
}
63136333
}
63146334

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

63176337
return OK;
63186338
}
@@ -7059,6 +7079,8 @@ void screen_resize(int width, int height)
70597079
default_grid.Rows = screen_Rows;
70607080
default_grid.Columns = screen_Columns;
70617081

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,12 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
319319
int clearattr, bool wrap)
320320
{
321321
size_t off = grid->LineOffset[row] + (size_t)startcol;
322-
UI_CALL(raw_line, 1, grid->OffsetRow + row, grid->OffsetColumn + startcol,
323-
grid->OffsetColumn + endcol, grid->OffsetColumn + clearcol,
324-
clearattr, wrap, (const schar_T *)grid->ScreenLines + off,
322+
int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetRow;
323+
int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetColumn;
324+
325+
UI_CALL(raw_line, grid->handle, row_off + row, col_off + startcol,
326+
col_off + endcol, col_off + clearcol, clearattr, wrap,
327+
(const schar_T *)grid->ScreenLines + off,
325328
(const sattr_T *)grid->ScreenAttrs + off);
326329

327330
if (p_wd) { // 'writedelay': flush & delay each time.

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
@@ -4262,7 +4262,7 @@ void win_setheight_win(int height, win_T *win)
42624262
}
42634263

42644264
frame_setheight(win->w_frame, height + win->w_status_height);
4265-
window_grid_alloc(win, false);
4265+
win_grid_alloc(win, false);
42664266

42674267
/* recompute the window positions */
42684268
row = win_comp_pos();
@@ -4459,7 +4459,7 @@ void win_setwidth_win(int width, win_T *wp)
44594459
}
44604460

44614461
frame_setwidth(wp->w_frame, width + wp->w_vsep_width);
4462-
window_grid_alloc(wp, false);
4462+
win_grid_alloc(wp, false);
44634463

44644464
/* recompute the window positions */
44654465
(void)win_comp_pos();

0 commit comments

Comments
 (0)