From f8b35078fc2eab22a982f43100f6c07d55931a05 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 9 Jan 2018 22:14:56 -0500 Subject: [PATCH] GUACAMOLE-470: Add support for configurable default palette. Add support for configuring a default palette for a terminal display. When the default palette is specified during display creation, that palette is used instead of GUAC_TERMINAL_INITIAL_PALETTE when resetting the display palette. --- src/terminal/display.c | 13 ++++++++++++- src/terminal/terminal.c | 2 +- src/terminal/terminal/display.h | 11 +++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/terminal/display.c b/src/terminal/display.c index 3ad1cba8..9391ec17 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -246,7 +246,8 @@ int __guac_terminal_set(guac_terminal_display* display, int row, int col, int co guac_terminal_display* guac_terminal_display_alloc(guac_client* client, const char* font_name, int font_size, int dpi, - guac_terminal_color* foreground, guac_terminal_color* background) { + guac_terminal_color* foreground, guac_terminal_color* background, + const guac_terminal_color (*palette)[256]) { PangoFontMap* font_map; PangoFont* font; @@ -294,6 +295,7 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, display->default_foreground = display->glyph_foreground = *foreground; display->default_background = display->glyph_background = *background; + display->default_palette = palette; /* Calculate character dimensions */ display->char_width = @@ -317,6 +319,9 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, void guac_terminal_display_free(guac_terminal_display* display) { + /* Free default palette. */ + free((void*) display->default_palette); + /* Free operations buffers */ free(display->operations); @@ -328,6 +333,12 @@ void guac_terminal_display_free(guac_terminal_display* display) { void guac_terminal_display_reset_palette(guac_terminal_display* display) { /* Reinitialize palette with default values */ + if (display->default_palette) { + memcpy(display->palette, *display->default_palette, + sizeof(GUAC_TERMINAL_INITIAL_PALETTE)); + return; + } + memcpy(display->palette, GUAC_TERMINAL_INITIAL_PALETTE, sizeof(GUAC_TERMINAL_INITIAL_PALETTE)); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 076305a9..a9f5ae51 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -332,7 +332,7 @@ guac_terminal* guac_terminal_create(guac_client* client, term->display = guac_terminal_display_alloc(client, font_name, font_size, dpi, &default_char.attributes.foreground, - &default_char.attributes.background); + &default_char.attributes.background, NULL); /* Fail if display init failed */ if (term->display == NULL) { diff --git a/src/terminal/terminal/display.h b/src/terminal/terminal/display.h index e51b07fd..98337fd2 100644 --- a/src/terminal/terminal/display.h +++ b/src/terminal/terminal/display.h @@ -138,6 +138,12 @@ typedef struct guac_terminal_display { */ guac_terminal_color palette[256]; + /** + * The default palette. Use GUAC_TERMINAL_INITIAL_PALETTE if null. + * Must free on destruction if not null. + */ + const guac_terminal_color (*default_palette)[256]; + /** * Default foreground color for all glyphs. */ @@ -215,7 +221,8 @@ typedef struct guac_terminal_display { */ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, const char* font_name, int font_size, int dpi, - guac_terminal_color* foreground, guac_terminal_color* background); + guac_terminal_color* foreground, guac_terminal_color* background, + const guac_terminal_color (*palette)[256]); /** * Frees the given display. @@ -224,7 +231,7 @@ void guac_terminal_display_free(guac_terminal_display* display); /** * Resets the palette of the given display to the initial, default color - * values, as defined by GUAC_TERMINAL_INITIAL_PALETTE. + * values, as defined by default_palette or GUAC_TERMINAL_INITIAL_PALETTE. * * @param display * The display to reset.