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

make border-radius directional #539

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
24 changes: 17 additions & 7 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ void init_default_style(struct mako_style *style) {
style->padding.bottom = 5;
style->padding.left = 5;

style->border_radius.top = 0;
style->border_radius.right = 0;
style->border_radius.bottom = 0;
style->border_radius.left = 0;

style->border_size = 2;
style->border_radius = 0;

#ifdef HAVE_ICONS
style->icons = true;
Expand Down Expand Up @@ -341,7 +345,7 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
target->spec.icon_location = true;
}

if (style->border_radius) {
if (style->spec.border_radius) {
target->border_radius = style->border_radius;
target->spec.border_radius = true;
}
Expand Down Expand Up @@ -407,6 +411,7 @@ bool apply_superset_style(
target->spec.margin = true;
target->spec.padding = true;
target->spec.border_size = true;
target->spec.border_radius = true;
target->spec.icons = true;
target->spec.max_icon_size = true;
target->spec.default_timeout = true;
Expand Down Expand Up @@ -447,6 +452,11 @@ bool apply_superset_style(
target->padding.bottom =
max(style->padding.bottom, target->padding.bottom);
target->padding.left = max(style->padding.left, target->padding.left);
target->border_radius.top = max(style->border_radius.top, target->border_radius.top);
target->border_radius.right = max(style->border_radius.right, target->border_radius.right);
target->border_radius.bottom =
max(style->border_radius.bottom, target->border_radius.bottom);
target->border_radius.left = max(style->border_radius.left, target->border_radius.left);
target->border_size = max(style->border_size, target->border_size);
target->icons = style->icons || target->icons;
target->max_icon_size = max(style->max_icon_size, target->max_icon_size);
Expand Down Expand Up @@ -561,8 +571,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
} else if (strcmp(name, "padding") == 0) {
spec->padding = parse_directional(value, &style->padding);
if (spec->border_radius && spec->padding) {
style->padding.left = max(style->border_radius, style->padding.left);
style->padding.right = max(style->border_radius, style->padding.right);
style->padding.left = max(style->border_radius.left, style->padding.left);
style->padding.right = max(style->border_radius.right, style->padding.right);
}
return spec->padding;
} else if (strcmp(name, "border-size") == 0) {
Expand Down Expand Up @@ -631,10 +641,10 @@ static bool apply_style_option(struct mako_style *style, const char *name,
} else if (strcmp(name, "history") == 0) {
return spec->history = parse_boolean(value, &style->history);
} else if (strcmp(name, "border-radius") == 0) {
spec->border_radius = parse_int_ge(value, &style->border_radius, 0);
spec->border_radius = parse_directional(value, &style->border_radius);
if (spec->border_radius && spec->padding) {
style->padding.left = max(style->border_radius, style->padding.left);
style->padding.right = max(style->border_radius, style->padding.right);
style->padding.left = max(style->border_radius.left, style->padding.left);
style->padding.right = max(style->border_radius.right, style->padding.right);
}
return spec->border_radius;
} else if (strcmp(name, "max-visible") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion contrib/completions/fish/mako.fish
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ complete -c mako -l margin -d 'Margin values in px, comma separated' -x
complete -c mako -l padding -d 'Padding values in px, comma separated' -x
complete -c mako -l border-size -d 'Border size in px' -x
complete -c mako -l border-color -d 'Border color in #RRGGBB[AA]' -x
complete -c mako -l border-radius -d 'Border radius in px' -x
complete -c mako -l border-radius -d 'Border radius values in px,comma separated' -x
complete -c mako -l progress-color -d 'Progress color indicator' -x
complete -c mako -l icons -d 'Show icons or not' -xa "1 0"
complete -c mako -l icon-path -d 'Icon search path, colon delimited' -r
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/zsh/_mako
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _arguments \
'--padding[Padding values, comma separated. Up to four values, with the same meaning as in CSS.]:padding:' \
'--border-size[Border size.]:size:' \
'--border-color[Border color.]:color:' \
'--border-radius[Corner radius values, comma separated. Up to four values, with the same meaning as in CSS.]:radius:' \
'--markup[Enable/disable markup.]:markup enabled:(0 1)' \
'--actions[Applications may request an action to be associated with activating a notification. Disabling this will cause mako to ignore these requests.]:action enabled:(0 1)' \
'--format[Format string.]:format:' \
Expand Down
5 changes: 3 additions & 2 deletions doc/mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ Supported actions:

Default: #4C7899FF

*border-radius*=_px_
Set popup corner radius to _px_ pixels.
*border-radius*=_directional_
Set popup corner radius on each side to the size specified by _directional_. See
*DIRECTIONAL VALUES* for more information.

Default: 0

Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct mako_style {
struct mako_directional outer_margin;
struct mako_directional margin;
struct mako_directional padding;
struct mako_directional border_radius;
int32_t border_size;
int32_t border_radius;

bool icons;
int32_t max_icon_size;
Expand Down
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ static const char usage[] =
" meaning as in CSS.\n"
" --border-size <px> Border size.\n"
" --border-color <color> Border color.\n"
" --border-radius <px> Corner radius\n"
" --border-radius <px>[,<px>...] Corner radius, comma separated.\n"
" Up to four values, with the same\n"
" meaning as in CSS.\n"
" --progress-color <color> Progress indicator color.\n"
" --icons <0|1> Show icons in notifications.\n"
" --icon-path <path>[:<path>...] Icon search path, colon delimited.\n"
Expand Down
34 changes: 22 additions & 12 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ static void move_to(cairo_t *cairo, double x, double y, int scale) {
}

static void set_rounded_rectangle(cairo_t *cairo, double x, double y, double width, double height,
int scale, int radius) {
int scale, int radius_top, int radius_right, int radius_bottom, int radius_left) {
if (width == 0 || height == 0) {
return;
}
x *= scale;
y *= scale;
width *= scale;
height *= scale;
radius *= scale;
radius_top *= scale;
radius_right *= scale;
radius_bottom *= scale;
radius_left *= scale;
double degrees = M_PI / 180.0;

cairo_new_sub_path(cairo);
cairo_arc(cairo, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
cairo_arc(cairo, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
cairo_arc(cairo, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
cairo_arc(cairo, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);

cairo_arc(cairo, x + width - radius_right, y + radius_right, radius_right, -90 * degrees, 0 * degrees);
cairo_arc(cairo, x + width - radius_left, y + height - radius_left, radius_left, 0 * degrees, 90 * degrees);
cairo_arc(cairo, x + radius_bottom, y + height - radius_bottom, radius_bottom, 90 * degrees, 180 * degrees);
cairo_arc(cairo, x + radius_top, y + radius_top, radius_top, 180 * degrees, 270 * degrees);

cairo_close_path(cairo);
}

Expand Down Expand Up @@ -96,7 +101,10 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
int border_size = 2 * style->border_size;
int padding_height = style->padding.top + style->padding.bottom;
int padding_width = style->padding.left + style->padding.right;
int radius = style->border_radius;
int radius_top = style->border_radius.top;
int radius_right = style->border_radius.right;
int radius_bottom = style->border_radius.bottom;
int radius_left = style->border_radius.left;
bool icon_vertical = style->icon_location == MAKO_ICON_LOCATION_TOP ||
style->icon_location == MAKO_ICON_LOCATION_BOTTOM;

Expand Down Expand Up @@ -195,9 +203,11 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
if (icon != NULL && ! icon_vertical && icon->height > text_height) {
notif_height = icon->height + border_size + padding_height;
}

if (notif_height < radius * 2) {
notif_height = radius * 2 + border_size;
if (notif_height < radius_top + radius_bottom) {
notif_height = radius_top + radius_bottom + border_size;
}
if (notif_height < radius_right + radius_left) {
notif_height = radius_right + radius_left + border_size;
}

int notif_background_width = notif_width - style->border_size;
Expand All @@ -210,7 +220,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
offset_y + style->border_size / 2.0,
notif_background_width,
notif_height - style->border_size,
scale, radius);
scale, radius_top, radius_right, radius_bottom, radius_left);

// Render background, keeping the path.
set_source_u32(cairo, style->colors.background);
Expand Down Expand Up @@ -241,7 +251,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
offset_y + style->border_size,
progress_width,
notif_height - style->border_size,
scale, 0);
scale, 0, 0, 0, 0);
cairo_fill(cairo);
cairo_restore(cairo);

Expand Down