Skip to content

Commit 12f4386

Browse files
committed
implement mininum width for notification
fixes #69
1 parent c0c5373 commit 12f4386

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

config.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void finish_config(struct mako_config *config) {
6868
}
6969

7070
void init_default_style(struct mako_style *style) {
71+
style->min_width = 300;
7172
style->width = 300;
7273
style->height = 100;
7374

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

219220
// Now on to actually setting things!
220221

222+
if (style->spec.width) {
223+
target->min_width = style->min_width;
224+
target->spec.min_width = true;
225+
}
226+
221227
if (style->spec.width) {
222228
target->width = style->width;
223229
target->spec.width = true;
@@ -401,6 +407,7 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
401407
bool apply_superset_style(
402408
struct mako_style *target, struct mako_config *config) {
403409
// Specify eveything that we'll be combining.
410+
target->spec.min_width = true;
404411
target->spec.width = true;
405412
target->spec.height = true;
406413
target->spec.outer_margin = true;
@@ -430,6 +437,7 @@ bool apply_superset_style(
430437
// We can cheat and skip checking whether any of these are specified,
431438
// since we're looking for the max and unspecified ones will be
432439
// initialized to zero.
440+
target->min_width = max(style->min_width, target->min_width);
433441
target->width = max(style->width, target->width);
434442
target->height = max(style->height, target->height);
435443
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,
528536
parse_color(value, &style->colors.background);
529537
} else if (strcmp(name, "text-color") == 0) {
530538
return spec->colors.text = parse_color(value, &style->colors.text);
539+
} else if (strcmp(name, "min-width") == 0) {
540+
return spec->min_width = parse_int_ge(value, &style->min_width, 1);
531541
} else if (strcmp(name, "width") == 0) {
532542
return spec->width = parse_int_ge(value, &style->width, 1);
533543
} else if (strcmp(name, "height") == 0) {
@@ -845,6 +855,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
845855
{"font", required_argument, 0, 0},
846856
{"background-color", required_argument, 0, 0},
847857
{"text-color", required_argument, 0, 0},
858+
{"min-width", required_argument, 0, 0},
848859
{"width", required_argument, 0, 0},
849860
{"height", required_argument, 0, 0},
850861
{"outer-margin", required_argument, 0, 0},

doc/mako.5.scd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ Supported actions:
125125

126126
Default: #FFFFFFFF
127127

128+
*min-width*=_px_
129+
Set mininum (dynamic) width of notification popups.
130+
131+
Default: 300
132+
128133
*width*=_px_
129134
Set width of notification popups.
130135

include/config.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ enum mako_icon_location {
3939
// fields in the mako_style structure should have a counterpart here. Inline
4040
// structs are also mirrored.
4141
struct mako_style_spec {
42-
bool width, height, outer_margin, margin, padding, border_size, border_radius, font,
43-
markup, format, text_alignment, actions, default_timeout, ignore_timeout,
44-
icons, max_icon_size, icon_path, group_criteria_spec, invisible, history,
45-
icon_location, max_visible, layer, output, anchor;
42+
bool min_width, width, height, outer_margin, margin, padding, border_size,
43+
border_radius, font, markup, format, text_alignment, actions, default_timeout,
44+
ignore_timeout, icons, max_icon_size, icon_path, group_criteria_spec, invisible,
45+
history, icon_location, max_visible, layer, output, anchor;
4646
struct {
4747
bool background, text, border, progress;
4848
} colors;
@@ -56,6 +56,7 @@ struct mako_style_spec {
5656
struct mako_style {
5757
struct mako_style_spec spec;
5858

59+
int32_t min_width;
5960
int32_t width;
6061
int32_t height;
6162
struct mako_directional outer_margin;

render.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
104104
int notif_width =
105105
(style->width <= surface->width) ? style->width : surface->width;
106106

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

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

176+
notif_width = MAX(style->min_width, text_width + border_size + padding_width);
177+
178+
// offset_x is for the entire draw operation inside the surface
179+
int offset_x;
180+
if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
181+
offset_x = surface->width - notif_width - style->margin.right;
182+
} else if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) {
183+
offset_x = style->margin.left;
184+
} else { // CENTER has nothing to & with, so it's the else case
185+
offset_x = (surface->width - notif_width) / 2;
186+
}
187+
185188
if (text_height > text_layout_height) {
186189
text_height = text_layout_height;
187190
}

0 commit comments

Comments
 (0)