From e90202923d87d4d04cd923cc1072e84df4db790d Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 6 Oct 2020 18:50:16 +0200 Subject: [PATCH] colors: use color scheme from file (only for Nord) --- src/bin/colors.c | 261 ++++++++++++++++++++++------------------------- src/bin/colors.h | 4 +- src/bin/theme.c | 10 +- 3 files changed, 129 insertions(+), 146 deletions(-) diff --git a/src/bin/colors.c b/src/bin/colors.c index 7407da5f..4791be4d 100644 --- a/src/bin/colors.c +++ b/src/bin/colors.c @@ -563,149 +563,112 @@ colors_256_get(int col, *a = default_colors256[col].a; } -void -color_scheme_apply(Evas_Object *edje, - const Config *config) +static void +_colorscheme_apply(Evas_Object *edje, + const Color_Scheme *cs) { - if (!eina_str_has_suffix(config->theme, "/nord.edj")) + if (!cs) return; -#define CS_BG 46, 52, 64, 255 -#define CS_FG 216, 222, 233, 255 -#define CS_MAIN 137, 152, 161, 255 -#define CS_HL 255, 255, 255, 255 -#define CS_RAGE 255, 51, 0, 255 -#define CS_RED 255, 0, 0, 255 -#define CS_ORANGE 255, 153, 51, 255 -#define CS_BLACK 0, 0, 0, 255 + +#define CS_SET(_K, _F) do {\ + edje_object_color_class_set(edje, _K, \ + cs->_F.r, cs->_F.g, cs->_F.b, cs->_F.a, \ + cs->_F.r, cs->_F.g, cs->_F.b, cs->_F.a, \ + cs->_F.r, cs->_F.g, cs->_F.b, cs->_F.a); \ +} while (0) +#define CS_SET_MANY(_K, _F1, _F2, _F3) do {\ + edje_object_color_class_set(edje, _K, \ + cs->_F1.r, cs->_F1.g, cs->_F1.b, cs->_F1.a, \ + cs->_F2.r, cs->_F2.g, cs->_F2.b, cs->_F2.a, \ + cs->_F3.r, cs->_F3.g, cs->_F3.b, cs->_F3.a); \ +} while (0) + + CS_SET("DEF", def); + CS_SET("BG", bg); + CS_SET("FG", fg); + CS_SET("CURSOR", main); + CS_SET("CURSOR_HIGHLIGHT", hl); + CS_SET("GLOW", main); + CS_SET("GLOW_HIGHLIGHT", hl); + CS_SET("GLOW_TXT", main); + CS_SET_MANY("GLOW_TXT_HIGHLIGHT", hl, main, main); + + CS_SET("END_SELECTION", end_sel); + CS_SET_MANY("TAB_MISSED", tab_missed_1, tab_missed_2, tab_missed_3); + CS_SET_MANY("TAB_MISSED_OVER", + tab_missed_over_1, tab_missed_over_2, tab_missed_over_3); + CS_SET_MANY("TAB_TITLE", fg, tab_title_2, bg); + #define CS_DARK 64, 64, 64, 255 -#define CS_YELLOW 255, 255, 64, 255 - edje_object_color_class_set(edje, "BG", CS_BG, CS_BG, CS_BG); - edje_object_color_class_set(edje, "FG", CS_BG, CS_BG, CS_BG); - edje_object_color_class_set(edje, "CURSOR", CS_MAIN, CS_MAIN, CS_MAIN); - edje_object_color_class_set(edje, "CURSOR_HIGHLIGHT", CS_HL, CS_HL, CS_HL); - edje_object_color_class_set(edje, "GLOW", CS_MAIN, CS_MAIN, CS_MAIN); - edje_object_color_class_set(edje, "GLOW_HIGHLIGHT", CS_HL, CS_HL, CS_HL); - edje_object_color_class_set(edje, "GLOW_TXT", CS_MAIN, CS_MAIN, CS_MAIN); - edje_object_color_class_set(edje, "GLOW_HIGHLIGHT", CS_HL, CS_MAIN, CS_MAIN); - edje_object_color_class_set(edje, "END_SELECTION", CS_RAGE, CS_RAGE, CS_RAGE); - edje_object_color_class_set(edje, "TAB_MISSED", CS_ORANGE, CS_RAGE, CS_RED); - edje_object_color_class_set(edje, "TAB_MISSED_OVER", CS_YELLOW, CS_ORANGE, CS_RED); - edje_object_color_class_set(edje, "TAB_TITLE", CS_FG, CS_BLACK, CS_BG); - edje_object_color_class_set(edje, "BG_SENDFILE", CS_DARK, CS_DARK, CS_DARK); - edje_object_color_class_set(edje, "SHINE", CS_HL, CS_HL, CS_HL); - -#define CS_SET(K, C) \ - edje_object_color_class_set(edje, K, C, C, C) - -#define CS_DEF 216, 222, 233, 255 /* #D8DEE9 */ -#define CS_ANSI00 59, 66, 82, 255 /* #3B4252 */ -#define CS_ANSI01 191, 97, 106, 255 /* #BF616A */ -#define CS_ANSI02 163, 190, 140, 255 /* #A3BE8C */ -#define CS_ANSI03 235, 203, 139, 255 /* #EBCB8B */ -#define CS_ANSI04 129, 161, 193, 255 /* #81A1C1 */ -#define CS_ANSI05 180, 142, 173, 255 /* #B38EAD */ -#define CS_ANSI06 136, 192, 208, 255 /* #88C0D0 */ -#define CS_ANSI07 229, 233, 248, 255 /* #E5E9F0 */ -#define CS_ANSI08 76, 86, 106, 255 /* #4C566A */ -#define CS_ANSI09 191, 97, 106, 255 /* #BF616A */ -#define CS_ANSI10 163, 190, 140, 255 /* #A3BE8C */ -#define CS_ANSI11 235, 203, 139, 255 /* #EBCB8B */ -#define CS_ANSI12 129, 161, 193, 255 /* #81A1C1 */ -#define CS_ANSI13 180, 142, 173, 255 /* #B38EAD */ -#define CS_ANSI14 143, 188, 187, 255 /* #8FBCBB */ -#define CS_ANSI15 236, 239, 244, 255 /* #ECEFF4 */ - - CS_SET("C0", CS_ANSI00); - CS_SET("C1", CS_ANSI01); - CS_SET("C2", CS_ANSI02); - CS_SET("C3", CS_ANSI03); - CS_SET("C4", CS_ANSI04); - CS_SET("C5", CS_ANSI05); - CS_SET("C6", CS_ANSI06); - CS_SET("C7", CS_ANSI07); - - CS_SET("C8", CS_ANSI08); - CS_SET("C9", CS_ANSI09); - CS_SET("C10", CS_ANSI10); - CS_SET("C11", CS_ANSI11); - CS_SET("C12", CS_ANSI12); - CS_SET("C13", CS_ANSI13); - CS_SET("C14", CS_ANSI14); - CS_SET("C14", CS_ANSI15); - - CS_SET("c0", CS_DEF); - CS_SET("c1", CS_ANSI00); - CS_SET("c2", CS_ANSI01); - CS_SET("c3", CS_ANSI02); - CS_SET("c4", CS_ANSI03); - CS_SET("c5", CS_ANSI04); - CS_SET("c6", CS_ANSI05); - CS_SET("c7", CS_ANSI06); - CS_SET("c8", CS_ANSI07); - - CS_SET("c11", CS_DEF); - - CS_SET("c12", CS_ANSI15); - CS_SET("c13", CS_ANSI08); - CS_SET("c14", CS_ANSI09); - CS_SET("c15", CS_ANSI10); - CS_SET("c16", CS_ANSI11); - CS_SET("c17", CS_ANSI12); - CS_SET("c18", CS_ANSI13); - CS_SET("c19", CS_ANSI14); - CS_SET("c20", CS_ANSI15); - - CS_SET("c25", CS_ANSI08); - CS_SET("c26", CS_ANSI09); - CS_SET("c27", CS_ANSI10); - CS_SET("c28", CS_ANSI11); - CS_SET("c29", CS_ANSI12); - CS_SET("c30", CS_ANSI13); - CS_SET("c31", CS_ANSI14); - CS_SET("c32", CS_ANSI15); - - CS_SET("c37", CS_ANSI08); - CS_SET("c38", CS_ANSI09); - CS_SET("c39", CS_ANSI10); - CS_SET("c40", CS_ANSI11); - CS_SET("c41", CS_ANSI12); - CS_SET("c42", CS_ANSI13); - CS_SET("c43", CS_ANSI14); - CS_SET("c44", CS_ANSI15); - -#undef CS_DEF -#undef CS_ANSI00 -#undef CS_ANSI01 -#undef CS_ANSI02 -#undef CS_ANSI03 -#undef CS_ANSI04 -#undef CS_ANSI05 -#undef CS_ANSI06 -#undef CS_ANSI07 -#undef CS_ANSI08 -#undef CS_ANSI09 -#undef CS_ANSI10 -#undef CS_ANSI11 -#undef CS_ANSI12 -#undef CS_ANSI13 -#undef CS_ANSI14 -#undef CS_ANSI15 - -#undef CS_BG -#undef CS_FG -#undef CS_MAIN -#undef CS_HL -#undef CS_RAGE -#undef CS_RED -#undef CS_ORANGE -#undef CS_BLACK +edje_object_color_class_set(edje, "BG_SENDFILE", CS_DARK, CS_DARK, CS_DARK); #undef CS_DARK -#undef CS_YELLOW + + CS_SET("SHINE", hl); + + CS_SET("C0", ansi[0]); + CS_SET("C1", ansi[1]); + CS_SET("C2", ansi[2]); + CS_SET("C3", ansi[3]); + CS_SET("C4", ansi[4]); + CS_SET("C5", ansi[5]); + CS_SET("C6", ansi[6]); + CS_SET("C7", ansi[7]); + + CS_SET("C8", ansi[8]); + CS_SET("C9", ansi[9]); + CS_SET("C10", ansi[10]); + CS_SET("C11", ansi[11]); + CS_SET("C12", ansi[12]); + CS_SET("C13", ansi[13]); + CS_SET("C14", ansi[14]); + CS_SET("C14", ansi[15]); + + CS_SET("c0", def); + CS_SET("c1", ansi[0]); + CS_SET("c2", ansi[1]); + CS_SET("c3", ansi[2]); + CS_SET("c4", ansi[3]); + CS_SET("c5", ansi[4]); + CS_SET("c6", ansi[5]); + CS_SET("c7", ansi[6]); + CS_SET("c8", ansi[7]); + + CS_SET("c11", def); + + CS_SET("c12", ansi[15]); + CS_SET("c13", ansi[8]); + CS_SET("c14", ansi[9]); + CS_SET("c15", ansi[10]); + CS_SET("c16", ansi[11]); + CS_SET("c17", ansi[12]); + CS_SET("c18", ansi[13]); + CS_SET("c19", ansi[14]); + CS_SET("c20", ansi[15]); + + CS_SET("c25", ansi[8]); + CS_SET("c26", ansi[9]); + CS_SET("c27", ansi[10]); + CS_SET("c28", ansi[11]); + CS_SET("c29", ansi[12]); + CS_SET("c30", ansi[13]); + CS_SET("c31", ansi[14]); + CS_SET("c32", ansi[15]); + + CS_SET("c37", ansi[8]); + CS_SET("c38", ansi[9]); + CS_SET("c39", ansi[10]); + CS_SET("c40", ansi[11]); + CS_SET("c41", ansi[12]); + CS_SET("c42", ansi[13]); + CS_SET("c43", ansi[14]); + CS_SET("c44", ansi[15]); + #undef CS_SET +#undef CS_SET_MANY } -Color_Scheme * -_color_scheme_from_file(const char *path, const char *name) +static Color_Scheme * +_color_scheme_get_from_file(const char *path, const char *name) { Eet_File *ef; Color_Scheme *cs; @@ -720,7 +683,7 @@ _color_scheme_from_file(const char *path, const char *name) return cs; } -Color_Scheme * +static Color_Scheme * color_scheme_get(const char *name) { static char path_user[PATH_MAX] = ""; @@ -736,9 +699,8 @@ color_scheme_get(const char *name) "%s/" COLORSCHEMES_FILENAME, elm_app_data_dir_get()); - - cs_user = _color_scheme_from_file(path_user, name); - cs_app = _color_scheme_from_file(path_app, name); + cs_user = _color_scheme_get_from_file(path_user, name); + cs_app = _color_scheme_get_from_file(path_app, name); if (cs_user && cs_app) { @@ -756,6 +718,25 @@ color_scheme_get(const char *name) return NULL; } +void +color_scheme_apply_from_config(Evas_Object *edje, + const Config *config) +{ + Color_Scheme *cs; + + if (!eina_str_has_suffix(config->theme, "/nord.edj")) + return; + + /* This should be cached in config */ + cs = color_scheme_get("Nord"); + if (!cs) + { + ERR("Could not find color scheme \"%s\"", "Nord"); + return; + } + _colorscheme_apply(edje, cs); +} + void colors_init(void) { diff --git a/src/bin/colors.h b/src/bin/colors.h index ed30ae1b..cfe5d1e7 100644 --- a/src/bin/colors.h +++ b/src/bin/colors.h @@ -58,8 +58,8 @@ colors_256_get(int col, void -color_scheme_apply(Evas_Object *edje, - const Config *config); +color_scheme_apply_from_config(Evas_Object *edje, + const Config *config); void colors_init(void); diff --git a/src/bin/theme.c b/src/bin/theme.c index 0adf1d37..9d1533fa 100644 --- a/src/bin/theme.c +++ b/src/bin/theme.c @@ -64,7 +64,8 @@ theme_apply(Evas_Object *edje, const Config *config, const char *group) EINA_SAFETY_ON_NULL_RETURN_VAL(config, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(group, EINA_FALSE); - /* use default if nord is chosen but rely on color_scheme_apply() */ + /* use default if nord is chosen + * but rely on color_scheme_apply_from_config() */ if (!eina_str_has_suffix(config->theme, "/nord.edj")) { if (edje_object_file_set(edje, config_theme_path_get(config), group)) @@ -83,7 +84,7 @@ theme_apply(Evas_Object *edje, const Config *config, const char *group) return EINA_FALSE; done: - color_scheme_apply(edje, config); + color_scheme_apply_from_config(edje, config); return EINA_TRUE; } @@ -99,7 +100,8 @@ theme_apply_elm(Evas_Object *layout, const Config *config, const char *group) edje = elm_layout_edje_get(layout); - /* use default if nord is chosen but rely on color_scheme_apply() */ + /* use default if nord is chosen + * but rely on color_scheme_apply_from_config() */ if (!eina_str_has_suffix(config->theme, "/nord.edj")) { if (elm_layout_file_set(layout, config_theme_path_get(config), group)) @@ -118,7 +120,7 @@ theme_apply_elm(Evas_Object *layout, const Config *config, const char *group) return EINA_FALSE; done: - color_scheme_apply(edje, config); + color_scheme_apply_from_config(edje, config); return EINA_TRUE; }