diff --git a/config.c b/config.c index ff7e7db..506aa6e 100644 --- a/config.c +++ b/config.c @@ -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; @@ -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; @@ -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; @@ -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); @@ -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) { @@ -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}, diff --git a/doc/mako.5.scd b/doc/mako.5.scd index 557bc16..e449cac 100644 --- a/doc/mako.5.scd +++ b/doc/mako.5.scd @@ -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. diff --git a/include/config.h b/include/config.h index 013923a..6bfbed2 100644 --- a/include/config.h +++ b/include/config.h @@ -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; @@ -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; diff --git a/render.c b/render.c index ad81690..6c35a15 100644 --- a/render.c +++ b/render.c @@ -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; @@ -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; }