Skip to content

Commit

Permalink
Move separator color into single struct
Browse files Browse the repository at this point in the history
  • Loading branch information
bebehei committed Feb 12, 2018
1 parent 2615190 commit a1b1136
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
3 changes: 1 addition & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ settings_t defaults = {
.separator_height = 2, /* height of the separator line between two notifications */
.padding = 0,
.h_padding = 0, /* horizontal padding */
.sep_color = AUTO, /* AUTO, FOREGROUND, FRAME, CUSTOM */
.sep_custom_color_str = NULL,/* custom color if sep_color is set to CUSTOM */
.sep_color = {AUTO, NULL}, /* AUTO, FOREGROUND, FRAME, CUSTOM */

.frame_width = 0,
.frame_color = "#888888",
Expand Down
40 changes: 20 additions & 20 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@

settings_t settings;

static enum separator_color parse_sepcolor(const char *string)
static struct separator_color_data parse_sepcolor(const char *string, struct separator_color_data def)
{
//TODO: map good empty separator color
if (strcmp(string, "auto") == 0)
return AUTO;
else if (strcmp(string, "foreground") == 0)
return FOREGROUND;
else if (strcmp(string, "frame") == 0)
return FRAME;
else
return CUSTOM;
if (!string)
return def;

struct separator_color_data ret;

if (strcmp(string, "auto") == 0) {
ret.type = AUTO;
} else if (strcmp(string, "foreground") == 0) {
ret.type = FOREGROUND;
} else if (strcmp(string, "frame") == 0) {
ret.type = FRAME;
} else {
ret.type = CUSTOM;
ret.sep_color = g_strdup(string);
}

return ret;
}


Expand Down Expand Up @@ -412,18 +420,10 @@ void load_settings(const char *cmdline_config_path)
settings.sep_color = parse_sepcolor(option_get_string(
"global", "separator_color",
"-sep_color/-separator_color",
"",
NULL,
"Color of the separator line (or 'auto')"
));
), defaults.sep_color);

if (settings.sep_color == CUSTOM) {
settings.sep_custom_color_str = g_strdup(option_get_string(
"global", "separator_color",
"-sep_color/-separator_color",
"",
"Color of the separator line (or 'auto')"
));
}

settings.stack_duplicates = option_get_bool(
"global", "stack_duplicates",
Expand Down
9 changes: 6 additions & 3 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
enum alignment { left, center, right };
enum ellipsize { start, middle, end };
enum icon_position_t { icons_left, icons_right, icons_off };
enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM };
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL };
enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM };
struct separator_color_data {
enum separator_color type;
char *sep_color;
};

typedef struct _settings {
bool print_notifications;
Expand Down Expand Up @@ -53,8 +57,7 @@ typedef struct _settings {
int separator_height;
int padding;
int h_padding;
enum separator_color sep_color;
char *sep_custom_color_str;
struct separator_color_data sep_color;
int frame_width;
char *frame_color;
int startup_notification;
Expand Down
6 changes: 3 additions & 3 deletions src/x11/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ static color_t calculate_foreground_color(color_t bg)

static color_t x_get_separator_color(colored_layout *cl, colored_layout *cl_next)
{
switch (settings.sep_color) {
switch (settings.sep_color.type) {
case FRAME:
if (cl_next->n->urgency > cl->n->urgency)
return cl_next->frame;
else
return cl->frame;
case CUSTOM:
return x_string_to_color_t(settings.sep_custom_color_str);
return x_string_to_color_t(settings.sep_color.sep_color);
case FOREGROUND:
return cl->fg;
case AUTO:
Expand Down Expand Up @@ -652,7 +652,7 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, colored_layou
color_t sep_color = x_get_separator_color(cl, cl_next);
cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b);

if (settings.sep_color == FRAME)
if (settings.sep_color.type == FRAME)
// Draw over the borders on both sides to avoid
// the wrong color in the corners.
cairo_rectangle(c, 0, dim.y, dim.w, settings.separator_height);
Expand Down

0 comments on commit a1b1136

Please sign in to comment.