From ccfcfb116d6dc9cb8881f04d5072796c91619d86 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 4 Aug 2019 12:44:43 -0700 Subject: [PATCH] GUACAMOLE-630: Persist details of color scheme and font changes. --- src/terminal/terminal.c | 33 ++++++++++++++++++++++++++++++++ src/terminal/terminal/terminal.h | 19 ++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index e502586a..05bf7209 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -343,6 +343,11 @@ guac_terminal* guac_terminal_create(guac_client* client, term->upload_path_handler = NULL; term->file_download_handler = NULL; + /* Copy initially-provided color scheme and font details */ + term->color_scheme = strdup(color_scheme); + term->font_name = strdup(font_name); + term->font_size = font_size; + /* Set size of available screen area */ term->outer_width = width; term->outer_height = height; @@ -511,6 +516,10 @@ void guac_terminal_free(guac_terminal* term) { /* Free scrollbar */ guac_terminal_scrollbar_free(term->scrollbar); + /* Free copies of font and color scheme information */ + free((char*) term->color_scheme); + free((char*) term->font_name); + /* Free the terminal itself */ free(term); @@ -1955,6 +1964,16 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal, terminal->term_height - 1, terminal->term_width - 1); + /* Acquire exclusive access to terminal */ + guac_terminal_lock(terminal); + + /* Update stored copy of color scheme */ + free((char*) terminal->color_scheme); + terminal->color_scheme = strdup(color_scheme); + + /* Release terminal */ + guac_terminal_unlock(terminal); + guac_terminal_notify(terminal); } @@ -1979,6 +1998,20 @@ void guac_terminal_apply_font(guac_terminal* terminal, const char* font_name, terminal->term_height - 1, terminal->term_width - 1); + /* Acquire exclusive access to terminal */ + guac_terminal_lock(terminal); + + /* Update stored copy of font name, if changed */ + if (font_name != NULL) + terminal->font_name = strdup(font_name); + + /* Update stored copy of font size, if changed */ + if (font_size != -1) + terminal->font_size = font_size; + + /* Release terminal */ + guac_terminal_unlock(terminal); + guac_terminal_notify(terminal); } diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index c2fd456b..e7746cba 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -506,6 +506,25 @@ struct guac_terminal { */ guac_common_clipboard* clipboard; + /** + * The name of the font to use when rendering glyphs, as requested at + * creation time or via guac_terminal_apply_font(). + */ + const char* font_name; + + /** + * The size of each glyph, in points, as requested at creation time or via + * guac_terminal_apply_font(). + */ + int font_size; + + /** + * The name of the color scheme to use, as requested at creation time or + * via guac_terminal_apply_color_scheme(). This string must be in the + * format accepted by guac_terminal_parse_color_scheme(). + */ + const char* color_scheme; + /** * ASCII character to send when backspace is pressed. */