Skip to content

Commit 7928ced

Browse files
committed
implement mininum width for notification
fixes #69
1 parent 0d0e662 commit 7928ced

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

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 = 0;
7172
style->width = 300;
7273
style->height = 100;
7374

@@ -223,6 +224,11 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
223224

224225
// Now on to actually setting things!
225226

227+
if (style->spec.width) {
228+
target->min_width = style->min_width;
229+
target->spec.min_width = true;
230+
}
231+
226232
if (style->spec.width) {
227233
target->width = style->width;
228234
target->spec.width = true;
@@ -411,6 +417,7 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
411417
bool apply_superset_style(
412418
struct mako_style *target, struct mako_config *config) {
413419
// Specify eveything that we'll be combining.
420+
target->spec.min_width = true;
414421
target->spec.width = true;
415422
target->spec.height = true;
416423
target->spec.outer_margin = true;
@@ -441,6 +448,7 @@ bool apply_superset_style(
441448
// We can cheat and skip checking whether any of these are specified,
442449
// since we're looking for the max and unspecified ones will be
443450
// initialized to zero.
451+
target->min_width = max(style->min_width, target->min_width);
444452
target->width = max(style->width, target->width);
445453
target->height = max(style->height, target->height);
446454
target->outer_margin.top = max(style->outer_margin.top, target->outer_margin.top);
@@ -566,6 +574,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
566574
parse_color(value, &style->colors.background);
567575
} else if (strcmp(name, "text-color") == 0) {
568576
return spec->colors.text = parse_color(value, &style->colors.text);
577+
} else if (strcmp(name, "min-width") == 0) {
578+
return spec->min_width = parse_int_ge(value, &style->min_width, 1);
569579
} else if (strcmp(name, "width") == 0) {
570580
return spec->width = parse_int_ge(value, &style->width, 1);
571581
} else if (strcmp(name, "height") == 0) {
@@ -901,6 +911,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
901911
{"text-color", required_argument, 0, 0},
902912
{"width", required_argument, 0, 0},
903913
{"height", required_argument, 0, 0},
914+
{"min-width", required_argument, 0, 0},
904915
{"outer-margin", required_argument, 0, 0},
905916
{"margin", required_argument, 0, 0},
906917
{"padding", required_argument, 0, 0},

doc/mako.5.scd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ Supported actions:
138138

139139
Default: 300
140140

141+
*min-width*=_px_
142+
Set mininum (dynamic) width of notification popups.
143+
The normal width of notifications will be considered
144+
the maximum notification width.
145+
Set to 0 to disable.
146+
147+
Default: 0
148+
141149
*height*=_px_
142150
Set maximum height of notification popups. Notifications whose text takes
143151
up less space are shrunk to fit.

include/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ 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,
42+
bool width, min_width, height, outer_margin, margin, padding, border_size, border_radius, font,
4343
markup, format, text_alignment, actions, default_timeout, ignore_timeout,
4444
icons, max_icon_size, icon_path, icon_border_radius, group_criteria_spec, invisible, history,
4545
icon_location, max_visible, layer, output, anchor;
@@ -57,6 +57,7 @@ struct mako_style {
5757
struct mako_style_spec spec;
5858

5959
int32_t width;
60+
int32_t min_width;
6061
int32_t height;
6162
struct mako_directional outer_margin;
6263
struct mako_directional margin;

main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ static const char usage[] =
2121
" --text-color <color> Text color.\n"
2222
" --width <px> Notification width.\n"
2323
" --height <px> Max notification height.\n"
24+
" --min-width <px> Minimum notification width, with\n"
25+
" the normal notification width acting\n"
26+
" as the maximum.\n"
2427
" --outer-margin <px>[,<px>...] Outer margin values, comma separated.\n"
2528
" Up to four values, with the same\n"
2629
" meaning as in CSS.\n"

render.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
113113
int notif_width =
114114
(style->width <= surface->width) ? style->width : surface->width;
115115

116-
// offset_x is for the entire draw operation inside the surface
117-
int offset_x;
118-
if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
119-
offset_x = surface->width - notif_width - style->margin.right;
120-
} else if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) {
121-
offset_x = style->margin.left;
122-
} else { // CENTER has nothing to & with, so it's the else case
123-
offset_x = (surface->width - notif_width) / 2;
124-
}
125-
126116
// text_x is the offset of the text inside our draw operation
127117
double text_x = style->padding.left;
128118
if (icon != NULL && style->icon_location == MAKO_ICON_LOCATION_LEFT) {
@@ -191,6 +181,27 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
191181
int text_height = buffer_text_height / scale;
192182
int text_width = buffer_text_width / scale;
193183

184+
if (style->min_width > 0) {
185+
int min_width = text_width + border_size + padding_width;
186+
if (icon && ! icon_vertical) {
187+
min_width += icon->width;
188+
min_width += style->icon_location == MAKO_ICON_LOCATION_LEFT ?
189+
style->padding.left : style->padding.right;
190+
}
191+
192+
notif_width = MAX(style->min_width, min_width);
193+
}
194+
195+
// offset_x is for the entire draw operation inside the surface
196+
int offset_x;
197+
if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
198+
offset_x = surface->width - notif_width - style->margin.right;
199+
} else if (surface->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) {
200+
offset_x = style->margin.left;
201+
} else { // CENTER has nothing to & with, so it's the else case
202+
offset_x = (surface->width - notif_width) / 2;
203+
}
204+
194205
if (text_height > text_layout_height) {
195206
text_height = text_layout_height;
196207
}

0 commit comments

Comments
 (0)