Skip to content

Commit

Permalink
get gradient count from number of configured colors instead of config…
Browse files Browse the repository at this point in the history
… parameter

as discussed in #572
  • Loading branch information
karlstav committed Jun 15, 2024
1 parent d8dca61 commit d59dde4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
46 changes: 26 additions & 20 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool validate_colors(void *params, void *err) {

if (p->gradient) {
if (p->gradient_count < 2) {
write_errorf(error, "\nAtleast two colors must be given as gradient!\n");
write_errorf(error, "\nAt least two colors must be given as gradient!\n");
return false;
}
if (p->gradient_count > 8) {
Expand Down Expand Up @@ -529,20 +529,19 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors
p->bcolor = strdup(iniparser_getstring(ini, "color:background", "default"));

p->gradient = iniparser_getint(ini, "color:gradient", 0);
p->gradient_count = iniparser_getint(ini, "color:gradient_count", 8);
for (int i = 0; i < 8; ++i) {
free(p->gradient_colors[i]);
}
free(p->gradient_colors);
p->gradient_colors = (char **)malloc(sizeof(char *) * p->gradient_count * 9);
p->gradient_colors[0] = strdup(iniparser_getstring(ini, "color:gradient_color_1", "#59cc33"));
p->gradient_colors[1] = strdup(iniparser_getstring(ini, "color:gradient_color_2", "#80cc33"));
p->gradient_colors[2] = strdup(iniparser_getstring(ini, "color:gradient_color_3", "#a6cc33"));
p->gradient_colors[3] = strdup(iniparser_getstring(ini, "color:gradient_color_4", "#cccc33"));
p->gradient_colors[4] = strdup(iniparser_getstring(ini, "color:gradient_color_5", "#cca633"));
p->gradient_colors[5] = strdup(iniparser_getstring(ini, "color:gradient_color_6", "#cc8033"));
p->gradient_colors[6] = strdup(iniparser_getstring(ini, "color:gradient_color_7", "#cc5933"));
p->gradient_colors[7] = strdup(iniparser_getstring(ini, "color:gradient_color_8", "#cc3333"));
p->gradient_colors = (char **)malloc(sizeof(char *) * 8 * 9);
p->gradient_colors[0] = strdup(iniparser_getstring(ini, "color:gradient_color_1", "not_set"));
p->gradient_colors[1] = strdup(iniparser_getstring(ini, "color:gradient_color_2", "not_set"));
p->gradient_colors[2] = strdup(iniparser_getstring(ini, "color:gradient_color_3", "not_set"));
p->gradient_colors[3] = strdup(iniparser_getstring(ini, "color:gradient_color_4", "not_set"));
p->gradient_colors[4] = strdup(iniparser_getstring(ini, "color:gradient_color_5", "not_set"));
p->gradient_colors[5] = strdup(iniparser_getstring(ini, "color:gradient_color_6", "not_set"));
p->gradient_colors[6] = strdup(iniparser_getstring(ini, "color:gradient_color_7", "not_set"));
p->gradient_colors[7] = strdup(iniparser_getstring(ini, "color:gradient_color_8", "not_set"));

#else
outputMethod = malloc(sizeof(char) * 32);
Expand All @@ -562,26 +561,33 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors
GetPrivateProfileString("color", "foreground", "default", p->color, 9, configPath);
GetPrivateProfileString("color", "background", "default", p->bcolor, 9, configPath);
p->gradient = GetPrivateProfileInt("color", "gradient", 0, configPath);
p->gradient_count = GetPrivateProfileInt("color", "gradient_count", 8, configPath);

GetPrivateProfileString("color", "gradient_color_1", "#59cc33", p->gradient_colors[0], 9,
GetPrivateProfileString("color", "gradient_color_1", "not_set", p->gradient_colors[0], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_2", "#80cc33", p->gradient_colors[1], 9,
GetPrivateProfileString("color", "gradient_color_2", "not_set", p->gradient_colors[1], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_3", "#a6cc33", p->gradient_colors[2], 9,
GetPrivateProfileString("color", "gradient_color_3", "not_set", p->gradient_colors[2], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_4", "#cccc33", p->gradient_colors[3], 9,
GetPrivateProfileString("color", "gradient_color_4", "not_set", p->gradient_colors[3], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_5", "#cca633", p->gradient_colors[4], 9,
GetPrivateProfileString("color", "gradient_color_5", "not_set", p->gradient_colors[4], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_6", "#cc8033", p->gradient_colors[5], 9,
GetPrivateProfileString("color", "gradient_color_6", "not_set", p->gradient_colors[5], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_7", "#cc5933", p->gradient_colors[6], 9,
GetPrivateProfileString("color", "gradient_color_7", "not_set", p->gradient_colors[6], 9,
configPath);
GetPrivateProfileString("color", "gradient_color_8", "#cc3333", p->gradient_colors[7], 9,
GetPrivateProfileString("color", "gradient_color_8", "not_set", p->gradient_colors[7], 9,
configPath);

#endif
p->gradient_count = 0;
for (int i = 0; i < 7; ++i) {
if (strcmp(p->gradient_colors[i], "not_set") != 0)
p->gradient_count++;
else
break;
}

if (colorsOnly) {
return validate_colors(p, error);
}
Expand Down
1 change: 0 additions & 1 deletion example_files/config
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@
# background must also be defined in hex or remain commented out. 1 = on, 0 = off.
# You can define as many as 8 different colors. They range from bottom to top of screen
; gradient = 0
; gradient_count = 8
; gradient_color_1 = '#59cc33'
; gradient_color_2 = '#80cc33'
; gradient_color_3 = '#a6cc33'
Expand Down

0 comments on commit d59dde4

Please sign in to comment.