diff --git a/src/protocols/ssh/client.c b/src/protocols/ssh/client.c index 43985b3f..cb615831 100644 --- a/src/protocols/ssh/client.c +++ b/src/protocols/ssh/client.c @@ -173,7 +173,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->term = guac_terminal_create(client, client_data->font_name, client_data->font_size, client->info.optimal_resolution, - client->info.optimal_width, client->info.optimal_height); + client->info.optimal_width, client->info.optimal_height, + 7, 0); /* Fail if terminal init failed */ if (client_data->term == NULL) { diff --git a/src/protocols/telnet/client.c b/src/protocols/telnet/client.c index a083df39..424dd6cf 100644 --- a/src/protocols/telnet/client.c +++ b/src/protocols/telnet/client.c @@ -200,7 +200,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->term = guac_terminal_create(client, client_data->font_name, client_data->font_size, client->info.optimal_resolution, - client->info.optimal_width, client->info.optimal_height); + client->info.optimal_width, client->info.optimal_height, + 7, 0); /* Fail if terminal init failed */ if (client_data->term == NULL) { diff --git a/src/terminal/display.c b/src/terminal/display.c index b54e27e4..c90c2882 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -306,8 +306,8 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, return NULL; } - display->glyph_foreground = foreground; - display->glyph_background = background; + display->default_foreground = display->glyph_foreground = foreground; + display->default_background = display->glyph_background = background; /* Calculate character dimensions */ display->char_width = @@ -475,12 +475,12 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int guac_terminal_operation* current; int x, y; - /* Fill with background color (index 0) */ + /* Fill with background color */ guac_terminal_char fill = { .value = 0, .attributes = { - .foreground = 0, - .background = 0 + .foreground = display->default_background, + .background = display->default_background }, .width = 1 }; diff --git a/src/terminal/display.h b/src/terminal/display.h index 084ece81..c9eb1c38 100644 --- a/src/terminal/display.h +++ b/src/terminal/display.h @@ -139,6 +139,16 @@ typedef struct guac_terminal_display { */ int char_height; + /** + * Default foreground color for all glyphs. + */ + int default_foreground; + + /** + * Default background color for all glyphs and the terminal itself. + */ + int default_background; + /** * Color of glyphs in copy buffer */ diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 5c688d61..c7c64ac7 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -190,20 +190,57 @@ void guac_terminal_reset(guac_terminal* term) { } +/** + * Paints or repaints the background of the terminal display. This painting + * occurs beneath the actual terminal and scrollbar layers, and thus will not + * overwrite any text or other content currently on the screen. This is only + * necessary to paint over parts of the terminal background which may otherwise + * be transparent (the default layer background). + * + * @param terminal + * The terminal whose background should be painted or repainted. + * + * @param width + * The width of the background to draw, in pixels. + * + * @param height + * The height of the background to draw, in pixels. + */ +static void guac_terminal_paint_background(guac_terminal* terminal, + int width, int height) { + + guac_terminal_display* display = terminal->display; + guac_client* client = display->client; + guac_socket* socket = client->socket; + + /* Get background color */ + const guac_terminal_color* color = + &guac_terminal_palette[display->default_background]; + + /* Paint background color */ + guac_protocol_send_rect(socket, GUAC_DEFAULT_LAYER, 0, 0, width, height); + guac_protocol_send_cfill(socket, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, + color->red, color->green, color->blue, 0xFF); + +} + guac_terminal* guac_terminal_create(guac_client* client, const char* font_name, int font_size, int dpi, - int width, int height) { + int width, int height, + int default_foreground, + int default_background) { guac_terminal_char default_char = { .value = 0, .attributes = { - .foreground = 7, - .background = 0, + .foreground = default_foreground, + .background = default_background, .bold = false, .reverse = false, .underscore = false }, - .width = 1}; + .width = 1 + }; /* Calculate available display area */ int available_width = width - GUAC_TERMINAL_SCROLLBAR_WIDTH; @@ -260,6 +297,7 @@ guac_terminal* guac_terminal_create(guac_client* client, /* Size display */ guac_protocol_send_size(term->display->client->socket, GUAC_DEFAULT_LAYER, width, height); + guac_terminal_paint_background(term, width, height); guac_terminal_display_resize(term->display, term->term_width, term->term_height); @@ -1234,6 +1272,7 @@ int guac_terminal_resize(guac_terminal* terminal, int width, int height) { /* Resize default layer to given pixel dimensions */ guac_protocol_send_size(socket, GUAC_DEFAULT_LAYER, width, height); + guac_terminal_paint_background(terminal, width, height); /* Notify scrollbar of resize */ guac_terminal_scrollbar_parent_resized(terminal->scrollbar, width, height, rows); diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index 7c6b7507..43a1be92 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -348,10 +348,45 @@ struct guac_terminal { /** * Creates a new guac_terminal, having the given width and height, and * rendering to the given client. + * + * @param client + * The client to which the terminal will be rendered. + * + * @param font_name + * The name of the font to use when rendering glyphs. + * + * @param font_size + * The size of each glyph, in points. + * + * @param dpi + * The DPI of the display. The given font size will be adjusted to produce + * glyphs at the given DPI. + * + * @param width + * The width of the terminal, in pixels. + * + * @param height + * The height of the terminal, in pixels. + * + * @param default_foreground + * The default foreground color for all glyphs whose foreground has not + * been explicitly set through terminal codes. This color is the color + * index within the terminal palette - a value between 0 and 15 inclusive. + * + * @param default_background + * The default background color for all glyphs whose background has not + * been explicitly set through terminal codes, and the background of the + * terminal as a whole. This color is the color index within the terminal + * palette - a value between 0 and 15 inclusive. + * + * @return + * A new guac_terminal having the given font, dimensions, and attributes + * which renders all text to the given client. */ guac_terminal* guac_terminal_create(guac_client* client, const char* font_name, int font_size, int dpi, - int width, int height); + int width, int height, + int default_foreground, int default_background); /** * Frees all resources associated with the given terminal.