Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: icon-border-radius #528

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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},
Expand Down
5 changes: 5 additions & 0 deletions doc/mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#define MAKO_ICON_H

#include <cairo/cairo.h>
#include <stdint.h>
#include "notification.h"

struct mako_icon {
double width;
double height;
double scale;
int32_t border_radius;
cairo_surface_t *image;
};

Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static const char usage[] =
" --icons <0|1> Show icons in notifications.\n"
" --icon-path <path>[:<path>...] Icon search path, colon delimited.\n"
" --max-icon-size <px> Set max size of icons.\n"
" --icon-border-radius <px> Icon's corner radius.\n"
" --markup <0|1> Enable/disable markup.\n"
" --actions <0|1> Enable/disable application action\n"
" execution.\n"
Expand Down
10 changes: 10 additions & 0 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down