From c20fe79ace997dc6e8e84219e9481ef323bd4749 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 8 Apr 2013 00:47:08 -0700 Subject: [PATCH] Remove scroll logging, reset scroll upon typing. --- protocols/ssh/include/terminal.h | 16 ++++++++++------ protocols/ssh/src/ssh_handlers.c | 12 ++++++++++-- protocols/ssh/src/terminal.c | 23 ++++------------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/protocols/ssh/include/terminal.h b/protocols/ssh/include/terminal.h index 63e536ea..ca0fd051 100644 --- a/protocols/ssh/include/terminal.h +++ b/protocols/ssh/include/terminal.h @@ -45,6 +45,8 @@ #include +#define GUAC_SSH_WHEEL_SCROLL_AMOUNT 3 + typedef struct guac_terminal guac_terminal; /** @@ -606,16 +608,18 @@ guac_terminal_scrollback_row* guac_terminal_scrollback_buffer_get_row( guac_terminal_scrollback_buffer* buffer, int row); /** - * Scroll down the display by one row, replacing the new space with data from - * the scrollback. + * Scroll down the display by the given amount, replacing the new space with + * data from the scrollback. If not enough data is available, the maximum + * amount will be scrolled. */ -void guac_terminal_scroll_display_down(guac_terminal* terminal); +void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount); /** - * Scroll up the display by one row, replacing the new space with data from - * either the scrollback or the terminal buffer. + * Scroll up the display by the given amount, replacing the new space with data + * from either the scrollback or the terminal buffer. If not enough data is + * available, the maximum amount will be scrolled. */ -void guac_terminal_scroll_display_up(guac_terminal* terminal); +void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount); #endif diff --git a/protocols/ssh/src/ssh_handlers.c b/protocols/ssh/src/ssh_handlers.c index 11fd9e47..2edc915e 100644 --- a/protocols/ssh/src/ssh_handlers.c +++ b/protocols/ssh/src/ssh_handlers.c @@ -164,14 +164,14 @@ int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) { /* Scroll up if wheel moved up */ if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_UP) { pthread_mutex_lock(&(term->lock)); - guac_terminal_scroll_display_up(term); + guac_terminal_scroll_display_up(term, GUAC_SSH_WHEEL_SCROLL_AMOUNT); pthread_mutex_unlock(&(term->lock)); } /* Scroll down if wheel moved down */ if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_DOWN) { pthread_mutex_lock(&(term->lock)); - guac_terminal_scroll_display_down(term); + guac_terminal_scroll_display_down(term, GUAC_SSH_WHEEL_SCROLL_AMOUNT); pthread_mutex_unlock(&(term->lock)); } @@ -182,6 +182,7 @@ int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) { int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) { ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data; + guac_terminal* term = client_data->term; /* Track modifiers */ if (keysym == 0xFFE3) { @@ -191,6 +192,13 @@ int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) { /* If key pressed */ else if (pressed) { + /* Reset scroll */ + if (term->scroll_offset != 0) { + pthread_mutex_lock(&(term->lock)); + guac_terminal_scroll_display_down(term, term->scroll_offset); + pthread_mutex_unlock(&(term->lock)); + } + /* If simple ASCII key */ if (keysym >= 0x00 && keysym <= 0xFF) { char data = (char) keysym; diff --git a/protocols/ssh/src/terminal.c b/protocols/ssh/src/terminal.c index 0da11890..6bdaea38 100644 --- a/protocols/ssh/src/terminal.c +++ b/protocols/ssh/src/terminal.c @@ -1219,16 +1219,10 @@ void guac_terminal_scrollback_buffer_append( if (buffer->length > buffer->rows) buffer->length = buffer->rows; - /* Log string version of row that WOULD have been scrolled into the - * scrollback */ - guac_client_log_info(terminal->client, - "scrollback->top=%i (length=%i/%i)", buffer->top, buffer->length, buffer->rows); - } -void guac_terminal_scroll_display_down(guac_terminal* terminal) { - - int scroll_amount = 3; +void guac_terminal_scroll_display_down(guac_terminal* terminal, + int scroll_amount) { int start_row, end_row; int dest_row; @@ -1257,10 +1251,6 @@ void guac_terminal_scroll_display_down(guac_terminal* terminal) { start_row = end_row - scroll_amount + 1; dest_row = terminal->term_height - scroll_amount; - guac_client_log_info(terminal->client, - "Scrolling rows %i through %i into view (scroll down)", - start_row, end_row); - /* Draw new rows from scrollback */ for (row=start_row; row<=end_row; row++) { @@ -1304,9 +1294,8 @@ void guac_terminal_scroll_display_down(guac_terminal* terminal) { } -void guac_terminal_scroll_display_up(guac_terminal* terminal) { - - int scroll_amount = 3; +void guac_terminal_scroll_display_up(guac_terminal* terminal, + int scroll_amount) { int start_row, end_row; int dest_row; @@ -1336,10 +1325,6 @@ void guac_terminal_scroll_display_up(guac_terminal* terminal) { end_row = start_row + scroll_amount - 1; dest_row = 0; - guac_client_log_info(terminal->client, - "Scrolling rows %i through %i into view (scroll up)", - start_row, end_row); - /* Draw new rows from scrollback */ for (row=start_row; row<=end_row; row++) {