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 <dh.herrmann@googlemail.com>
This commit is contained in:
1 parent
62e720e069
commit
1d764ebfbc
3 files changed
+40
-7
No files matched your search
@@ -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)
|
||||
|
||||
+37
-7
@@ -54,10 +54,10 @@
|
||||
#include <string.h>
|
||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||
#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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user