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

implement mininum width for notification #509

Open
wants to merge 2 commits 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
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 @@ -550,6 +558,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 @@ -856,6 +866,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 @@ -133,6 +133,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
29 changes: 19 additions & 10 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +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;
if (icon != NULL && style->icon_location == MAKO_ICON_LOCATION_LEFT) {
Expand Down Expand Up @@ -182,6 +172,25 @@ 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;

int min_width = text_width + border_size + padding_width;
if (icon && ! icon_vertical) {
min_width += icon->width;
min_width += style->icon_location == MAKO_ICON_LOCATION_LEFT ?
style->padding.left : style->padding.right;
}

notif_width = MAX(style->min_width, min_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