diff --git a/config.def.h b/config.def.h index 2071c40..07da68d 100644 --- a/config.def.h +++ b/config.def.h @@ -22,6 +22,11 @@ int verbosity = 0; int word_wrap = False; int line_height = 0; /* a line height < font height will be raised to font height */ +int separator_enabled = False; +float separator_width = 0.7; /* width in relation to window width */ +float separator_height = 0.1; /* height in relation to line_height */ +enum separator_color sep_color = AUTO; /* AUTO or FOREGROUND */ + /* monitor to display notifications on */ int monitor = 0; diff --git a/dunst.c b/dunst.c index fc3459b..967962a 100644 --- a/dunst.c +++ b/dunst.c @@ -507,6 +507,52 @@ int calculate_x_offset(int line_width, int text_width) } } +unsigned long calculate_foreground_color(unsigned long source_color) +{ + Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)); + XColor color; + + color.pixel = source_color; + XQueryColor(dc->dpy, cmap, &color); + + int c_delta = 10000; + + /* do we need to darken or brighten the colors? */ + int darken = (color.red + color.green + color.blue) / 3 > 65535 / 2; + + if (darken) { + if (color.red - c_delta < 0) + color.red = 0; + else + color.red -= c_delta; + if (color.green - c_delta < 0) + color.green = 0; + else + color.green -= c_delta; + if (color.blue - c_delta < 0) + color.blue = 0; + else + color.blue -= c_delta; + } else { + if (color.red + c_delta > 65535) + color.red = 65535; + else + color.red += c_delta; + if (color.green + c_delta > 65535) + color.green = 65535; + else + color.green += c_delta; + if (color.blue + c_delta > 65535) + color.green = 65535; + else + color.green += c_delta; + } + + color.pixel = 0; + XAllocColor(dc->dpy, cmap, &color); + return color.pixel; +} + void draw_win(void) { int width, x, y, height; @@ -536,6 +582,12 @@ void draw_win(void) line_cnt += n->draw_txt_buf.line_count; } + if (separator_enabled) { + line_cnt += l_length(displayed_notifications) - 1; + if (indicate_hidden && !l_is_empty(notification_queue)) + line_cnt++; + } + /* if we have a dynamic width, calculate the actual width */ if (width == 0) { for (l_node * iter = displayed_notifications->head; iter; @@ -619,6 +671,27 @@ void draw_win(void) drawtextn(dc, line, strlen(line), n->colors); dc->y += line_height - ((line_height - font_h) / 2); } + + /* draw separator */ + if (separator_enabled && line_cnt > 1) { + dc->x = 0; + drawrect(dc, 0, 0, width, line_height, True, n->colors->BG); + + double color; + if (sep_color == AUTO) + color = calculate_foreground_color(n->colors->BG); + else + color = n->colors->FG; + + int new_y = dc->y + line_height; + int sep_height = line_height * separator_height; + sep_height = sep_height < 1 ? 1 : sep_height; + int sep_width = width * separator_width; + dc->y = dc->y + (line_height - sep_height) / 2; + dc->x = (width - sep_width) / 2; + drawrect(dc, 0, 0, sep_width, sep_height, True, color); + dc->y = new_y; + } } /* draw x_more */ @@ -1490,7 +1563,6 @@ dunst_ini_handle(void *user_data, const char *section, close_all_ks.str = dunst_ini_get_string(value); } else if (strcmp(name, "history_key") == 0) { history_ks.str = dunst_ini_get_string(value); - } else if (strcmp(name, "alignment") == 0) { if (strcmp(value, "left") == 0) align = left; @@ -1504,6 +1576,24 @@ dunst_ini_handle(void *user_data, const char *section, else if (strcmp(name, "sticky_history") == 0) sticky_history = dunst_ini_get_boolean(value); + + } else if (strcmp(section, "separator") == 0) { + if (strcmp(name, "enable") == 0) + separator_enabled = dunst_ini_get_boolean(value); + if (strcmp(name, "width") == 0) + separator_width = strtod(value, NULL); + if (strcmp(name, "height") == 0) + separator_height = strtod(value, NULL); + if (strcmp(name, "color") == 0) { + char *str = dunst_ini_get_string(value); + if (strcmp(str, "auto") == 0) + sep_color = AUTO; + else if (strcmp(str, "foreground") == 0) + sep_color = FOREGROUND; + else + fprintf(stderr, "Warning: Unknown separator color\n"); + free(str); + } } else if (strcmp(section, "urgency_low") == 0) { if (strcmp(name, "background") == 0) lowbgcolor = dunst_ini_get_string(value); diff --git a/dunst.h b/dunst.h index 3eec1f7..c4ba22d 100644 --- a/dunst.h +++ b/dunst.h @@ -14,6 +14,7 @@ enum alignment { left, center, right }; +enum separator_color { FOREGROUND, AUTO }; typedef struct _rule_t { char *name; diff --git a/dunstrc b/dunstrc index 636d1b5..9620e0c 100644 --- a/dunstrc +++ b/dunstrc @@ -66,6 +66,20 @@ # it will get raised to the font height. line_height = 0 +[separator] + + #enable drawing of separator line + enable = no + + #width of separator line in relation to window width + width = 0.8 + #height of separator line in relation to line height + height = 0.3 + + # color can either be "foreground" to use the foreground color or + # "auto" to generate a fitting color depending on the background color + color = auto + [shortcuts] # shortcuts are specified as [modifier+][modifier+]...key # available modifiers are 'ctrl', 'mod1' (the alt-key), 'mod2', 'mod3'