Skip to content

Commit

Permalink
implement mininum width for notification
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Mar 22, 2024
1 parent c0c5373 commit 12f4386
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
11 changes: 11 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void finish_config(struct mako_config *config) {
}

void init_default_style(struct mako_style *style) {
style->min_width = 300;
style->width = 300;
style->height = 100;

Expand Down Expand Up @@ -218,6 +219,11 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {

// Now on to actually setting things!

if (style->spec.width) {
target->min_width = style->min_width;
target->spec.min_width = true;
}

if (style->spec.width) {
target->width = style->width;
target->spec.width = true;
Expand Down Expand Up @@ -401,6 +407,7 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
bool apply_superset_style(
struct mako_style *target, struct mako_config *config) {
// Specify eveything that we'll be combining.
target->spec.min_width = true;
target->spec.width = true;
target->spec.height = true;
target->spec.outer_margin = true;
Expand Down Expand Up @@ -430,6 +437,7 @@ bool apply_superset_style(
// We can cheat and skip checking whether any of these are specified,
// since we're looking for the max and unspecified ones will be
// initialized to zero.
target->min_width = max(style->min_width, target->min_width);
target->width = max(style->width, target->width);
target->height = max(style->height, target->height);
target->outer_margin.top = max(style->outer_margin.top, target->outer_margin.top);
Expand Down Expand Up @@ -528,6 +536,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
parse_color(value, &style->colors.background);
} else if (strcmp(name, "text-color") == 0) {
return spec->colors.text = parse_color(value, &style->colors.text);
} else if (strcmp(name, "min-width") == 0) {
return spec->min_width = parse_int_ge(value, &style->min_width, 1);
} else if (strcmp(name, "width") == 0) {
return spec->width = parse_int_ge(value, &style->width, 1);
} else if (strcmp(name, "height") == 0) {
Expand Down Expand Up @@ -845,6 +855,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
{"font", required_argument, 0, 0},
{"background-color", required_argument, 0, 0},
{"text-color", required_argument, 0, 0},
{"min-width", required_argument, 0, 0},
{"width", required_argument, 0, 0},
{"height", required_argument, 0, 0},
{"outer-margin", 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 @@ -125,6 +125,11 @@ Supported actions:

Default: #FFFFFFFF

*min-width*=_px_
Set mininum (dynamic) width of notification popups.

Default: 300

*width*=_px_
Set width of notification popups.

Expand Down
9 changes: 5 additions & 4 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ enum mako_icon_location {
// fields in the mako_style structure should have a counterpart here. Inline
// structs are also mirrored.
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,
icon_location, max_visible, layer, output, anchor;
bool min_width, 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, icon_location, max_visible, layer, output, anchor;
struct {
bool background, text, border, progress;
} colors;
Expand All @@ -56,6 +56,7 @@ struct mako_style_spec {
struct mako_style {
struct mako_style_spec spec;

int32_t min_width;
int32_t width;
int32_t height;
struct mako_directional outer_margin;
Expand Down
21 changes: 12 additions & 9 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
int notif_width =
(style->width <= surface->width) ? style->width : surface->width;

// offset_x is for the entire draw operation inside the surface
int offset_x;
if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
offset_x = surface->width - notif_width - style->margin.right;
} else if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) {
offset_x = style->margin.left;
} else { // CENTER has nothing to & with, so it's the else case
offset_x = (surface->width - notif_width) / 2;
}

// text_x is the offset of the text inside our draw operation
double text_x = style->padding.left;
Expand Down Expand Up @@ -182,6 +173,18 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
int text_height = buffer_text_height / scale;
int text_width = buffer_text_width / scale;

notif_width = MAX(style->min_width, text_width + border_size + padding_width);

// offset_x is for the entire draw operation inside the surface
int offset_x;
if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
offset_x = surface->width - notif_width - style->margin.right;
} else if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) {
offset_x = style->margin.left;
} else { // CENTER has nothing to & with, so it's the else case
offset_x = (surface->width - notif_width) / 2;
}

if (text_height > text_layout_height) {
text_height = text_layout_height;
}
Expand Down

0 comments on commit 12f4386

Please sign in to comment.