From d9406f4b643843160ed3e9ffe4331169dbccb135 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 25 Jan 2019 16:43:02 +0100 Subject: terminal: simplify sizing logic --- src/nvim/window.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index a2e3825274..f88b36615a 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5026,7 +5026,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) invalidate_botline_win(wp); 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); } } @@ -5048,8 +5049,8 @@ void win_new_width(win_T *wp, int width) wp->w_width = width; // TODO(bfredl): refactor this. There should be some variable // wp->w_inner_width which always contains the final actual width. - // Alternatively use wp->w_width for this and introduce wp->w_outer_width - // Then use this to fix terminal_resize. + // Alternatively use wp->w_width for this and introduce wp->w_outer_width. + // Then use this to fix terminal_check_size. if (!ui_is_external(kUIMultigrid) || wp->w_grid.requested_cols == 0) { 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_height != 0) { - terminal_resize(wp->w_buffer->terminal, - (uint16_t)(MAX(0, wp->w_width - win_col_off(wp))), - 0); + terminal_check_size(wp->w_buffer->terminal); } } wp->w_pos_changed = true; -- cgit From 2ab70cb55c80b17fb4100dd7f2d056131c02b08b Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 25 Jan 2019 18:44:29 +0100 Subject: window/ui: reorganize size variables, fix terminal window size with multigrid. wp->w_height_inner now contains the "inner" size, regardless if the window has been drawn yet or not. It should be used instead of wp->w_grid.Rows, for stuff that is not directly related to accessing the allocated grid memory, such like cursor movement and terminal size --- src/nvim/window.c | 144 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 68 deletions(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index f88b36615a..36d780a661 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3025,8 +3025,10 @@ static void new_frame(win_T *wp) void win_init_size(void) { firstwin->w_height = ROWS_AVAIL; + firstwin->w_height_inner = firstwin->w_height; topframe->fr_height = ROWS_AVAIL; firstwin->w_width = Columns; + firstwin->w_width_inner = firstwin->w_width; topframe->fr_width = Columns; } @@ -4123,8 +4125,10 @@ static void frame_remove(frame_T *frp) void win_alloc_lines(win_T *wp) { wp->w_lines_valid = 0; - assert(wp->w_grid.Rows >= 0); - wp->w_lines = xcalloc(MAX(wp->w_grid.Rows + 1, Rows), sizeof(wline_T)); + assert(wp->w_height_inner >= 0); + // TODO(bfredl) :this should work, add call to win_set_inner_size? + // wp->w_lines = xcalloc(wp->w_height_inner+1, sizeof(wline_T)); + wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T)); } /* @@ -4876,9 +4880,9 @@ void win_drag_vsep_line(win_T *dragwin, int offset) // Has no effect when the window is less than two lines. void set_fraction(win_T *wp) { - if (wp->w_height > 1) { - wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT + wp->w_height / 2) - / (long)wp->w_height; + if (wp->w_height_inner > 1) { + wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT + wp->w_height_inner / 2) + / (long)wp->w_height_inner; } } @@ -4889,46 +4893,25 @@ void set_fraction(win_T *wp) */ void win_new_height(win_T *wp, int height) { - int prev_height = wp->w_height; - - /* Don't want a negative height. Happens when splitting a tiny window. - * Will equalize heights soon to fix it. */ - if (height < 0) + // Don't want a negative height. Happens when splitting a tiny window. + // Will equalize heights soon to fix it. + if (height < 0) { height = 0; - if (wp->w_height == height) - return; /* nothing to do */ - - if (wp->w_height > 0) { - if (wp == curwin) { - // w_wrow needs to be valid. When setting 'laststatus' this may - // call win_new_height() recursively. - validate_cursor(); - } - if (wp->w_height != prev_height) { // -V547 - return; // Recursive call already changed the size, bail out. - } - if (wp->w_wrow != wp->w_prev_fraction_row) { - set_fraction(wp); - } } - - wp->w_height = height; - wp->w_skipcol = 0; - - // There is no point in adjusting the scroll position when exiting. Some - // values might be invalid. - if (!exiting) { - scroll_to_fraction(wp, prev_height); + if (wp->w_height == height) { + return; // nothing to do } + wp->w_height = height; wp->w_pos_changed = true; + win_set_inner_size(wp); } void scroll_to_fraction(win_T *wp, int prev_height) { linenr_T lnum; int sline, line_size; - int height = wp->w_height; + int height = wp->w_height_inner; /* Don't change w_topline when height is zero. Don't set w_topline when * 'scrollbind' is set and this isn't the current window. */ @@ -4951,8 +4934,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) // Make sure the whole cursor line is visible, if possible. const int rows = plines_win(wp, lnum, false); - if (sline > wp->w_height - rows) { - sline = wp->w_height - rows; + if (sline > wp->w_height_inner - rows) { + sline = wp->w_height_inner - rows; wp->w_wrow -= rows - line_size; } } @@ -4964,14 +4947,14 @@ void scroll_to_fraction(win_T *wp, int prev_height) * room use w_skipcol; */ wp->w_wrow = line_size; - if (wp->w_wrow >= wp->w_height - && (wp->w_width - win_col_off(wp)) > 0) { - wp->w_skipcol += wp->w_width - win_col_off(wp); - --wp->w_wrow; - while (wp->w_wrow >= wp->w_height) { - wp->w_skipcol += wp->w_width - win_col_off(wp) + if (wp->w_wrow >= wp->w_height_inner + && (wp->w_width_inner - win_col_off(wp)) > 0) { + wp->w_skipcol += wp->w_width_inner - win_col_off(wp); + wp->w_wrow--; + while (wp->w_wrow >= wp->w_height_inner) { + wp->w_skipcol += wp->w_width_inner - win_col_off(wp) + win_col_off2(wp); - --wp->w_wrow; + wp->w_wrow--; } } set_topline(wp, lnum); @@ -5024,22 +5007,58 @@ void scroll_to_fraction(win_T *wp, int prev_height) redraw_win_later(wp, SOME_VALID); wp->w_redr_status = TRUE; invalidate_botline_win(wp); - - if (wp->w_buffer->terminal) { - terminal_check_size(wp->w_buffer->terminal); - // TODO: terminal should this itself: - redraw_win_later(wp, NOT_VALID); - } } -void win_inner_width_changed(win_T *wp) +void win_set_inner_size(win_T *wp) { - wp->w_lines_valid = 0; - changed_line_abv_curs_win(wp); - invalidate_botline_win(wp); - if (wp == curwin) { - update_topline(); - curs_columns(TRUE); /* validate w_wrow */ + int width = wp->w_width_request; + if (width == 0) { + width = wp->w_width; + } + + int prev_height = wp->w_height_inner; + int height = wp->w_height_request; + if (height == 0) { + height = wp->w_height; + } + + if (height != prev_height) { + if (height > 0) { + if (wp == curwin) { + // w_wrow needs to be valid. When setting 'laststatus' this may + // call win_new_height() recursively. + validate_cursor(); + } + if (wp->w_height_inner != prev_height) { // -V547 + return; // Recursive call already changed the size, bail out. + } + if (wp->w_wrow != wp->w_prev_fraction_row) { + set_fraction(wp); + } + } + wp->w_height_inner = height; + wp->w_skipcol = 0; + + // There is no point in adjusting the scroll position when exiting. Some + // values might be invalid. + if (!exiting) { + scroll_to_fraction(wp, prev_height); + } + } + + if (width != wp->w_width_inner) { + wp->w_width_inner = width; + wp->w_lines_valid = 0; + changed_line_abv_curs_win(wp); + invalidate_botline_win(wp); + if (wp == curwin) { + update_topline(); + curs_columns(true); // validate w_wrow + } + } + + if (wp->w_buffer->terminal) { + terminal_check_size(wp->w_buffer->terminal); } } @@ -5047,22 +5066,11 @@ void win_inner_width_changed(win_T *wp) void win_new_width(win_T *wp, int width) { wp->w_width = width; - // TODO(bfredl): refactor this. There should be some variable - // wp->w_inner_width which always contains the final actual width. - // Alternatively use wp->w_width for this and introduce wp->w_outer_width. - // Then use this to fix terminal_check_size. - if (!ui_is_external(kUIMultigrid) || wp->w_grid.requested_cols == 0) { - win_inner_width_changed(wp); - } + win_set_inner_size(wp); redraw_win_later(wp, NOT_VALID); wp->w_redr_status = TRUE; - if (wp->w_buffer->terminal) { - if (wp->w_height != 0) { - terminal_check_size(wp->w_buffer->terminal); - } - } wp->w_pos_changed = true; } -- cgit From 30bd1c1e85d2fcffa24a87803bec3070e52c7c7e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 26 Jan 2019 12:37:38 +0100 Subject: terminal: handle size when switching buffers in window --- src/nvim/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 36d780a661..0edb04f028 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4126,7 +4126,7 @@ void win_alloc_lines(win_T *wp) { wp->w_lines_valid = 0; assert(wp->w_height_inner >= 0); - // TODO(bfredl) :this should work, add call to win_set_inner_size? + // TODO(bfredl): this should work, add call to win_set_inner_size? // wp->w_lines = xcalloc(wp->w_height_inner+1, sizeof(wline_T)); wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T)); } -- cgit From de16c0bf6445f92f2b6e92ba3253d581e5562178 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 26 Jan 2019 18:14:53 +0100 Subject: screen: simplify wp->w_lines allocation logic --- src/nvim/window.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 0edb04f028..91a983e4c7 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3891,7 +3891,6 @@ static win_T *win_alloc(win_T *after, int hidden) // allocate window structure and linesizes arrays win_T *new_wp = xcalloc(1, sizeof(win_T)); - win_alloc_lines(new_wp); new_wp->handle = ++last_win_id; handle_register_window(new_wp); @@ -3972,7 +3971,7 @@ win_free ( } } - win_free_lsize(wp); + xfree(wp->w_lines); for (i = 0; i < wp->w_tagstacklen; ++i) xfree(wp->w_tagstack[i].tagname); @@ -4119,30 +4118,6 @@ static void frame_remove(frame_T *frp) } -/* - * Allocate w_lines[] for window "wp". - */ -void win_alloc_lines(win_T *wp) -{ - wp->w_lines_valid = 0; - assert(wp->w_height_inner >= 0); - // TODO(bfredl): this should work, add call to win_set_inner_size? - // wp->w_lines = xcalloc(wp->w_height_inner+1, sizeof(wline_T)); - wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T)); -} - -/* - * free lsize arrays for a window - */ -void win_free_lsize(win_T *wp) -{ - // TODO: why would wp be NULL here? - if (wp != NULL) { - xfree(wp->w_lines); - wp->w_lines = NULL; - } -} - /* * Called from win_new_shellsize() after Rows changed. * This only does the current tab page, others must be done when made active. -- cgit