aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUtkarsh Maheshwari <utkarshme96@gmail.com>2018-06-06 02:59:11 +0530
committerBjörn Linse <bjorn.linse@gmail.com>2018-12-31 12:44:21 +0100
commit01555de2da79eaf6e569e5e6ee7244dbf5f709e5 (patch)
treec4cf93ea7ff63b6282d6ab596d6a155a43f9596f /src
parentf102f50ebeca98365b308463c25eb2caffffba51 (diff)
downloadrneovim-01555de2da79eaf6e569e5e6ee7244dbf5f709e5.tar.gz
rneovim-01555de2da79eaf6e569e5e6ee7244dbf5f709e5.tar.bz2
rneovim-01555de2da79eaf6e569e5e6ee7244dbf5f709e5.zip
multigrid: Allow UIs to set grid size different from window size
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/ui.c19
-rw-r--r--src/nvim/charset.c24
-rw-r--r--src/nvim/cursor.c8
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/ex_cmds.c6
-rw-r--r--src/nvim/ex_docmd.c6
-rw-r--r--src/nvim/getchar.c6
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/indent.c2
-rw-r--r--src/nvim/misc1.c12
-rw-r--r--src/nvim/move.c123
-rw-r--r--src/nvim/normal.c30
-rw-r--r--src/nvim/screen.c175
-rw-r--r--src/nvim/search.c2
-rw-r--r--src/nvim/types.h4
-rw-r--r--src/nvim/ui.c32
-rw-r--r--src/nvim/window.c6
17 files changed, 268 insertions, 193 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 01f8c9f71c..18befd498f 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -126,7 +126,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
}
}
- if (ui->ui_ext[kUIHlState]) {
+ if (ui->ui_ext[kUIHlState] || ui->ui_ext[kUIMultigrid]) {
ui->ui_ext[kUILinegrid] = true;
}
@@ -245,6 +245,23 @@ static void ui_set_option(UI *ui, bool init, String name, Object value,
name.data);
}
+/// Sets the inner "width" and "height" of the window grid identified by
+/// "grid" handle. If the grid does not exist, set error.
+void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width,
+ Integer height, Error *error)
+ FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY
+{
+ if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
+ api_set_error(error, kErrorTypeException,
+ "UI not attached to channel: %" PRId64, channel_id);
+ return;
+ }
+
+ // TODO(utkarshme): Check if grid exists
+
+ ui_grid_resize((GridHandle)grid, (int)width, (int)height);
+}
+
/// Pushes data into UI.UIData, to be consumed later by remote_ui_flush().
static void push_call(UI *ui, const char *name, Array args)
{
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 4e8bb3b0d7..874c996b1b 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1022,12 +1022,12 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
&& vim_isbreak(c)
&& !vim_isbreak((int)s[1])
&& wp->w_p_wrap
- && (wp->w_width != 0)) {
+ && (wp->w_grid.Columns != 0)) {
// Count all characters from first non-blank after a blank up to next
// non-blank after a blank.
numberextra = win_col_off(wp);
col2 = col;
- colmax = (colnr_T)(wp->w_width - numberextra - col_adj);
+ colmax = (colnr_T)(wp->w_grid.Columns - numberextra - col_adj);
if (col >= colmax) {
colmax += col_adj;
@@ -1076,9 +1076,9 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
numberextra = numberwidth;
col += numberextra + mb_added;
- if (col >= (colnr_T)wp->w_width) {
- col -= wp->w_width;
- numberextra = wp->w_width - (numberextra - win_col_off2(wp));
+ if (col >= (colnr_T)wp->w_grid.Columns) {
+ col -= wp->w_grid.Columns;
+ numberextra = wp->w_grid.Columns - (numberextra - win_col_off2(wp));
if (col >= numberextra && numberextra > 0) {
col %= numberextra;
}
@@ -1097,16 +1097,16 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
numberwidth -= win_col_off2(wp);
}
- if (col == 0 || (col + size + sbrlen > (colnr_T)wp->w_width)) {
+ if (col == 0 || (col + size + sbrlen > (colnr_T)wp->w_grid.Columns)) {
added = 0;
if (*p_sbr != NUL) {
- if (size + sbrlen + numberwidth > (colnr_T)wp->w_width) {
+ if (size + sbrlen + numberwidth > (colnr_T)wp->w_grid.Columns) {
// Calculate effective window width.
- int width = (colnr_T)wp->w_width - sbrlen - numberwidth;
- int prev_width = col ? ((colnr_T)wp->w_width - (sbrlen + col)) : 0;
+ int width = (colnr_T)wp->w_grid.Columns - sbrlen - numberwidth;
+ int prev_width = col ? ((colnr_T)wp->w_grid.Columns - (sbrlen + col)) : 0;
if (width == 0) {
- width = (colnr_T)wp->w_width;
+ width = (colnr_T)wp->w_grid.Columns;
}
added += ((size - prev_width) / width) * vim_strsize(p_sbr);
if ((size - prev_width) % width) {
@@ -1175,11 +1175,11 @@ bool in_win_border(win_T *wp, colnr_T vcol)
int width1; // width of first line (after line number)
int width2; // width of further lines
- if (wp->w_width == 0) {
+ if (wp->w_grid.Columns == 0) {
// there is no border
return false;
}
- width1 = wp->w_width - win_col_off(wp);
+ width1 = wp->w_grid.Columns - win_col_off(wp);
if ((int)vcol < width1 - 1) {
return false;
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 0fda941a51..8c80c1dfc0 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -120,11 +120,11 @@ static int coladvance2(
--curwin->w_curswant;
}
} else {
- int width = curwin->w_width - win_col_off(curwin);
+ int width = curwin->w_grid.Columns - win_col_off(curwin);
if (finetune
&& curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
&& wcol >= (colnr_T)width) {
csize = linetabsize(line);
if (csize > 0)
@@ -224,7 +224,7 @@ static int coladvance2(
int b = (int)wcol - (int)col;
/* The difference between wcol and col is used to set coladd. */
- if (b > 0 && b < (MAXCOL - 2 * curwin->w_width))
+ if (b > 0 && b < (MAXCOL - 2 * curwin->w_grid.Columns))
pos->coladd = b;
col += b;
@@ -436,7 +436,7 @@ bool leftcol_changed(void)
bool retval = false;
changed_cline_bef_curs();
- lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1;
+ lastcol = curwin->w_leftcol + curwin->w_grid.Columns - curwin_col_off() - 1;
validate_virtcol();
/*
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index d67818aa81..6fe62f1a87 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -16774,10 +16774,10 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
- uint16_t term_width = MAX(0, curwin->w_width - win_col_off(curwin));
+ uint16_t term_width = MAX(0, curwin->w_grid.Columns - win_col_off(curwin));
Channel *chan = channel_job_start(argv, on_stdout, on_stderr, on_exit,
true, false, false, cwd,
- term_width, curwin->w_height,
+ term_width, curwin->w_grid.Rows,
xstrdup("xterm-256color"),
&rettv->vval.v_number);
if (rettv->vval.v_number <= 0) {
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 36c4e333cf..0d14c90110 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -257,7 +257,7 @@ void ex_align(exarg_T *eap)
if (width <= 0)
width = curbuf->b_p_tw;
if (width == 0 && curbuf->b_p_wm > 0)
- width = curwin->w_width - curbuf->b_p_wm;
+ width = curwin->w_grid.Columns - curbuf->b_p_wm;
if (width <= 0)
width = 80;
}
@@ -2870,11 +2870,11 @@ void ex_z(exarg_T *eap)
// Vi compatible: ":z!" uses display height, without a count uses
// 'scroll'
if (eap->forceit) {
- bigness = curwin->w_height;
+ bigness = curwin->w_grid.Rows;
} else if (ONE_WINDOW) {
bigness = curwin->w_p_scr * 2;
} else {
- bigness = curwin->w_height - 3;
+ bigness = curwin->w_grid.Rows - 3;
}
if (bigness < 1) {
bigness = 1;
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 4ef332186e..4e5619ccc8 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -9196,7 +9196,7 @@ static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
&& (fprintf(fd,
"exe '%dresize ' . ((&lines * %" PRId64
" + %" PRId64 ") / %" PRId64 ")",
- n, (int64_t)wp->w_height,
+ n, (int64_t)wp->w_grid.Rows,
(int64_t)(Rows / 2), (int64_t)Rows) < 0
|| put_eol(fd) == FAIL))
return FAIL;
@@ -9459,8 +9459,8 @@ put_view(
" * winheight(0) + %" PRId64 ") / %" PRId64 ")",
(int64_t)wp->w_cursor.lnum,
(int64_t)(wp->w_cursor.lnum - wp->w_topline),
- (int64_t)(wp->w_height / 2),
- (int64_t)wp->w_height) < 0
+ (int64_t)(wp->w_grid.Rows / 2),
+ (int64_t)wp->w_grid.Rows) < 0
|| put_eol(fd) == FAIL
|| put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL
|| put_line(fd, "exe s:l") == FAIL
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 94702a9a3a..6a2ee12e46 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -2120,8 +2120,8 @@ static int vgetorpeek(int advance)
++col;
}
curwin->w_wrow = curwin->w_cline_row
- + curwin->w_wcol / curwin->w_width;
- curwin->w_wcol %= curwin->w_width;
+ + curwin->w_wcol / curwin->w_grid.Columns;
+ curwin->w_wcol %= curwin->w_grid.Columns;
curwin->w_wcol += curwin_col_off();
col = 0; /* no correction needed */
} else {
@@ -2130,7 +2130,7 @@ static int vgetorpeek(int advance)
}
} else if (curwin->w_p_wrap && curwin->w_wrow) {
--curwin->w_wrow;
- curwin->w_wcol = curwin->w_width - 1;
+ curwin->w_wcol = curwin->w_grid.Columns - 1;
col = curwin->w_cursor.col - 1;
}
if (col > 0 && curwin->w_wcol > 0) {
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 3462199476..57d14d650c 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -162,7 +162,7 @@ EXTERN int screen_Rows INIT(= 0); /* actual size of ScreenLines[] */
EXTERN int screen_Columns INIT(= 0); /* actual size of ScreenLines[] */
EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0,
- 0, 0, 0 });
+ 0, 0 });
/*
* When vgetc() is called, it sets mod_mask to the set of modifiers that are
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 3cc64e0033..76b06190a5 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -464,7 +464,7 @@ int get_breakindent_win(win_T *wp, char_u *line)
static varnumber_T prev_tick = 0; // Changedtick of cached value.
int bri = 0;
/* window width minus window margin space, i.e. what rests for text */
- const int eff_wwidth = wp->w_width
+ const int eff_wwidth = wp->w_grid.Columns
- ((wp->w_p_nu || wp->w_p_rnu)
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
? number_width(wp) + 1 : 0);
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index ffe2d11f08..fb5586dea2 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1251,7 +1251,7 @@ int plines_win_nofill(
return 1;
}
- if (wp->w_width == 0) {
+ if (wp->w_grid.Columns == 0) {
return 1;
}
@@ -1261,8 +1261,8 @@ int plines_win_nofill(
}
const int lines = plines_win_nofold(wp, lnum);
- if (winheight && lines > wp->w_height) {
- return wp->w_height;
+ if (winheight && lines > wp->w_grid.Rows) {
+ return wp->w_grid.Rows;
}
return lines;
}
@@ -1292,7 +1292,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum)
/*
* Add column offset for 'number', 'relativenumber' and 'foldcolumn'.
*/
- width = wp->w_width - win_col_off(wp);
+ width = wp->w_grid.Columns - win_col_off(wp);
if (width <= 0 || col > 32000) {
return 32000; // bigger than the number of screen columns
}
@@ -1318,7 +1318,7 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column)
if (!wp->w_p_wrap)
return lines + 1;
- if (wp->w_width == 0)
+ if (wp->w_grid.Columns == 0)
return lines + 1;
char_u *line = ml_get_buf(wp->w_buffer, lnum, false);
@@ -1340,7 +1340,7 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column)
}
// Add column offset for 'number', 'relativenumber', 'foldcolumn', etc.
- int width = wp->w_width - win_col_off(wp);
+ int width = wp->w_grid.Columns - win_col_off(wp);
if (width <= 0) {
return 9999;
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index bb44b458e8..6e317b03a4 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -83,7 +83,7 @@ static void comp_botline(win_T *wp)
redraw_for_cursorline(wp);
wp->w_valid |= (VALID_CROW|VALID_CHEIGHT);
}
- if (done + n > wp->w_height)
+ if (done + n > wp->w_grid.Rows)
break;
done += n;
lnum = last;
@@ -203,7 +203,7 @@ void update_topline(void)
check_topline = true;
if (check_topline) {
- int halfheight = curwin->w_height / 2 - 1;
+ int halfheight = curwin->w_grid.Rows / 2 - 1;
if (halfheight < 2)
halfheight = 2;
long n;
@@ -295,14 +295,14 @@ void update_topline(void)
lnum >= curwin->w_botline - p_so; --lnum) {
++line_count;
/* stop at end of file or when we know we are far off */
- if (lnum <= 0 || line_count > curwin->w_height + 1)
+ if (lnum <= 0 || line_count > curwin->w_grid.Rows + 1)
break;
(void)hasFolding(lnum, &lnum, NULL);
}
} else
line_count = curwin->w_cursor.lnum - curwin->w_botline
+ 1 + p_so;
- if (line_count <= curwin->w_height + 1)
+ if (line_count <= curwin->w_grid.Rows + 1)
scroll_cursor_bot(scrolljump_value(), false);
else
scroll_cursor_halfway(false);
@@ -349,7 +349,7 @@ void update_topline_win(win_T* win)
*/
static int scrolljump_value(void)
{
- long result = p_sj >= 0 ? p_sj : (curwin->w_height * -p_sj) / 100;
+ long result = p_sj >= 0 ? p_sj : (curwin->w_grid.Rows * -p_sj) / 100;
assert(result <= INT_MAX);
return (int)result;
}
@@ -525,6 +525,7 @@ int cursor_valid(void)
*/
void validate_cursor(void)
{
+ win_grid_alloc(curwin, true); // we need to have w_grid.Rows/Columns updated
check_cursor_moved(curwin);
if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW))
curs_columns(true);
@@ -663,14 +664,14 @@ void validate_cursor_col(void)
colnr_T col = curwin->w_virtcol;
colnr_T off = curwin_col_off();
col += off;
- int width = curwin->w_width - off + curwin_col_off2();
+ int width = curwin->w_grid.Columns - off + curwin_col_off2();
/* long line wrapping, adjust curwin->w_wrow */
if (curwin->w_p_wrap
- && col >= (colnr_T)curwin->w_width
+ && col >= (colnr_T)curwin->w_grid.Columns
&& width > 0)
/* use same formula as what is used in curs_columns() */
- col -= ((col - curwin->w_width) / width + 1) * width;
+ col -= ((col - curwin->w_grid.Columns) / width + 1) * width;
if (col > (int)curwin->w_leftcol)
col -= curwin->w_leftcol;
else
@@ -763,20 +764,20 @@ void curs_columns(
*/
curwin->w_wrow = curwin->w_cline_row;
- int textwidth = curwin->w_width - extra;
+ int textwidth = curwin->w_grid.Columns - extra;
if (textwidth <= 0) {
/* No room for text, put cursor in last char of window. */
- curwin->w_wcol = curwin->w_width - 1;
- curwin->w_wrow = curwin->w_height - 1;
+ curwin->w_wcol = curwin->w_grid.Columns - 1;
+ curwin->w_wrow = curwin->w_grid.Rows - 1;
} else if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
width = textwidth + curwin_col_off2();
/* long line wrapping, adjust curwin->w_wrow */
- if (curwin->w_wcol >= curwin->w_width) {
+ if (curwin->w_wcol >= curwin->w_grid.Columns) {
/* this same formula is used in validate_cursor_col() */
- n = (curwin->w_wcol - curwin->w_width) / width + 1;
+ n = (curwin->w_wcol - curwin->w_grid.Columns) / width + 1;
curwin->w_wcol -= n * width;
curwin->w_wrow += n;
@@ -803,7 +804,7 @@ void curs_columns(
assert(p_siso <= INT_MAX);
int off_left = startcol - curwin->w_leftcol - (int)p_siso;
int off_right =
- endcol - curwin->w_leftcol - curwin->w_width + (int)p_siso + 1;
+ endcol - curwin->w_leftcol - curwin->w_grid.Columns + (int)p_siso + 1;
if (off_left < 0 || off_right > 0) {
int diff = (off_left < 0) ? -off_left: off_right;
@@ -846,17 +847,17 @@ void curs_columns(
prev_skipcol = curwin->w_skipcol;
int p_lines = 0;
- if ((curwin->w_wrow >= curwin->w_height
+ if ((curwin->w_wrow >= curwin->w_grid.Rows
|| ((prev_skipcol > 0
- || curwin->w_wrow + p_so >= curwin->w_height)
+ || curwin->w_wrow + p_so >= curwin->w_grid.Rows)
&& (p_lines =
plines_win_nofill
(curwin, curwin->w_cursor.lnum, false))
- - 1 >= curwin->w_height))
- && curwin->w_height != 0
+ - 1 >= curwin->w_grid.Rows))
+ && curwin->w_grid.Rows != 0
&& curwin->w_cursor.lnum == curwin->w_topline
&& width > 0
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
/* Cursor past end of screen. Happens with a single line that does
* not fit on screen. Find a skipcol to show the text around the
@@ -878,19 +879,19 @@ void curs_columns(
}
else
n = p_lines;
- if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width)
+ if ((colnr_T)n >= curwin->w_grid.Rows + curwin->w_skipcol / width)
extra += 2;
if (extra == 3 || p_lines < p_so * 2) {
/* not enough room for 'scrolloff', put cursor in the middle */
n = curwin->w_virtcol / width;
- if (n > curwin->w_height / 2)
- n -= curwin->w_height / 2;
+ if (n > curwin->w_grid.Rows / 2)
+ n -= curwin->w_grid.Rows / 2;
else
n = 0;
/* don't skip more than necessary */
- if (n > p_lines - curwin->w_height + 1)
- n = p_lines - curwin->w_height + 1;
+ if (n > p_lines - curwin->w_grid.Rows + 1)
+ n = p_lines - curwin->w_grid.Rows + 1;
curwin->w_skipcol = n * width;
} else if (extra == 1) {
/* less then 'scrolloff' lines above, decrease skipcol */
@@ -904,7 +905,7 @@ void curs_columns(
}
} else if (extra == 2) {
/* less then 'scrolloff' lines below, increase skipcol */
- endcol = (n - curwin->w_height + 1) * width;
+ endcol = (n - curwin->w_grid.Rows + 1) * width;
while (endcol > curwin->w_virtcol)
endcol -= width;
if (endcol > curwin->w_skipcol)
@@ -912,9 +913,9 @@ void curs_columns(
}
curwin->w_wrow -= curwin->w_skipcol / width;
- if (curwin->w_wrow >= curwin->w_height) {
+ if (curwin->w_wrow >= curwin->w_grid.Rows) {
/* small window, make sure cursor is in it */
- extra = curwin->w_wrow - curwin->w_height + 1;
+ extra = curwin->w_wrow - curwin->w_grid.Rows + 1;
curwin->w_skipcol += extra * width;
curwin->w_wrow -= extra;
}
@@ -956,7 +957,7 @@ scrolldown (
validate_cursor(); /* w_wrow needs to be valid */
while (line_count-- > 0) {
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)
- && curwin->w_topfill < curwin->w_height - 1) {
+ && curwin->w_topfill < curwin->w_grid.Rows - 1) {
++curwin->w_topfill;
++done;
} else {
@@ -991,15 +992,15 @@ scrolldown (
*/
int wrow = curwin->w_wrow;
if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
validate_virtcol();
validate_cheight();
wrow += curwin->w_cline_height - 1 -
- curwin->w_virtcol / curwin->w_width;
+ curwin->w_virtcol / curwin->w_grid.Columns;
}
bool moved = false;
- while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1) {
+ while (wrow >= curwin->w_grid.Rows && curwin->w_cursor.lnum > 1) {
linenr_T first;
if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) {
--wrow;
@@ -1084,12 +1085,12 @@ check_topfill (
{
if (wp->w_topfill > 0) {
int n = plines_win_nofill(wp, wp->w_topline, true);
- if (wp->w_topfill + n > wp->w_height) {
+ if (wp->w_topfill + n > wp->w_grid.Rows) {
if (down && wp->w_topline > 1) {
--wp->w_topline;
wp->w_topfill = 0;
} else {
- wp->w_topfill = wp->w_height - n;
+ wp->w_topfill = wp->w_grid.Rows - n;
if (wp->w_topfill < 0)
wp->w_topfill = 0;
}
@@ -1104,12 +1105,12 @@ check_topfill (
static void max_topfill(void)
{
int n = plines_nofill(curwin->w_topline);
- if (n >= curwin->w_height)
+ if (n >= curwin->w_grid.Rows)
curwin->w_topfill = 0;
else {
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
- if (curwin->w_topfill + n > curwin->w_height)
- curwin->w_topfill = curwin->w_height - n;
+ if (curwin->w_topfill + n > curwin->w_grid.Rows)
+ curwin->w_topfill = curwin->w_grid.Rows - n;
}
}
@@ -1140,14 +1141,14 @@ void scrolldown_clamp(void)
else
end_row += plines_nofill(curwin->w_topline - 1);
if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
validate_cheight();
validate_virtcol();
end_row += curwin->w_cline_height - 1 -
- curwin->w_virtcol / curwin->w_width;
+ curwin->w_virtcol / curwin->w_grid.Columns;
}
- if (end_row < curwin->w_height - p_so) {
+ if (end_row < curwin->w_grid.Rows - p_so) {
if (can_fill) {
++curwin->w_topfill;
check_topfill(curwin, true);
@@ -1182,10 +1183,10 @@ void scrollup_clamp(void)
int start_row = curwin->w_wrow - plines_nofill(curwin->w_topline)
- curwin->w_topfill;
if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
validate_virtcol();
- start_row -= curwin->w_virtcol / curwin->w_width;
+ start_row -= curwin->w_virtcol / curwin->w_grid.Columns;
}
if (start_row >= p_so) {
if (curwin->w_topfill > 0)
@@ -1339,7 +1340,7 @@ void scroll_cursor_top(int min_scroll, int always)
else
used += plines(bot);
}
- if (used > curwin->w_height)
+ if (used > curwin->w_grid.Rows)
break;
if (top < curwin->w_topline)
scrolled += i;
@@ -1362,7 +1363,7 @@ void scroll_cursor_top(int min_scroll, int always)
* This makes sure we get the same position when using "k" and "j"
* in a small window.
*/
- if (used > curwin->w_height) {
+ if (used > curwin->w_grid.Rows) {
scroll_cursor_halfway(false);
} else {
/*
@@ -1399,7 +1400,7 @@ void set_empty_rows(win_T *wp, int used)
if (used == 0)
wp->w_empty_rows = 0; /* single line that doesn't fit */
else {
- wp->w_empty_rows = wp->w_height - used;
+ wp->w_empty_rows = wp->w_grid.Rows - used;
if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) {
wp->w_filler_rows = diff_check_fill(wp, wp->w_botline);
if (wp->w_empty_rows > wp->w_filler_rows)
@@ -1442,7 +1443,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
curwin->w_topline = loff.lnum) {
loff.lnum = curwin->w_topline;
topline_back(&loff);
- if (loff.height == MAXCOL || used + loff.height > curwin->w_height)
+ if (loff.height == MAXCOL || used + loff.height > curwin->w_grid.Rows)
break;
used += loff.height;
curwin->w_topfill = loff.fill;
@@ -1504,7 +1505,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
used = MAXCOL;
else
used += loff.height;
- if (used > curwin->w_height)
+ if (used > curwin->w_grid.Rows)
break;
if (loff.lnum >= curwin->w_botline
&& (loff.lnum > curwin->w_botline
@@ -1522,7 +1523,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
/* Add one line below */
botline_forw(&boff);
used += boff.height;
- if (used > curwin->w_height)
+ if (used > curwin->w_grid.Rows)
break;
if (extra < (
mouse_dragging > 0 ? mouse_dragging - 1 :
@@ -1548,7 +1549,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
if (scrolled <= 0)
line_count = 0;
/* more than a screenfull, don't scroll but redraw */
- else if (used > curwin->w_height)
+ else if (used > curwin->w_grid.Rows)
line_count = used;
/* scroll minimal number of lines */
else {
@@ -1569,7 +1570,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
* Scroll up if the cursor is off the bottom of the screen a bit.
* Otherwise put it at 1/2 of the screen.
*/
- if (line_count >= curwin->w_height && line_count > min_scroll)
+ if (line_count >= curwin->w_grid.Rows && line_count > min_scroll)
scroll_cursor_halfway(false);
else
scrollup(line_count, true);
@@ -1611,7 +1612,7 @@ void scroll_cursor_halfway(int atend)
if (boff.lnum < curbuf->b_ml.ml_line_count) {
botline_forw(&boff);
used += boff.height;
- if (used > curwin->w_height)
+ if (used > curwin->w_grid.Rows)
break;
below += boff.height;
} else {
@@ -1627,7 +1628,7 @@ void scroll_cursor_halfway(int atend)
used = MAXCOL;
else
used += loff.height;
- if (used > curwin->w_height)
+ if (used > curwin->w_grid.Rows)
break;
above += loff.height;
topline = loff.lnum;
@@ -1637,7 +1638,7 @@ void scroll_cursor_halfway(int atend)
if (!hasFolding(topline, &curwin->w_topline, NULL))
curwin->w_topline = topline;
curwin->w_topfill = topfill;
- if (old_topline > curwin->w_topline + curwin->w_height)
+ if (old_topline > curwin->w_topline + curwin->w_grid.Rows)
curwin->w_botfill = false;
check_topfill(curwin, false);
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
@@ -1665,7 +1666,7 @@ void cursor_correct(void)
}
if (curwin->w_topline == 1) {
above_wanted = 0;
- int max_off = curwin->w_height / 2;
+ int max_off = curwin->w_grid.Rows / 2;
if (below_wanted > max_off)
below_wanted = max_off;
}
@@ -1674,7 +1675,7 @@ void cursor_correct(void)
&& mouse_dragging == 0
) {
below_wanted = 0;
- int max_off = (curwin->w_height - 1) / 2;
+ int max_off = (curwin->w_grid.Rows - 1) / 2;
if (above_wanted > max_off)
above_wanted = max_off;
}
@@ -1847,7 +1848,7 @@ int onepage(Direction dir, long count)
/* Find the line just above the new topline to get the right line
* at the bottom of the window. */
n = 0;
- while (n <= curwin->w_height && loff.lnum >= 1) {
+ while (n <= curwin->w_grid.Rows && loff.lnum >= 1) {
topline_back(&loff);
if (loff.height == MAXCOL)
n = MAXCOL;
@@ -1938,7 +1939,7 @@ int onepage(Direction dir, long count)
*/
static void get_scroll_overlap(lineoff_T *lp, int dir)
{
- int min_height = curwin->w_height - 2;
+ int min_height = curwin->w_grid.Rows - 2;
if (lp->fill > 0)
lp->height = 1;
@@ -1993,11 +1994,11 @@ void halfpage(bool flag, linenr_T Prenum)
int i;
if (Prenum)
- curwin->w_p_scr = (Prenum > curwin->w_height) ?
- curwin->w_height : Prenum;
+ curwin->w_p_scr = (Prenum > curwin->w_grid.Rows) ?
+ curwin->w_grid.Rows : Prenum;
assert(curwin->w_p_scr <= INT_MAX);
- int n = curwin->w_p_scr <= curwin->w_height ? (int)curwin->w_p_scr
- : curwin->w_height;
+ int n = curwin->w_p_scr <= curwin->w_grid.Rows ? (int)curwin->w_p_scr
+ : curwin->w_grid.Rows;
update_topline();
validate_botline();
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 4e6c3c4063..28c577034c 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -3906,14 +3906,14 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
col_off1 = curwin_col_off();
col_off2 = col_off1 - curwin_col_off2();
- width1 = curwin->w_width - col_off1;
- width2 = curwin->w_width - col_off2;
+ width1 = curwin->w_grid.Columns - col_off1;
+ width2 = curwin->w_grid.Columns - col_off2;
if (width2 == 0) {
width2 = 1; // Avoid divide by zero.
}
- if (curwin->w_width != 0) {
+ if (curwin->w_grid.Columns != 0) {
/*
* Instead of sticking at the last character of the buffer line we
* try to stick in the last column of the screen.
@@ -4256,7 +4256,7 @@ dozet:
/* "zH" - scroll screen right half-page */
case 'H':
- cap->count1 *= curwin->w_width / 2;
+ cap->count1 *= curwin->w_grid.Columns / 2;
FALLTHROUGH;
/* "zh" - scroll screen to the right */
@@ -4272,7 +4272,7 @@ dozet:
break;
/* "zL" - scroll screen left half-page */
- case 'L': cap->count1 *= curwin->w_width / 2;
+ case 'L': cap->count1 *= curwin->w_grid.Columns / 2;
FALLTHROUGH;
/* "zl" - scroll screen to the left */
@@ -4308,7 +4308,7 @@ dozet:
col = 0; /* like the cursor is in col 0 */
else
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
- n = curwin->w_width - curwin_col_off();
+ n = curwin->w_grid.Columns - curwin_col_off();
if (col + l_p_siso < n)
col = 0;
else
@@ -5018,7 +5018,7 @@ static void nv_scroll(cmdarg_T *cap)
used -= diff_check_fill(curwin, curwin->w_topline)
- curwin->w_topfill;
validate_botline(); /* make sure w_empty_rows is valid */
- half = (curwin->w_height - curwin->w_empty_rows + 1) / 2;
+ half = (curwin->w_grid.Rows - curwin->w_empty_rows + 1) / 2;
for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) {
/* Count half he number of filler lines to be "below this
* line" and half to be "above the next line". */
@@ -5033,7 +5033,7 @@ static void nv_scroll(cmdarg_T *cap)
if (hasFolding(curwin->w_topline + n, NULL, &lnum))
n = lnum - curwin->w_topline;
}
- if (n > 0 && used > curwin->w_height)
+ if (n > 0 && used > curwin->w_grid.Rows)
--n;
} else { /* (cap->cmdchar == 'H') */
n = cap->count1 - 1;
@@ -6748,9 +6748,9 @@ static void nv_g_cmd(cmdarg_T *cap)
oap->motion_type = kMTCharWise;
oap->inclusive = false;
if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
- int width1 = curwin->w_width - curwin_col_off();
+ int width1 = curwin->w_grid.Columns - curwin_col_off();
int width2 = width1 + curwin_col_off2();
validate_virtcol();
@@ -6763,7 +6763,7 @@ static void nv_g_cmd(cmdarg_T *cap)
* 'relativenumber' is on and lines are wrapping the middle can be more
* to the left. */
if (cap->nchar == 'm')
- i += (curwin->w_width - curwin_col_off()
+ i += (curwin->w_grid.Columns - curwin_col_off()
+ ((curwin->w_p_wrap && i > 0)
? curwin_col_off2() : 0)) / 2;
coladvance((colnr_T)i);
@@ -6809,11 +6809,11 @@ static void nv_g_cmd(cmdarg_T *cap)
oap->motion_type = kMTCharWise;
oap->inclusive = true;
if (curwin->w_p_wrap
- && curwin->w_width != 0
+ && curwin->w_grid.Columns != 0
) {
curwin->w_curswant = MAXCOL; /* so we stay at the end */
if (cap->count1 == 1) {
- int width1 = curwin->w_width - col_off;
+ int width1 = curwin->w_grid.Columns - col_off;
int width2 = width1 + curwin_col_off2();
validate_virtcol();
@@ -6839,7 +6839,7 @@ static void nv_g_cmd(cmdarg_T *cap)
} else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false)
clearopbeep(oap);
} else {
- i = curwin->w_leftcol + curwin->w_width - col_off - 1;
+ i = curwin->w_leftcol + curwin->w_grid.Columns - col_off - 1;
coladvance((colnr_T)i);
/* Make sure we stick in this column. */
@@ -7954,7 +7954,7 @@ static void get_op_vcol(
colnr_T end;
if (VIsual_mode != Ctrl_V
- || (!initial && oap->end.col < curwin->w_width)) {
+ || (!initial && oap->end.col < curwin->w_grid.Columns)) {
return;
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 3aaca394f5..f247aa707d 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -118,7 +118,11 @@
#define MB_FILLER_CHAR '<' /* character used when a double-width character
* doesn't fit. */
+
#define W_ENDCOL(wp) (wp->w_width + wp->w_wincol)
+#define W_ENDROW(wp) (wp->w_height + wp->w_winrow)
+
+#define DEFAULT_GRID_HANDLE 1
static match_T search_hl; /* used for 'hlsearch' highlight matching */
@@ -137,10 +141,6 @@ typedef struct {
} LineState;
#define LINE_STATE(p) { p, 0, 0 }
-/// The last handle that was assigned to a ScreenGrid. 1 is reserved for
-/// the default_grid.
-static int last_handle = 1;
-
/// Whether to call "ui_call_grid_resize" in win_grid_alloc
static int send_grid_resize;
@@ -295,11 +295,11 @@ void update_screen(int type)
redraw_tabline = true;
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- if (wp->w_winrow + wp->w_height > valid) {
+ if (W_ENDROW(wp) > valid) {
wp->w_redr_type = NOT_VALID;
wp->w_lines_valid = 0;
}
- if (wp->w_winrow + wp->w_height + wp->w_status_height > valid) {
+ if (W_ENDROW(wp) + wp->w_status_height > valid) {
wp->w_redr_status = true;
}
}
@@ -313,7 +313,7 @@ void update_screen(int type)
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_winrow < msg_scrolled) {
- if (wp->w_winrow + wp->w_height > msg_scrolled
+ if (W_ENDROW(wp) > msg_scrolled
&& wp->w_redr_type < REDRAW_TOP
&& wp->w_lines_valid > 0
&& wp->w_topline == wp->w_lines[0].wl_lnum) {
@@ -321,7 +321,7 @@ void update_screen(int type)
wp->w_redr_type = REDRAW_TOP;
} else {
wp->w_redr_type = NOT_VALID;
- if (wp->w_winrow + wp->w_height + wp->w_status_height
+ if (W_ENDROW(wp) + wp->w_status_height
<= msg_scrolled) {
wp->w_redr_status = TRUE;
}
@@ -705,8 +705,8 @@ static void win_update(win_T *wp)
if (buf->terminal) {
terminal_resize(buf->terminal,
- (uint16_t)(MAX(0, wp->w_width - win_col_off(wp))),
- (uint16_t)wp->w_height);
+ (uint16_t)(MAX(0, wp->w_grid.Columns - win_col_off(wp))),
+ (uint16_t)wp->w_grid.Rows);
}
} else if (buf->b_mod_set
&& buf->b_mod_xlines != 0
@@ -1440,7 +1440,7 @@ static void win_update(win_T *wp)
if (wp->w_p_rnu) {
// 'relativenumber' set: The text doesn't need to be drawn, but
// the number column nearly always does.
- (void)win_line(wp, lnum, srow, wp->w_height, true, true);
+ (void)win_line(wp, lnum, srow, wp->w_grid.Rows, true, true);
}
// This line does not need to be drawn, advance to the next one.
@@ -1501,7 +1501,7 @@ static void win_update(win_T *wp)
wp->w_botline = lnum;
} else if (dy_flags & DY_LASTLINE) { // 'display' has "lastline"
// Last line isn't finished: Display "@@@" at the end.
- grid_fill(&wp->w_grid, wp->w_height - 1, wp->w_height,
+ grid_fill(&wp->w_grid, wp->w_grid.Rows - 1, wp->w_grid.Rows,
wp->w_grid.Columns - 3, wp->w_grid.Columns, '@', '@', at_attr);
set_empty_rows(wp, srow);
wp->w_botline = lnum;
@@ -1531,7 +1531,7 @@ static void win_update(win_T *wp)
// make sure the rest of the screen is blank
// write the 'fill_eob' character to rows that aren't part of the file.
- win_draw_end(wp, fill_eob, ' ', row, wp->w_height, HLF_EOB);
+ win_draw_end(wp, fill_eob, ' ', row, wp->w_grid.Rows, HLF_EOB);
}
if (wp->w_redr_type >= REDRAW_TOP) {
@@ -1611,8 +1611,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h
if (n > 0) {
/* draw the fold column at the right */
- if (n > wp->w_width)
- n = wp->w_width;
+ if (n > wp->w_grid.Columns)
+ n = wp->w_grid.Columns;
grid_fill(&wp->w_grid, row, endrow, wp->w_grid.Columns - n,
wp->w_grid.Columns, ' ', ' ', win_hl_attr(wp, HLF_FC));
}
@@ -1621,8 +1621,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h
int nn = n + win_signcol_width(wp);
/* draw the sign column left of the fold column */
- if (nn > wp->w_width) {
- nn = wp->w_width;
+ if (nn > wp->w_grid.Columns) {
+ nn = wp->w_grid.Columns;
}
grid_fill(&wp->w_grid, row, endrow, wp->w_grid.Columns - nn,
wp->w_grid.Columns - n, ' ', ' ', win_hl_attr(wp, HLF_SC));
@@ -1638,8 +1638,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h
if (cmdwin_type != 0 && wp == curwin) {
/* draw the cmdline character in the leftmost column */
n = 1;
- if (n > wp->w_width)
- n = wp->w_width;
+ if (n > wp->w_grid.Columns)
+ n = wp->w_grid.Columns;
grid_fill(&wp->w_grid, row, endrow, 0, n, cmdwin_type, ' ',
win_hl_attr(wp, HLF_AT));
}
@@ -1647,8 +1647,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h
int nn = n + fdc;
/* draw the fold column at the left */
- if (nn > wp->w_width)
- nn = wp->w_width;
+ if (nn > wp->w_grid.Columns)
+ nn = wp->w_grid.Columns;
grid_fill(&wp->w_grid, row, endrow, n, nn, ' ', ' ',
win_hl_attr(wp, HLF_FC));
n = nn;
@@ -1658,8 +1658,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h
int nn = n + win_signcol_width(wp);
/* draw the sign column after the fold column */
- if (nn > wp->w_width) {
- nn = wp->w_width;
+ if (nn > wp->w_grid.Columns) {
+ nn = wp->w_grid.Columns;
}
grid_fill(&wp->w_grid, row, endrow, n, nn, ' ', ' ',
win_hl_attr(wp, HLF_SC));
@@ -1688,7 +1688,7 @@ static int compute_foldcolumn(win_T *wp, int col)
{
int fdc = wp->w_p_fdc;
int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw;
- int wwidth = wp->w_width;
+ int wwidth = wp->w_grid.Columns;
if (fdc > wwidth - (col + wmw)) {
fdc = wwidth - (col + wmw);
@@ -2680,7 +2680,7 @@ win_line (
// Rightleft window: process the text in the normal direction, but put
// it in grid->ScreenLines[off] from right to left. Start at the
// rightmost column of the window.
- col = wp->w_width - 1;
+ col = grid->Columns - 1;
off += col;
}
@@ -2858,7 +2858,7 @@ win_line (
if (wp->w_p_rl)
n_extra = col + 1;
else
- n_extra = wp->w_width - col;
+ n_extra = grid->Columns - col;
char_attr = win_hl_attr(wp, HLF_DED);
}
if (*p_sbr != NUL && need_showbreak) {
@@ -3129,7 +3129,7 @@ win_line (
* last column. */
if ((
wp->w_p_rl ? (col <= 0) :
- (col >= wp->w_width - 1))
+ (col >= grid->Columns - 1))
&& (*mb_char2cells)(mb_c) == 2) {
c = '>';
mb_c = c;
@@ -3271,7 +3271,7 @@ win_line (
* next line. */
if ((
wp->w_p_rl ? (col <= 0) :
- (col >= wp->w_width - 1))
+ (col >= grid->Columns - 1))
&& (*mb_char2cells)(mb_c) == 2) {
c = '>';
mb_c = c;
@@ -3445,7 +3445,7 @@ win_line (
char_u *p = ptr - (mb_off + 1);
// TODO: is passing p for start of the line OK?
n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1;
- if (c == TAB && n_extra + col > wp->w_width) {
+ if (c == TAB && n_extra + col > grid->Columns) {
n_extra = (int)wp->w_buffer->b_p_ts
- vcol % (int)wp->w_buffer->b_p_ts - 1;
}
@@ -3604,7 +3604,7 @@ win_line (
&& VIsual_mode != Ctrl_V
&& (
wp->w_p_rl ? (col >= 0) :
- (col < wp->w_width))
+ (col < grid->Columns))
&& !(noinvcur
&& lnum == wp->w_cursor.lnum
&& (colnr_T)vcol == wp->w_virtcol)))
@@ -3676,7 +3676,7 @@ win_line (
&& vcol < tocol
&& (
wp->w_p_rl ? (col >= 0) :
- (col < wp->w_width))) {
+ (col < grid->Columns))) {
c = ' ';
ptr--; // put it back at the NUL
}
@@ -3746,7 +3746,7 @@ win_line (
&& conceal_cursor_line(wp)
&& (int)wp->w_virtcol <= vcol + n_skip) {
if (wp->w_p_rl) {
- wp->w_wcol = wp->w_width - col + boguscols - 1;
+ wp->w_wcol = grid->Columns - col + boguscols - 1;
} else {
wp->w_wcol = col - boguscols;
}
@@ -3834,7 +3834,7 @@ win_line (
if (col < 0)
n = 1;
} else {
- if (col >= wp->w_width)
+ if (col >= grid->Columns)
n = -1;
}
if (n != 0) {
@@ -3907,7 +3907,7 @@ win_line (
if (((wp->w_p_cuc
&& (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
&& (int)wp->w_virtcol <
- wp->w_width * (row - startrow + 1) + v
+ grid->Columns * (row - startrow + 1) + v
&& lnum != wp->w_cursor.lnum)
|| draw_color_col || line_attr_lowprio || line_attr
|| diff_hlf != (hlf_T)0 || do_virttext)) {
@@ -3955,7 +3955,7 @@ win_line (
int col_stride = wp->w_p_rl ? -1 : 1;
- while (wp->w_p_rl ? col >= 0 : col < wp->w_width) {
+ while (wp->w_p_rl ? col >= 0 : col < grid->Columns) {
int cells = -1;
if (do_virttext && !delay_virttext) {
if (*s.p == NUL) {
@@ -3969,7 +3969,7 @@ win_line (
}
}
if (*s.p != NUL) {
- cells = line_putchar(&s, &grid->ScreenLines[off], wp->w_width - col,
+ cells = line_putchar(&s, &grid->ScreenLines[off], grid->Columns - col,
false);
}
}
@@ -3998,9 +3998,9 @@ win_line (
attr = hl_combine_attr(attr, line_attr);
- ScreenAttrs[off] = attr;
+ grid->ScreenAttrs[off] = attr;
if (cells == 2) {
- ScreenAttrs[off+1] = attr;
+ grid->ScreenAttrs[off+1] = attr;
}
off += cells * col_stride;
@@ -4017,7 +4017,7 @@ win_line (
if (wp->w_buffer->terminal) {
// terminal buffers may need to highlight beyond the end of the
// logical line
- while (col < wp->w_width) {
+ while (col < grid->Columns) {
schar_from_ascii(grid->ScreenLines[off], ' ');
grid->ScreenAttrs[off++] = term_attrs[vcol++];
col++;
@@ -4047,7 +4047,7 @@ win_line (
&& filler_todo <= 0
&& (
wp->w_p_rl ? col == 0 :
- col == wp->w_width - 1)
+ col == grid->Columns - 1)
&& (*ptr != NUL
|| (wp->w_p_list && lcs_eol_one > 0)
|| (n_extra && (c_extra != NUL || *p_extra != NUL)))) {
@@ -4227,7 +4227,7 @@ win_line (
*/
if ((
wp->w_p_rl ? (col < 0) :
- (col >= wp->w_width))
+ (col >= grid->Columns))
&& (*ptr != NUL
|| filler_todo > 0
|| (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
@@ -4276,7 +4276,7 @@ win_line (
col = 0;
off = (unsigned)(grid->Rows * grid->Columns);
if (wp->w_p_rl) {
- col = wp->w_width - 1; /* col is not used if breaking! */
+ col = grid->Columns - 1; /* col is not used if breaking! */
off += col;
}
@@ -4586,7 +4586,7 @@ static void draw_vsep_win(win_T *wp, int row)
if (wp->w_vsep_width) {
// draw the vertical separator right of this window
c = fillchar_vsep(wp, &hl);
- grid_fill(&default_grid, wp->w_winrow + row, wp->w_winrow + wp->w_height,
+ grid_fill(&default_grid, wp->w_winrow + row, W_ENDROW(wp),
W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
}
}
@@ -4905,7 +4905,7 @@ static void win_redr_status(win_T *wp, int ignore_pum)
}
}
- row = wp->w_winrow + wp->w_height;
+ row = W_ENDROW(wp);
grid_puts(&default_grid, p, row, wp->w_wincol, attr);
grid_fill(&default_grid, row, row + 1, len + wp->w_wincol,
this_ru_col + wp->w_wincol, fillchar, fillchar, attr);
@@ -4927,8 +4927,7 @@ static void win_redr_status(win_T *wp, int ignore_pum)
} else {
fillchar = fillchar_vsep(wp, &attr);
}
- grid_putchar(&default_grid, fillchar, wp->w_winrow + wp->w_height,
- W_ENDCOL(wp), attr);
+ grid_putchar(&default_grid, fillchar, W_ENDROW(wp), W_ENDCOL(wp), attr);
}
busy = FALSE;
}
@@ -5075,7 +5074,7 @@ win_redr_custom (
maxwidth = default_grid.Columns;
use_sandbox = was_set_insecurely((char_u *)"tabline", 0);
} else {
- row = wp->w_winrow + wp->w_height;
+ row = W_ENDROW(wp);
fillchar = fillchar_status(&attr, wp);
maxwidth = wp->w_width;
@@ -5834,7 +5833,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col,
}
}
- if (end_col == Columns) {
+ if (end_col == grid->Columns) {
grid->LineWraps[row] = false;
}
@@ -5886,25 +5885,51 @@ int screen_valid(int doclear)
// TODO(utkarshme): Think of a better name, place
void win_grid_alloc(win_T *wp, int doclear)
{
- if (wp->w_grid.ScreenLines == NULL
- || wp->w_grid.Rows != wp->w_height
- || wp->w_grid.Columns != wp->w_width) {
- grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear);
+ ScreenGrid *grid = &wp->w_grid;
+ int rows = grid->internal_rows;
+ int columns = grid->internal_columns;
+ int was_resized = 0;
- // only assign a grid handle if not already
- if (wp->w_grid.handle == 0) {
- wp->w_grid.handle = ++last_handle;
- }
+ if (rows == 0) {
+ rows = wp->w_height;
+ }
+ if (columns == 0) {
+ columns = wp->w_width;
+ }
+
+ if (grid->ScreenLines == NULL
+ || grid->Rows != rows
+ || grid->Columns != columns) {
+ grid_alloc(grid, rows, columns, doclear);
+ win_free_lsize(wp);
+ win_alloc_lines(wp);
+ was_resized = true;
+ }
+
+ grid->OffsetRow = wp->w_winrow;
+ grid->OffsetColumn = wp->w_wincol;
- wp->w_grid.OffsetRow = wp->w_winrow;
- wp->w_grid.OffsetColumn = wp->w_wincol;
+ grid_assign_handle(grid);
- wp->w_grid.was_resized = true;
+ // send grid resize event if:
+ // - a grid was just resized
+ // - screen_resize was called and all grid sizes must be sent
+ // - the UI wants multigrid event (necessary)
+ if ((send_grid_resize || was_resized)
+ && ui_is_external(kUIMultigrid)) {
+ ui_call_grid_resize(grid->handle, grid->Columns, grid->Rows);
+ was_resized = false;
}
+}
+
+/// assign a handle to the grid. The grid need not be allocated.
+void grid_assign_handle(ScreenGrid *grid)
+{
+ static int last_grid_handle = DEFAULT_GRID_HANDLE;
- if (send_grid_resize || wp->w_grid.was_resized) {
- ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows);
- wp->w_grid.was_resized = false;
+ // only assign a grid handle if not already
+ if (grid->handle == 0) {
+ grid->handle = ++last_grid_handle;
}
}
@@ -5999,7 +6024,7 @@ retry:
default_grid.OffsetRow = 0;
default_grid.OffsetColumn = 0;
- default_grid.handle = 1;
+ default_grid.handle = DEFAULT_GRID_HANDLE;
must_redraw = CLEAR; /* need to clear the screen later */
if (doclear)
@@ -6170,7 +6195,7 @@ void setcursor(void)
if (curwin->w_p_rl) {
// With 'rightleft' set and the cursor on a double-wide character,
// position it on the leftmost column.
- left_offset = curwin->w_width - curwin->w_wcol
+ left_offset = curwin->w_grid.Columns - curwin->w_wcol
- ((utf_ptr2cells(get_cursor_pos_ptr()) == 2
&& vim_isprintc(gchar_cursor())) ? 2 : 1);
}
@@ -6212,10 +6237,10 @@ static int win_do_lines(win_T *wp, int row, int line_count, int del)
int retval;
if (del) {
retval = grid_del_lines(&wp->w_grid, row, line_count,
- wp->w_height, 0, wp->w_width);
+ wp->w_grid.Rows, 0, wp->w_grid.Columns);
} else {
retval = grid_ins_lines(&wp->w_grid, row, line_count,
- wp->w_height, 0, wp->w_width);
+ wp->w_grid.Rows, 0, wp->w_grid.Columns);
}
return retval;
}
@@ -6232,9 +6257,11 @@ static int win_do_lines(win_T *wp, int row, int line_count, int del)
/// insert lines on the screen and update ScreenLines[]
+/// 'line_count' is the number of lines to be inserted.
/// 'end' is the line after the scrolled part. Normally it is Rows.
-/// When scrolling region used 'off' is the offset from the top for the region.
-/// 'row' and 'end' are relative to the start of the region.
+/// 'col' is the column from with we start inserting.
+//
+/// 'row', 'col' and 'end' are relative to the start of the region.
///
/// @return FAIL for failure, OK for success.
int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
@@ -6915,7 +6942,7 @@ static void win_redr_ruler(win_T *wp, int always)
int off;
if (wp->w_status_height) {
- row = wp->w_winrow + wp->w_height;
+ row = W_ENDROW(wp);
fillchar = fillchar_status(&attr, wp);
off = wp->w_wincol;
width = wp->w_width;
@@ -7168,3 +7195,13 @@ void win_new_shellsize(void)
shell_new_columns(); // update window sizes
}
}
+
+win_T * get_win_by_grid_handle(GridHandle handle)
+{
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (wp->w_grid.handle == handle) {
+ return wp;
+ }
+ }
+ return NULL;
+}
diff --git a/src/nvim/search.c b/src/nvim/search.c
index f31ec7170b..e6243ad5ba 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -2167,7 +2167,7 @@ showmatch(
getvcol(curwin, lpos, NULL, &vcol, NULL);
}
if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol
- && vcol < curwin->w_leftcol + curwin->w_width)) {
+ && vcol < curwin->w_leftcol + curwin->w_grid.Columns)) {
mpos = *lpos; /* save the pos, update_screen() may change it */
save_cursor = curwin->w_cursor;
save_so = p_so;
diff --git a/src/nvim/types.h b/src/nvim/types.h
index aa83bc04bf..aa4332fad1 100644
--- a/src/nvim/types.h
+++ b/src/nvim/types.h
@@ -40,7 +40,9 @@ typedef struct {
int OffsetRow;
int OffsetColumn;
- int was_resized;
+ // the size expected to be allocated to the internal grid
+ int internal_rows;
+ int internal_columns;
} ScreenGrid;
#endif // NVIM_TYPES_H
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index a454afad24..968c3b7b16 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -57,7 +57,7 @@ static int busy = 0;
static int mode_idx = SHAPE_IDX_N;
static bool pending_mode_info_update = false;
static bool pending_mode_update = false;
-static GridHandle cursor_grid_handle = 1;
+static GridHandle cursor_grid_handle = DEFAULT_GRID_HANDLE;
#if MIN_LOG_LEVEL > DEBUG_LOG_LEVEL
# define UI_LOG(funname, ...)
@@ -197,13 +197,6 @@ void ui_refresh(void)
row = col = 0;
pending_cursor_update = true;
- ui_default_colors_set();
-
- int save_p_lz = p_lz;
- p_lz = false; // convince redrawing() to return true ...
- screen_resize(width, height);
- p_lz = save_p_lz;
-
for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
ui_ext[i] = ext_widgets[i];
if (i < kUIGlobalCount) {
@@ -211,6 +204,14 @@ void ui_refresh(void)
BOOLEAN_OBJ(ext_widgets[i]));
}
}
+
+ ui_default_colors_set();
+
+ int save_p_lz = p_lz;
+ p_lz = false; // convince redrawing() to return true ...
+ screen_resize(width, height);
+ p_lz = save_p_lz;
+
ui_mode_info_set();
pending_mode_update = true;
ui_cursor_shape();
@@ -437,3 +438,18 @@ Array ui_array(void)
}
return all_uis;
}
+
+void ui_grid_resize(GridHandle grid_handle, int width, int height)
+{
+ win_T *wp = get_win_by_grid_handle(grid_handle);
+
+ if (wp == NULL) {
+ //TODO(utkarshme): error out
+ abort();
+ return;
+ }
+
+ wp->w_grid.internal_rows = (int)height;
+ wp->w_grid.internal_columns = (int)width;
+ redraw_win_later(wp, SOME_VALID);
+}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 4d2b238b7a..5153bfadda 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -3860,6 +3860,8 @@ static win_T *win_alloc(win_T *after, int hidden)
new_wp->handle = ++last_win_id;
handle_register_window(new_wp);
+ grid_assign_handle(&new_wp->w_grid);
+
// Init w: variables.
new_wp->w_vars = tv_dict_alloc();
init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE);
@@ -4087,8 +4089,8 @@ static void frame_remove(frame_T *frp)
void win_alloc_lines(win_T *wp)
{
wp->w_lines_valid = 0;
- assert(Rows >= 0);
- wp->w_lines = xcalloc(Rows, sizeof(wline_T));
+ assert(wp->w_grid.Rows >= 0);
+ wp->w_lines = xcalloc(wp->w_grid.Rows + 1, sizeof(wline_T));
}
/*