From 1d764ebfbc7cab24a4945415ca8c70e5705ce8fe Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 18 Sep 2012 17:25:34 +0200 Subject: [PATCH] tsm: add *_set_palette() helper Instead of accessing kmscon-state we now add a helper to select the palette and make the terminal-subsystem use it on initialization. Signed-off-by: David Herrmann --- src/terminal.c | 1 + src/tsm_vte.c | 44 +++++++++++++++++++++++++++++++++++++------- src/tsm_vte.h | 2 ++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/terminal.c b/src/terminal.c index 6f9f04e..f31dd17 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -435,6 +435,7 @@ int kmscon_terminal_new(struct kmscon_terminal **out, ret = tsm_vte_new(&term->vte, term->console, write_event, term); if (ret) goto err_con; + tsm_vte_set_palette(term->vte, kmscon_conf.palette); ret = kmscon_pty_new(&term->pty, term->eloop, pty_input, term); if (ret) diff --git a/src/tsm_vte.c b/src/tsm_vte.c index 24db476..c951f5a 100644 --- a/src/tsm_vte.c +++ b/src/tsm_vte.c @@ -54,10 +54,10 @@ #include #include #include "log.h" -#include "main.h" #include "tsm_screen.h" #include "tsm_unicode.h" #include "tsm_vte.h" +#include "uterm.h" #define LOG_SUBSYSTEM "vte" @@ -151,6 +151,7 @@ struct tsm_vte { struct tsm_screen *con; tsm_vte_write_cb write_cb; void *data; + char *palette_name; struct tsm_utf8_mach *mach; unsigned long parse_cnt; @@ -287,16 +288,16 @@ static uint8_t color_palette_solarized_white[COLOR_NUM][3] = { [COLOR_BACKGROUND] = { 238, 232, 213 }, /* light grey */ }; -static uint8_t (*get_palette(void))[3] +static uint8_t (*get_palette(struct tsm_vte *vte))[3] { - if (!kmscon_conf.palette) + if (!vte->palette_name) return color_palette; - if (!strcmp(kmscon_conf.palette, "solarized")) + if (!strcmp(vte->palette_name, "solarized")) return color_palette_solarized; - if (!strcmp(kmscon_conf.palette, "solarized-black")) + if (!strcmp(vte->palette_name, "solarized-black")) return color_palette_solarized_black; - if (!strcmp(kmscon_conf.palette, "solarized-white")) + if (!strcmp(vte->palette_name, "solarized-white")) return color_palette_solarized_white; return color_palette; @@ -374,7 +375,7 @@ int tsm_vte_new(struct tsm_vte **out, struct tsm_screen *con, vte->con = con; vte->write_cb = write_cb; vte->data = data; - vte->palette = get_palette(); + vte->palette = get_palette(vte); vte->def_attr.fccode = COLOR_FOREGROUND; vte->def_attr.bccode = COLOR_BACKGROUND; to_rgb(vte, &vte->def_attr); @@ -418,6 +419,35 @@ void tsm_vte_unref(struct tsm_vte *vte) free(vte); } +int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette) +{ + char *tmp = NULL; + + if (!vte) + return -EINVAL; + + if (palette) { + tmp = strdup(palette); + if (!tmp) + return -ENOMEM; + } + + free(vte->palette_name); + vte->palette_name = tmp; + + vte->palette = get_palette(vte); + vte->def_attr.fccode = COLOR_FOREGROUND; + vte->def_attr.bccode = COLOR_BACKGROUND; + + to_rgb(vte, &vte->def_attr); + memcpy(&vte->cattr, &vte->def_attr, sizeof(vte->cattr)); + + tsm_screen_set_def_attr(vte->con, &vte->def_attr); + tsm_screen_erase_screen(vte->con, false); + + return 0; +} + /* * Write raw byte-stream to pty. * When writing data to the client we must make sure that we send the correct diff --git a/src/tsm_vte.h b/src/tsm_vte.h index a57dd21..683a654 100644 --- a/src/tsm_vte.h +++ b/src/tsm_vte.h @@ -67,6 +67,8 @@ int tsm_vte_new(struct tsm_vte **out, struct tsm_screen *con, void tsm_vte_ref(struct tsm_vte *vte); void tsm_vte_unref(struct tsm_vte *vte); +int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette); + void tsm_vte_reset(struct tsm_vte *vte); void tsm_vte_input(struct tsm_vte *vte, const char *u8, size_t len); bool tsm_vte_handle_keyboard(struct tsm_vte *vte, uint32_t keysym,