diff --git a/config.c b/config.c index 70be717..96ed77b 100644 --- a/config.c +++ b/config.c @@ -96,6 +96,7 @@ void init_default_style(struct mako_style *style) { #endif style->max_icon_size = 64; style->icon_path = strdup(""); // hicolor and pixmaps are implicit. + style->icon_border_radius = 0; style->font = strdup("monospace 10"); style->markup = true; @@ -264,6 +265,11 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) { target->spec.icon_path = true; } + if (style->spec.icon_border_radius) { + target->icon_border_radius = style->icon_border_radius; + target->spec.icon_border_radius = true; + } + if (style->spec.font) { free(target->font); target->font = new_font; @@ -598,6 +604,9 @@ static bool apply_style_option(struct mako_style *style, const char *name, } else if (strcmp(name, "icon-path") == 0) { free(style->icon_path); return spec->icon_path = !!(style->icon_path = strdup(value)); + } else if (strcmp(name, "icon-border-radius") == 0) { + spec->icon_border_radius = parse_int_ge(value, &style->icon_border_radius, 0); + return spec->icon_border_radius; } else if (strcmp(name, "markup") == 0) { return spec->markup = parse_boolean(value, &style->markup); } else if (strcmp(name, "actions") == 0) { @@ -869,6 +878,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) { {"icon-location", required_argument, 0, 0}, {"icon-path", required_argument, 0, 0}, {"max-icon-size", required_argument, 0, 0}, + {"icon-border-radius", required_argument, 0, 0}, {"markup", required_argument, 0, 0}, {"actions", required_argument, 0, 0}, {"format", required_argument, 0, 0}, diff --git a/doc/mako.5.scd b/doc/mako.5.scd index 91378ba..f7188b3 100644 --- a/doc/mako.5.scd +++ b/doc/mako.5.scd @@ -223,6 +223,11 @@ Supported actions: Default: left +*icon-border-radius*=_px_ + Sets icon corner radius to _px_ pixels. + + Default: 0 + *markup*=0|1 If 1, enable Pango markup. If 0, disable Pango markup. If enabled, Pango markup will be interpreted in your format specifier and in the body of diff --git a/icon.c b/icon.c index 3a0d49b..8d8b32b 100644 --- a/icon.c +++ b/icon.c @@ -294,7 +294,7 @@ struct mako_icon *create_icon(struct mako_notification *notif) { #endif void draw_icon(cairo_t *cairo, struct mako_icon *icon, - double xpos, double ypos, double scale) { + double xpos, double ypos, double scale) { cairo_save(cairo); cairo_scale(cairo, scale*icon->scale, scale*icon->scale); cairo_set_source_surface(cairo, icon->image, xpos/icon->scale, ypos/icon->scale); diff --git a/include/config.h b/include/config.h index 013923a..8d0eddb 100644 --- a/include/config.h +++ b/include/config.h @@ -41,7 +41,7 @@ enum mako_icon_location { struct mako_style_spec { bool width, height, outer_margin, margin, padding, border_size, border_radius, font, markup, format, text_alignment, actions, default_timeout, ignore_timeout, - icons, max_icon_size, icon_path, group_criteria_spec, invisible, history, + icons, max_icon_size, icon_path, icon_border_radius, group_criteria_spec, invisible, history, icon_location, max_visible, layer, output, anchor; struct { bool background, text, border, progress; @@ -67,6 +67,7 @@ struct mako_style { bool icons; int32_t max_icon_size; char *icon_path; + int32_t icon_border_radius; char *font; bool markup; diff --git a/include/icon.h b/include/icon.h index 0c5aba0..0941495 100644 --- a/include/icon.h +++ b/include/icon.h @@ -2,12 +2,14 @@ #define MAKO_ICON_H #include +#include #include "notification.h" struct mako_icon { double width; double height; double scale; + int32_t border_radius; cairo_surface_t *image; }; diff --git a/main.c b/main.c index d235cef..897bffe 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,7 @@ static const char usage[] = " --icons <0|1> Show icons in notifications.\n" " --icon-path [:...] Icon search path, colon delimited.\n" " --max-icon-size Set max size of icons.\n" + " --icon-border-radius Icon's corner radius.\n" " --markup <0|1> Enable/disable markup.\n" " --actions <0|1> Enable/disable application action\n" " execution.\n" diff --git a/render.c b/render.c index 5b68632..eafe539 100644 --- a/render.c +++ b/render.c @@ -40,6 +40,11 @@ static void set_rounded_rectangle(cairo_t *cairo, double x, double y, double wid if (width == 0 || height == 0) { return; } + // limit radius to avoid destroying shapes smaller than the given radius + double shortest_side = width > height ? width : height; + if (radius > shortest_side / 2) { + radius = shortest_side / 2; + } x *= scale; y *= scale; width *= scale; @@ -97,6 +102,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct int padding_height = style->padding.top + style->padding.bottom; int padding_width = style->padding.left + style->padding.right; int radius = style->border_radius; + int icon_radius = style->icon_border_radius; bool icon_vertical = style->icon_location == MAKO_ICON_LOCATION_TOP || style->icon_location == MAKO_ICON_LOCATION_BOTTOM; @@ -290,7 +296,11 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct style->padding.bottom - icon->height; break; } + cairo_save(cairo); + set_rounded_rectangle(cairo, xpos, ypos, icon->width, icon->height, scale, icon_radius); + cairo_clip(cairo); draw_icon(cairo, icon, xpos, ypos, scale); + cairo_restore(cairo); } if (icon_vertical) {