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.
This commit is contained in:
Jim Chen 2018-01-09 22:14:56 -05:00
parent b61a6ab758
commit f8b35078fc
3 changed files with 22 additions and 4 deletions

View File

@ -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));

View File

@ -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) {

View File

@ -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.