Skip to content

Commit 44b1638

Browse files
authored
GUACAMOLE-2158: Merge fix issues on terminal resize.
2 parents 92e69c0 + c71e1db commit 44b1638

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/terminal/buffer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,20 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer,
427427

428428
}
429429

430-
void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount) {
430+
void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount,
431+
bool increase_length) {
431432

432433
if (amount <= 0)
433434
return;
434435

435436
buffer->top = (buffer->top + amount) % buffer->available;
436437

437-
buffer->length += amount;
438-
if (buffer->length > buffer->available)
439-
buffer->length = buffer->available;
438+
/* Increase buffer length only if new row is added */
439+
if (increase_length) {
440+
buffer->length += amount;
441+
if (buffer->length > buffer->available)
442+
buffer->length = buffer->available;
443+
}
440444

441445
}
442446

src/terminal/terminal.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,8 @@ void guac_terminal_scroll_up(guac_terminal* term,
834834
/* Scroll up visibly */
835835
guac_terminal_display_copy_rows(term->display, start_row + amount, end_row, -amount);
836836

837-
/* Advance by scroll amount */
838-
guac_terminal_buffer_scroll_up(term->current_buffer, amount);
837+
/* Advance and increase buffer length by scroll amount */
838+
guac_terminal_buffer_scroll_up(term->current_buffer, amount, true);
839839

840840
/* Reset scrollbar bounds */
841841
guac_terminal_scrollbar_set_bounds(term->scrollbar,
@@ -1225,7 +1225,7 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) {
12251225
shift_amount, term->display->height - 1, -shift_amount);
12261226

12271227
/* Update buffer top and cursor row based on shift */
1228-
guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount);
1228+
guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount, false);
12291229
term->cursor_row -= shift_amount;
12301230
if (term->visible_cursor_row != -1)
12311231
term->visible_cursor_row -= shift_amount;
@@ -1296,6 +1296,10 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) {
12961296
/* Draw characters at top from scroll */
12971297
__guac_terminal_redraw_rect(term, 0, 0, shift_amount - 1, width-1);
12981298

1299+
/* Draw characters from scroll at bottom */
1300+
__guac_terminal_redraw_rect(term, term->display->height - shift_amount,
1301+
0, term->display->height - 1, width-1);
1302+
12991303
}
13001304

13011305
}

src/terminal/terminal/buffer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer,
9191
* @param amount
9292
* The number of rows to scroll upwards. Zero and negative values have no
9393
* effect.
94+
*
95+
* @param increase_length
96+
* Whether the length of the buffer should be increased to account for
97+
* newly added rows. If false, the length of the buffer remains unchanged.
9498
*/
95-
void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount);
99+
void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount,
100+
bool increase_length);
96101

97102
/**
98103
* Scrolls the contents of the given buffer down by the given number of rows.

0 commit comments

Comments
 (0)