From 4d007e7e788aae0f936003e123f96ff2e7b08472 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 23 Oct 2012 01:38:10 -0700 Subject: [PATCH] Automatically fit to screen. --- protocols/ssh/include/ssh_terminal.h | 4 +- protocols/ssh/src/ssh_client.c | 3 +- protocols/ssh/src/ssh_terminal.c | 70 ++++++++++++++-------------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/protocols/ssh/include/ssh_terminal.h b/protocols/ssh/include/ssh_terminal.h index e29e6736..7f56d59a 100644 --- a/protocols/ssh/include/ssh_terminal.h +++ b/protocols/ssh/include/ssh_terminal.h @@ -194,7 +194,9 @@ typedef struct ssh_guac_terminal_color { extern const ssh_guac_terminal_color ssh_guac_terminal_palette[16]; -ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client); +ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client, + int width, int height); + void ssh_guac_terminal_free(ssh_guac_terminal* term); int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size); diff --git a/protocols/ssh/src/ssh_client.c b/protocols/ssh/src/ssh_client.c index d2062780..69cb528c 100644 --- a/protocols/ssh/src/ssh_client.c +++ b/protocols/ssh/src/ssh_client.c @@ -109,7 +109,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_socket* socket = client->socket; ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data)); - ssh_guac_terminal* term = ssh_guac_terminal_create(client); + ssh_guac_terminal* term = ssh_guac_terminal_create(client, + client->info.optimal_width, client->info.optimal_height); /* Init client data */ client->data = client_data; diff --git a/protocols/ssh/src/ssh_terminal.c b/protocols/ssh/src/ssh_terminal.c index 0cb453ee..58f9d7dc 100644 --- a/protocols/ssh/src/ssh_terminal.c +++ b/protocols/ssh/src/ssh_terminal.c @@ -73,7 +73,8 @@ const ssh_guac_terminal_color ssh_guac_terminal_palette[16] = { }; -ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) { +ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client, + int width, int height) { int row, col; @@ -95,39 +96,6 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) { term->glyph_stroke = guac_client_alloc_buffer(client); term->filled_glyphs = guac_client_alloc_buffer(client); - term->cursor_row = 0; - term->cursor_col = 0; - term->cursor_layer = guac_client_alloc_layer(client); - - term->term_width = 100; - term->term_height = 37; - term->char_handler = ssh_guac_terminal_echo; - - term->scroll_start = 0; - term->scroll_end = term->term_height - 1; - - /* Create scrollback buffer */ - term->scrollback = malloc(term->term_height * sizeof(ssh_guac_terminal_char*)); - - /* Init buffer */ - for (row = 0; row < term->term_height; row++) { - - /* Create row */ - ssh_guac_terminal_char* current_row = - term->scrollback[row] = malloc(term->term_width * sizeof(ssh_guac_terminal_char)); - - /* Init row */ - for (col = 0; col < term->term_width; col++) { - - /* Empty character, default colors */ - current_row[col].value = '\0'; - current_row[col].foreground = term->default_foreground; - current_row[col].background = term->default_background; - - } - - } - /* Get font */ term->font_desc = pango_font_description_new(); pango_font_description_set_family(term->font_desc, "monospace"); @@ -156,6 +124,40 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) { (pango_font_metrics_get_descent(metrics) + pango_font_metrics_get_ascent(metrics)) / PANGO_SCALE; + + term->cursor_row = 0; + term->cursor_col = 0; + term->cursor_layer = guac_client_alloc_layer(client); + + term->term_width = width / term->char_width; + term->term_height = height / term->char_height; + term->char_handler = ssh_guac_terminal_echo; + + term->scroll_start = 0; + term->scroll_end = term->term_height - 1; + + /* Create scrollback buffer */ + term->scrollback = malloc(term->term_height * sizeof(ssh_guac_terminal_char*)); + + /* Init buffer */ + for (row = 0; row < term->term_height; row++) { + + /* Create row */ + ssh_guac_terminal_char* current_row = + term->scrollback[row] = malloc(term->term_width * sizeof(ssh_guac_terminal_char)); + + /* Init row */ + for (col = 0; col < term->term_width; col++) { + + /* Empty character, default colors */ + current_row[col].value = '\0'; + current_row[col].foreground = term->default_foreground; + current_row[col].background = term->default_background; + + } + + } + /* Clear with background color */ ssh_guac_terminal_clear(term, 0, 0, term->term_height, term->term_width,