terminal: simplify sizing logic

This commit is contained in:
Björn Linse
2019-01-25 16:43:02 +01:00
parent f2398a766e
commit d9406f4b64
4 changed files with 20 additions and 29 deletions

View File

@@ -4339,7 +4339,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
} else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) {
if (curbuf->terminal) { if (curbuf->terminal) {
// Force the scrollback to take effect. // Force the scrollback to take effect.
terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX); terminal_check_size(curbuf->terminal);
} }
} else if (pp == &curwin->w_p_nuw) { } else if (pp == &curwin->w_p_nuw) {
curwin->w_nrwidth_line_count = 0; curwin->w_nrwidth_line_count = 0;

View File

@@ -629,9 +629,7 @@ static void win_update(win_T *wp)
wp->w_nrwidth = i; wp->w_nrwidth = i;
if (buf->terminal) { if (buf->terminal) {
terminal_resize(buf->terminal, terminal_check_size(buf->terminal);
(uint16_t)(MAX(0, wp->w_grid.Columns - win_col_off(wp))),
(uint16_t)wp->w_grid.Rows);
} }
} else if (buf->b_mod_set } else if (buf->b_mod_set
&& buf->b_mod_xlines != 0 && buf->b_mod_xlines != 0

View File

@@ -334,34 +334,22 @@ void terminal_close(Terminal *term, char *msg)
} }
} }
void terminal_resize(Terminal *term, uint16_t width, uint16_t height) void terminal_check_size(Terminal *term)
{ {
if (term->closed) { if (term->closed) {
// TODO: WTF does this mean:
// If two windows display the same terminal and one is closed by keypress. // If two windows display the same terminal and one is closed by keypress.
return; return;
} }
bool force = width == UINT16_MAX || height == UINT16_MAX;
int curwidth, curheight; int curwidth, curheight;
vterm_get_size(term->vt, &curheight, &curwidth); vterm_get_size(term->vt, &curheight, &curwidth);
uint16_t width = 0, height = 0;
if (force || !width) { bool window_seen = false;
width = (uint16_t)curwidth;
}
if (force || !height) {
height = (uint16_t)curheight;
}
if (!force && curheight == height && curwidth == width) {
return;
}
if (height == 0 || width == 0) {
return;
}
FOR_ALL_TAB_WINDOWS(tp, wp) { FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer && wp->w_buffer->terminal == term) { if (wp->w_buffer && wp->w_buffer->terminal == term) {
window_seen = true;
const uint16_t win_width = const uint16_t win_width =
(uint16_t)(MAX(0, wp->w_width - win_col_off(wp))); (uint16_t)(MAX(0, wp->w_width - win_col_off(wp)));
width = MAX(width, win_width); width = MAX(width, win_width);
@@ -369,6 +357,10 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height)
} }
} }
if ((curheight == height && curwidth == width) || height == 0 || width == 0) {
return;
}
vterm_set_size(term->vt, height, width); vterm_set_size(term->vt, height, width);
vterm_screen_flush_damage(term->vts); vterm_screen_flush_damage(term->vts);
term->pending_resize = true; term->pending_resize = true;
@@ -383,8 +375,10 @@ void terminal_enter(void)
memset(s, 0, sizeof(TerminalState)); memset(s, 0, sizeof(TerminalState));
s->term = buf->terminal; s->term = buf->terminal;
// Ensure the terminal is properly sized. // Ensure the terminal is properly sized. Ideally window size management
terminal_resize(s->term, 0, 0); // code should always have resized the terminal already, but check here to
// be sure.
terminal_check_size(s->term);
int save_state = State; int save_state = State;
s->save_rd = RedrawingDisabled; s->save_rd = RedrawingDisabled;

View File

@@ -5026,7 +5026,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
invalidate_botline_win(wp); invalidate_botline_win(wp);
if (wp->w_buffer->terminal) { if (wp->w_buffer->terminal) {
terminal_resize(wp->w_buffer->terminal, 0, wp->w_height); terminal_check_size(wp->w_buffer->terminal);
// TODO: terminal should this itself:
redraw_win_later(wp, NOT_VALID); redraw_win_later(wp, NOT_VALID);
} }
} }
@@ -5048,8 +5049,8 @@ void win_new_width(win_T *wp, int width)
wp->w_width = width; wp->w_width = width;
// TODO(bfredl): refactor this. There should be some variable // TODO(bfredl): refactor this. There should be some variable
// wp->w_inner_width which always contains the final actual width. // wp->w_inner_width which always contains the final actual width.
// Alternatively use wp->w_width for this and introduce wp->w_outer_width // Alternatively use wp->w_width for this and introduce wp->w_outer_width.
// Then use this to fix terminal_resize. // Then use this to fix terminal_check_size.
if (!ui_is_external(kUIMultigrid) || wp->w_grid.requested_cols == 0) { if (!ui_is_external(kUIMultigrid) || wp->w_grid.requested_cols == 0) {
win_inner_width_changed(wp); win_inner_width_changed(wp);
} }
@@ -5059,9 +5060,7 @@ void win_new_width(win_T *wp, int width)
if (wp->w_buffer->terminal) { if (wp->w_buffer->terminal) {
if (wp->w_height != 0) { if (wp->w_height != 0) {
terminal_resize(wp->w_buffer->terminal, terminal_check_size(wp->w_buffer->terminal);
(uint16_t)(MAX(0, wp->w_width - win_col_off(wp))),
0);
} }
} }
wp->w_pos_changed = true; wp->w_pos_changed = true;