Skip to content

Commit dd51cbf

Browse files
authored
Merge pull request #1411 from bynect/fix-height
Fix height problem
2 parents 5149aa7 + e4e5171 commit dd51cbf

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

src/draw.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void layout_setup(struct colored_layout *cl, int width, int height, doubl
265265
int icon_width = cl->icon ? get_icon_width(cl->icon, scale) + horizontal_padding : 0;
266266
int text_width = width - 2 * settings.h_padding - (cl->n->icon_position == ICON_TOP ? 0 : icon_width);
267267
int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0;
268-
int max_text_height = MAX(0, height - progress_bar_height - 2 * settings.padding);
268+
int max_text_height = MAX(0, settings.height.max - progress_bar_height - 2 * settings.padding);
269269
layout_setup_pango(cl->l, text_width, max_text_height, cl->n->word_wrap, cl->n->ellipsize, cl->n->alignment);
270270
}
271271

@@ -305,14 +305,14 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout
305305
dim.h = MAX(icon_height, dim.text_height);
306306
}
307307

308-
dim.h += progress_bar_height;
308+
dim.h += progress_bar_height + settings.padding * 2;
309309
dim.w = dim.text_width + icon_width + 2 * settings.h_padding;
310310

311311
if (have_progress_bar(cl))
312312
dim.w = MAX(settings.progress_bar_min_width, dim.w);
313313

314-
dim.h = MIN(settings.height.max, dim.h + settings.padding * 2);
315314
dim.h = MAX(settings.height.min, dim.h);
315+
dim.h = MIN(settings.height.max, dim.h);
316316

317317
dim.w = MAX(settings.width.min, dim.w);
318318
dim.w = MIN(settings.width.max, dim.w);
@@ -490,7 +490,6 @@ static int layout_get_height(struct colored_layout *cl, double scale)
490490
h_progress_bar = settings.progress_bar_height + settings.padding;
491491
}
492492

493-
494493
return (cl->n->icon_position == ICON_TOP && cl->n->icon)
495494
? h_icon + h_text + h_progress_bar + vertical_padding
496495
: MAX(h_text, h_icon) + h_progress_bar;
@@ -793,6 +792,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
793792
text_y = h_without_progress_bar / 2 - text_h / 2;
794793
} else if (settings.vertical_alignment == VERTICAL_BOTTOM) {
795794
text_y = h_without_progress_bar - settings.padding - text_h;
795+
if (text_y < 0) text_y = settings.padding;
796796
} // else VERTICAL_TOP
797797

798798
// icon positioning
@@ -923,12 +923,9 @@ static struct dimensions layout_render(cairo_surface_t *srf,
923923
double scale = output->get_scale();
924924
const int cl_h = layout_get_height(cl, scale);
925925

926-
int h_text = 0;
927-
get_text_size(cl->l, NULL, &h_text, scale);
928-
929926
int bg_width = 0;
930-
int bg_height = MIN(settings.height.max, (2 * settings.padding) + cl_h);
931-
bg_height = MAX(settings.height.min, bg_height);
927+
int bg_height = MAX(settings.height.min, 2 * settings.padding + cl_h);
928+
bg_height = MIN(settings.height.max, bg_height);
932929

933930
cairo_surface_t *content = render_background(srf, cl, cl_next, dim.y, dim.w, bg_height, dim.corner_radius, corners, &bg_width, scale);
934931
cairo_t *c = cairo_create(content);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[urgency_low]
2+
background = "#222222"
3+
foreground = "#888888"
4+
timeout = 10
5+
6+
[urgency_normal]
7+
background = "#285577"
8+
foreground = "#ffffff"
9+
timeout = 10
10+
11+
[urgency_critical]
12+
background = "#900000"
13+
foreground = "#ffffff"
14+
timeout = 0
15+
16+
[global]
17+
icon_path = /usr/share/icons/Papirus/24x24/status/:/usr/share/icons/Papirus/24x24/devices/:/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/
18+
background = "#8f00f8"
19+
icon_position = off
20+
format = "<b>REFORMAT %s</b>\n%b"

test/functional-tests/dunstrc.vertical_align

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
background = "#285577"
88
foreground = "#ffffff"
99
timeout = 10
10+
default_icon = dialog-information
1011

1112
[urgency_critical]
1213
background = "#900000"
1314
foreground = "#ffffff"
1415
timeout = 0
16+
default_icon = dialog-information
1517

1618
[hide]
1719
category = .*hide.*

test/functional-tests/test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function width {
157157
}
158158

159159
function test_height {
160-
tmp_dunstrc dunstrc.default "height = $1"
160+
tmp_dunstrc dunstrc.default "height = (0, $1)"
161161
start_dunst dunstrc.tmp
162162
$DUNSTIFY -a "dunst tester" -u c "height = $1"
163163
$DUNSTIFY -a "dunst tester" -u c "Temporibus accusantium libero sequi at nostrum dolor sequi sed. Cum minus reprehenderit voluptatibus laboriosam et et ut. Laudantium blanditiis omnis ipsa rerum quas velit ut. Quae voluptate soluta enim consequatur libero eum similique ad. Veritatis neque consequatur et aperiam quisquam id nostrum. Consequatur voluptas aut ut omnis atque cum perferendis. Possimus laudantium tempore iste qui nemo voluptate quod. Labore totam debitis consectetur amet. Maxime quibusdam ipsum voluptates quod ex nam sunt. Officiis repellat quod maxime cumque tenetur. Veritatis labore aperiam repellendus. Provident dignissimos ducimus voluptates."
@@ -299,7 +299,7 @@ function dynamic_height {
299299
echo "dynamic_height"
300300
echo "###################################"
301301

302-
for max in 50 100 200 ""; do
302+
for max in 50 100 200 300 ""; do
303303
for min in 50 100 200 ""; do
304304
[[ $min -gt $max ]] && continue
305305

@@ -336,14 +336,14 @@ function vertical_align {
336336

337337
for valign in top center bottom; do
338338
for padding_case in "${padding_cases[@]}"; do
339-
read vertical horizontal icon height label <<<"$padding_case"
339+
read vertical horizontal icon height_min label <<<"$padding_case"
340340

341341
padding_settings="
342342
padding = $vertical
343343
horizontal_padding = $horizontal
344344
text_icon_padding = $icon
345345
vertical_alignment = $valign
346-
height = ($height, )
346+
height = ($height_min, )
347347
"
348348

349349
tmp_dunstrc dunstrc.vertical_align "$padding_settings"
@@ -353,6 +353,7 @@ function vertical_align {
353353
for alignment in left center right; do
354354
category="icon-$position-alignment-$alignment"
355355
$DUNSTIFY -a "dunst tester" --hints string:category:$category -u n "$category"$'\n'"emphasis: $label"$'\n'"vertical alignment: $valign"
356+
echo $category
356357
done
357358
done
358359

@@ -363,6 +364,7 @@ function vertical_align {
363364
for alignment in left center right; do
364365
category="icon-$position-alignment-$alignment-hide"
365366
$DUNSTIFY -a "dunst tester" --hints string:category:$category -u n "$category"$'\n'"emphasis: $label"$'\n'"vertical alignment: $valign"
367+
echo $category
366368
done
367369
done
368370

0 commit comments

Comments
 (0)