mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 03:28:33 +00:00
terminal: simplify sizing logic
This commit is contained in:
@@ -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) {
|
||||
// TODO: WTF does this mean:
|
||||
// If two windows display the same terminal and one is closed by keypress.
|
||||
return;
|
||||
}
|
||||
bool force = width == UINT16_MAX || height == UINT16_MAX;
|
||||
int curwidth, curheight;
|
||||
vterm_get_size(term->vt, &curheight, &curwidth);
|
||||
uint16_t width = 0, height = 0;
|
||||
|
||||
if (force || !width) {
|
||||
width = (uint16_t)curwidth;
|
||||
}
|
||||
|
||||
if (force || !height) {
|
||||
height = (uint16_t)curheight;
|
||||
}
|
||||
|
||||
if (!force && curheight == height && curwidth == width) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (height == 0 || width == 0) {
|
||||
return;
|
||||
}
|
||||
bool window_seen = false;
|
||||
|
||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||
if (wp->w_buffer && wp->w_buffer->terminal == term) {
|
||||
window_seen = true;
|
||||
const uint16_t win_width =
|
||||
(uint16_t)(MAX(0, wp->w_width - win_col_off(wp)));
|
||||
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_screen_flush_damage(term->vts);
|
||||
term->pending_resize = true;
|
||||
@@ -383,8 +375,10 @@ void terminal_enter(void)
|
||||
memset(s, 0, sizeof(TerminalState));
|
||||
s->term = buf->terminal;
|
||||
|
||||
// Ensure the terminal is properly sized.
|
||||
terminal_resize(s->term, 0, 0);
|
||||
// Ensure the terminal is properly sized. Ideally window size management
|
||||
// code should always have resized the terminal already, but check here to
|
||||
// be sure.
|
||||
terminal_check_size(s->term);
|
||||
|
||||
int save_state = State;
|
||||
s->save_rd = RedrawingDisabled;
|
||||
|
Reference in New Issue
Block a user