Handle display size properly, start out empty.

This commit is contained in:
Michael Jumper 2013-04-26 14:14:19 -07:00
parent dd4862f59a
commit 6092badb3b
4 changed files with 51 additions and 38 deletions

View File

@ -177,10 +177,10 @@ typedef struct guac_terminal_display {
} guac_terminal_display;
/**
* Allocates a new display having the given dimensions.
* Allocates a new display having the given default foreground and background
* colors.
*/
guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int width, int height,
int foreground, int background);
guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int foreground, int background);
/**
* Frees the given display.
@ -211,7 +211,7 @@ void guac_terminal_display_set_columns(guac_terminal_display* display, int row,
/**
* Resize the terminal to the given dimensions.
*/
void guac_terminal_display_resize(guac_terminal_display* display, int rows, int cols);
void guac_terminal_display_resize(guac_terminal_display* display, int width, int height);
/**
* Flushes all pending operations within the given guac_terminal_display.

View File

@ -278,7 +278,7 @@ void guac_terminal_set_columns(guac_terminal* terminal, int row,
/**
* Resize the terminal to the given dimensions.
*/
void guac_terminal_resize(guac_terminal* term, int rows, int cols);
void guac_terminal_resize(guac_terminal* term, int width, int height);
/**
* Flushes all pending operations within the given guac_terminal.

View File

@ -249,11 +249,7 @@ int __guac_terminal_set(guac_terminal_display* display, int row, int col, char c
}
guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int width, int height,
int foreground, int background) {
guac_terminal_operation* current;
int x, y;
guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int foreground, int background) {
PangoFontMap* font_map;
PangoFont* font;
@ -299,29 +295,10 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int widt
(pango_font_metrics_get_descent(metrics)
+ pango_font_metrics_get_ascent(metrics)) / PANGO_SCALE;
/* Set width and height */
display->width = width;
display->height = height;
/* Alloc operations */
display->operations = malloc(width * height *
sizeof(guac_terminal_operation));
/* Init each operation buffer row */
current = display->operations;
for (y=0; y<height; y++) {
/* Init entire row to NOP */
for (x=0; x<width; x++)
(current++)->type = GUAC_CHAR_NOP;
}
/* Send initial display size */
guac_protocol_send_size(client->socket,
GUAC_DEFAULT_LAYER,
display->char_width * width,
display->char_height * height);
/* Initially empty */
display->width = 0;
display->height = 0;
display->operations = NULL;
return display;
@ -428,8 +405,41 @@ void guac_terminal_display_set_columns(guac_terminal_display* display, int row,
}
void guac_terminal_display_resize(guac_terminal_display* display, int rows, int cols) {
/* STUB */
void guac_terminal_display_resize(guac_terminal_display* display, int width, int height) {
guac_terminal_operation* current;
int x, y;
/* Set width and height */
display->width = width;
display->height = height;
/* Free old operations buffer */
if (display->operations != NULL)
free(display->operations);
/* Alloc operations */
display->operations = malloc(width * height *
sizeof(guac_terminal_operation));
/* Init each operation buffer row */
current = display->operations;
for (y=0; y<height; y++) {
/* Init entire row to NOP */
for (x=0; x<width; x++)
(current++)->type = GUAC_CHAR_NOP;
}
/* Send initial display size */
guac_protocol_send_size(display->client->socket,
GUAC_DEFAULT_LAYER,
display->char_width * width,
display->char_height * height);
}
void __guac_terminal_display_flush_copy(guac_terminal_display* display) {

View File

@ -75,7 +75,6 @@ guac_terminal* guac_terminal_create(guac_client* client,
/* Init display */
term->display = guac_terminal_display_alloc(client,
80, 24, /*term->term_width, term->term_height,*/
default_char.attributes.foreground,
default_char.attributes.background);
@ -86,8 +85,8 @@ guac_terminal* guac_terminal_create(guac_client* client,
term->cursor_row = 0;
term->cursor_col = 0;
term->term_width = 80; /*width / term->display->char_width;*/
term->term_height = 24; /*height / term->display->char_height;*/
term->term_width = width / term->display->char_width;
term->term_height = height / term->display->char_height;
term->char_handler = guac_terminal_echo;
term->scroll_start = 0;
@ -95,6 +94,10 @@ guac_terminal* guac_terminal_create(guac_client* client,
term->text_selected = false;
/* Size display */
guac_terminal_display_resize(term->display,
term->term_width, term->term_height);
/* Init terminal lock */
pthread_mutex_init(&(term->lock), NULL);