billiob pushed a commit to branch master. http://git.enlightenment.org/apps/terminology.git/commit/?id=17246e5d8440adb9923124834f2c2ae73ba57d1f
commit 17246e5d8440adb9923124834f2c2ae73ba57d1f Author: Boris Faure <bill...@gmail.com> Date: Tue Nov 3 23:37:26 2020 +0100 config: add color_scheme TODO: set it from current theme --- src/bin/colors.c | 53 ++++++++++++++++++++++++++++++++++------------------- src/bin/colors.h | 5 +++-- src/bin/config.c | 10 +++++++++- src/bin/config.h | 16 +++++++++++----- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/bin/colors.c b/src/bin/colors.c index acca108..8952190 100644 --- a/src/bin/colors.c +++ b/src/bin/colors.c @@ -669,7 +669,7 @@ _color_scheme_get_from_file(const char *path, const char *name) } static Color_Scheme * -color_scheme_get(const char *name) +_color_scheme_get(const char *name) { static char path_user[PATH_MAX] = ""; static char path_app[PATH_MAX] = ""; @@ -703,6 +703,22 @@ color_scheme_get(const char *name) return NULL; } +void +config_compute_color_scheme(Config *cfg) +{ + EINA_SAFETY_ON_NULL_RETURN(cfg); + + free((void*)cfg->color_scheme); + cfg->color_scheme = _color_scheme_get(cfg->color_scheme_name); + if (!cfg->color_scheme) + { + eina_stringshare_del(cfg->color_scheme_name); + cfg->color_scheme_name = eina_stringshare_add("Default"); + cfg->color_scheme = color_scheme_dup(&default_colorscheme); + } +} + + static int color_scheme_cmp(const void *d1, const void *d2) { @@ -797,10 +813,10 @@ Color_Scheme * color_scheme_dup(const Color_Scheme *src) { Color_Scheme *cs; - size_t len_name = strlen(src->name) + 1; - size_t len_author = strlen(src->author) + 1; - size_t len_website = strlen(src->website) + 1; - size_t len_license = strlen(src->license) + 1; + size_t len_name = strlen(src->md.name) + 1; + size_t len_author = strlen(src->md.author) + 1; + size_t len_website = strlen(src->md.website) + 1; + size_t len_license = strlen(src->md.license) + 1; size_t len = sizeof(*cs) + len_name + len_author + len_website + len_license; char *s; @@ -811,20 +827,20 @@ color_scheme_dup(const Color_Scheme *src) memcpy(cs, src, sizeof(*cs)); s = ((char*)cs) + sizeof(*cs); - cs->name = s; - memcpy(s, src->name, len_name); + cs->md.name = s; + memcpy(s, src->md.name, len_name); s += len_name; - cs->author = s; - memcpy(s, src->author, len_author); + cs->md.author = s; + memcpy(s, src->md.author, len_author); s += len_author; - cs->website = s; - memcpy(s, src->website, len_website); + cs->md.website = s; + memcpy(s, src->md.website, len_website); s += len_website; - cs->license = s; - memcpy(s, src->license, len_license); + cs->md.license = s; + memcpy(s, src->md.license, len_license); return cs; } @@ -833,16 +849,15 @@ void color_scheme_apply_from_config(Evas_Object *edje, const Config *config) { - Color_Scheme *cs; + const Color_Scheme *cs; - if (!eina_str_has_suffix(config->theme, "/nord.edj")) - return; + EINA_SAFETY_ON_NULL_RETURN(config); + EINA_SAFETY_ON_NULL_RETURN(edje); - /* This should be cached in config */ - cs = color_scheme_get("Nord"); + cs = config->color_scheme; if (!cs) { - ERR("Could not find color scheme \"%s\"", "Nord"); + ERR("Could not find color scheme \"%s\"", config->color_scheme_name); return; } color_scheme_apply(edje, cs); diff --git a/src/bin/colors.h b/src/bin/colors.h index 6a3d238..399d5b4 100644 --- a/src/bin/colors.h +++ b/src/bin/colors.h @@ -4,8 +4,6 @@ #include <Evas.h> #include "config.h" -typedef struct _Color_Scheme Color_Scheme; -typedef struct _Color_Block Color_Block; struct _Color_Block { @@ -86,6 +84,9 @@ color_scheme_list(void); Color_Scheme * color_scheme_dup(const Color_Scheme *src); +void +config_compute_color_scheme(Config *cfg); + void colors_init(void); diff --git a/src/bin/config.c b/src/bin/config.c index c97cb36..9897331 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -105,6 +105,8 @@ config_init(void) (edd_base, Config, "helper.inline_please", helper.inline_please, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "theme", theme, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC + (edd_base, Config, "color_scheme_name", color_scheme_name, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "background", background, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC @@ -282,6 +284,7 @@ config_sync(const Config *config_src, Config *config) eina_stringshare_replace(&(config->helper.local.video), config_src->helper.local.video); eina_stringshare_replace(&(config->helper.local.image), config_src->helper.local.image); eina_stringshare_replace(&(config->theme), config_src->theme); + eina_stringshare_replace(&(config->color_scheme_name), config_src->color_scheme_name); config->scrollback = config_src->scrollback; config->tab_zoom = config_src->tab_zoom; config->hide_cursor = config_src->hide_cursor; @@ -548,6 +551,7 @@ config_new(void) config->helper.inline_please = EINA_TRUE; config->scrollback = 2000; config->theme = eina_stringshare_add("default.edj"); + config->color_scheme_name = eina_stringshare_add("Default"); config->background = NULL; config->tab_zoom = 0.5; config->opacity = 50; @@ -605,7 +609,6 @@ config_new(void) return config; } - Config * config_load(void) { @@ -769,6 +772,7 @@ config_load(void) } else { + config_compute_color_scheme(config); config->font_set = 1; } @@ -809,6 +813,8 @@ config_fork(const Config *config) SCPY(helper.local.image); CPY(helper.inline_please); SCPY(theme); + SCPY(color_scheme_name); + config2->color_scheme = color_scheme_dup(config->color_scheme); SCPY(background); CPY(scrollback); CPY(tab_zoom); @@ -880,6 +886,8 @@ config_del(Config *config) eina_stringshare_del(config->font.name); eina_stringshare_del(config->font.orig_name); eina_stringshare_del(config->theme); + eina_stringshare_del(config->color_scheme_name); + free((void*)config->color_scheme); eina_stringshare_del(config->background); eina_stringshare_del(config->helper.email); eina_stringshare_del(config->helper.url.general); diff --git a/src/bin/config.h b/src/bin/config.h index 2fb1266..fd3c7b1 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -5,7 +5,16 @@ typedef struct _Config Config; typedef struct _Color Color; +typedef struct _Color_Scheme Color_Scheme; +typedef struct _Color_Block Color_Block; typedef struct _Config_Keys Config_Keys; +struct _Color +{ + unsigned char r, g, b, a; +}; + + +#include "colors.h" struct _Config_Keys { @@ -20,11 +29,6 @@ struct _Config_Keys }; /* TODO: separate config per terminal (tab, window) and global. */ -struct _Color -{ - unsigned char r, g, b, a; -}; - typedef enum _Cursor_Shape { CURSOR_SHAPE_BLOCK = 0, @@ -55,6 +59,8 @@ struct _Config Eina_Bool inline_please; } helper; const char *theme; + const char *color_scheme_name; + const Color_Scheme *color_scheme; /* not in EET */ const char *background; double tab_zoom; double hide_cursor; --