From 49d239fdf9a2e2d23239d1e1dd255b7526de1e83 Mon Sep 17 00:00:00 2001 From: Corentin SORIANO Date: Wed, 5 Nov 2025 20:19:02 +0100 Subject: [PATCH 1/2] GUACAMOLE-2158: Increase terminal buffer length only if new rows are being added. --- src/terminal/buffer.c | 12 ++++++++---- src/terminal/terminal.c | 6 +++--- src/terminal/terminal/buffer.h | 7 ++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/terminal/buffer.c b/src/terminal/buffer.c index 995ce3295e..bd6ad4f768 100644 --- a/src/terminal/buffer.c +++ b/src/terminal/buffer.c @@ -427,16 +427,20 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer, } -void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount) { +void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount, + bool increase_length) { if (amount <= 0) return; buffer->top = (buffer->top + amount) % buffer->available; - buffer->length += amount; - if (buffer->length > buffer->available) - buffer->length = buffer->available; + /* Increase buffer length only if new row is added */ + if (increase_length) { + buffer->length += amount; + if (buffer->length > buffer->available) + buffer->length = buffer->available; + } } diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 27a2bf84a4..e639fd6222 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -834,8 +834,8 @@ void guac_terminal_scroll_up(guac_terminal* term, /* Scroll up visibly */ guac_terminal_display_copy_rows(term->display, start_row + amount, end_row, -amount); - /* Advance by scroll amount */ - guac_terminal_buffer_scroll_up(term->current_buffer, amount); + /* Advance and increase buffer length by scroll amount */ + guac_terminal_buffer_scroll_up(term->current_buffer, amount, true); /* Reset scrollbar bounds */ guac_terminal_scrollbar_set_bounds(term->scrollbar, @@ -1225,7 +1225,7 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) { shift_amount, term->display->height - 1, -shift_amount); /* Update buffer top and cursor row based on shift */ - guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount); + guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount, false); term->cursor_row -= shift_amount; if (term->visible_cursor_row != -1) term->visible_cursor_row -= shift_amount; diff --git a/src/terminal/terminal/buffer.h b/src/terminal/terminal/buffer.h index 9f175ba140..f27af74f8c 100644 --- a/src/terminal/terminal/buffer.h +++ b/src/terminal/terminal/buffer.h @@ -91,8 +91,13 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer, * @param amount * The number of rows to scroll upwards. Zero and negative values have no * effect. + * + * @param increase_length + * Whether the length of the buffer should be increased to account for + * newly added rows. If false, the length of the buffer remains unchanged. */ -void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount); +void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount, + bool increase_length); /** * Scrolls the contents of the given buffer down by the given number of rows. From c71e1dbcb124b4a39849665f96a62092c46e05a4 Mon Sep 17 00:00:00 2001 From: Corentin SORIANO Date: Wed, 5 Nov 2025 21:38:52 +0100 Subject: [PATCH 2/2] GUACAMOLE-2158: Redraw the content below the scroll after enlarging the terminal. --- src/terminal/terminal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index e639fd6222..0600df51ea 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -1296,6 +1296,10 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) { /* Draw characters at top from scroll */ __guac_terminal_redraw_rect(term, 0, 0, shift_amount - 1, width-1); + /* Draw characters from scroll at bottom */ + __guac_terminal_redraw_rect(term, term->display->height - shift_amount, + 0, term->display->height - 1, width-1); + } }