Skip to content

Commit

Permalink
Merge pull request #85 from mucamaca/directional-padding
Browse files Browse the repository at this point in the history
Implement directional padding
  • Loading branch information
emersion committed Oct 24, 2018
2 parents 2d8025b + 93f7f65 commit e6aaa24
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
14 changes: 11 additions & 3 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ void init_default_style(struct mako_style *style) {
style->margin.bottom = 10;
style->margin.left = 10;

style->padding = 5;
style->padding.top = 5;
style->padding.right = 5;
style->padding.bottom = 5;
style->padding.left = 5;

style->border_size = 2;

style->font = strdup("monospace 10");
Expand Down Expand Up @@ -235,7 +239,11 @@ bool apply_superset_style(
target->margin.bottom =
max(style->margin.bottom, target->margin.bottom);
target->margin.left = max(style->margin.left, target->margin.left);
target->padding = max(style->padding, target->padding);
target->padding.top = max(style->padding.top, target->padding.top);
target->padding.right = max(style->padding.right, target->padding.right);
target->padding.bottom =
max(style->padding.bottom, target->padding.bottom);
target->padding.left = max(style->padding.left, target->padding.left);
target->border_size = max(style->border_size, target->border_size);
target->default_timeout =
max(style->default_timeout, target->default_timeout);
Expand Down Expand Up @@ -336,7 +344,7 @@ static bool apply_style_option(struct mako_style *style, const char *name,
} else if (strcmp(name, "margin") == 0) {
return spec->margin = parse_directional(value, &style->margin);
} else if (strcmp(name, "padding") == 0) {
return spec->padding = parse_int(value, &style->padding);
return spec->padding = parse_directional(value, &style->padding);
} else if (strcmp(name, "border-size") == 0) {
return spec->border_size = parse_int(value, &style->border_size);
} else if (strcmp(name, "border-color") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct mako_style {
int32_t width;
int32_t height;
struct mako_directional margin;
int32_t padding;
struct mako_directional padding;
int32_t border_size;

char *font;
Expand Down
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ static const char usage[] =
" --margin <px>[,<px>...] Margin values, comma separated.\n"
" Up to four values, with the same\n"
" meaning as in CSS.\n"
" --padding <px> Padding.\n"
" --padding <px>[,<px>...] Padding values, comma separated.\n"
" Up to four values, with the same\n"
" meaning as in CSS.\n"
" --border-size <px> Border size.\n"
" --border-color <color> Border color.\n"
" --markup <0|1> Enable/disable markup.\n"
Expand Down
5 changes: 3 additions & 2 deletions mako.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ dismissed with a click or via *makoctl*(1).

Default: 10

*--padding* _px_
Set padding to _px_ pixels from the edge of the popup.
*--padding* _directional_
Set padding on each side to the size specified by _directional_. See
*DIRECTIONAL VALUES* for more information.

Default: 5

Expand Down
13 changes: 7 additions & 6 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
struct mako_style *style, const char *text, int offset_y, int scale,
struct mako_hotspot *hotspot) {
int border_size = 2 * style->border_size;
int padding_size = 2 * style->padding;
int padding_height = style->padding.top + style->padding.bottom;
int padding_width = style->padding.left + style->padding.right;

// If the compositor has forced us to shrink down, do so.
int notif_width =
Expand All @@ -91,8 +92,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,

PangoLayout *layout = pango_cairo_create_layout(cairo);
set_layout_size(layout,
notif_width - border_size - padding_size,
style->height - border_size - padding_size,
notif_width - border_size - padding_width,
style->height - border_size - padding_height,
scale);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
Expand Down Expand Up @@ -125,7 +126,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
pango_layout_get_pixel_size(layout, NULL, &buffer_text_height);
int text_height = buffer_text_height / scale;

int notif_height = border_size + padding_size + text_height;
int notif_height = border_size + padding_height + text_height;

// Render border
set_source_u32(cairo, style->colors.border);
Expand Down Expand Up @@ -153,8 +154,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
// Render text
set_source_u32(cairo, style->colors.text);
move_to(cairo,
offset_x + style->border_size + style->padding,
offset_y + style->border_size + style->padding,
offset_x + style->border_size + style->padding.left,
offset_y + style->border_size + style->padding.top,
scale);
pango_cairo_update_layout(cairo, layout);
pango_cairo_show_layout(cairo, layout);
Expand Down

0 comments on commit e6aaa24

Please sign in to comment.