From d41361a7cdc1a0e949d565a46c72fa8e32ca73f2 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:39:28 +0100 Subject: [PATCH 1/3] refactor --- src/draw.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/draw.c b/src/draw.c index 2b0e74053..67ad2424c 100644 --- a/src/draw.c +++ b/src/draw.c @@ -305,14 +305,14 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout dim.h = MAX(icon_height, dim.text_height); } - dim.h += progress_bar_height; + dim.h += progress_bar_height + settings.padding * 2; dim.w = dim.text_width + icon_width + 2 * settings.h_padding; if (have_progress_bar(cl)) dim.w = MAX(settings.progress_bar_min_width, dim.w); - dim.h = MIN(settings.height.max, dim.h + settings.padding * 2); dim.h = MAX(settings.height.min, dim.h); + dim.h = MIN(settings.height.max, dim.h); dim.w = MAX(settings.width.min, dim.w); dim.w = MIN(settings.width.max, dim.w); @@ -792,7 +792,8 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int if (settings.vertical_alignment == VERTICAL_CENTER) { text_y = h_without_progress_bar / 2 - text_h / 2; } else if (settings.vertical_alignment == VERTICAL_BOTTOM) { - text_y = h_without_progress_bar - settings.padding - text_h; + text_y = h_without_progress_bar + settings.padding - text_h; + if (text_y < 0) text_y = settings.padding; } // else VERTICAL_TOP // icon positioning @@ -927,8 +928,8 @@ static struct dimensions layout_render(cairo_surface_t *srf, get_text_size(cl->l, NULL, &h_text, scale); int bg_width = 0; - int bg_height = MIN(settings.height.max, (2 * settings.padding) + cl_h); - bg_height = MAX(settings.height.min, bg_height); + int bg_height = MAX(settings.height.min, 2 * settings.padding + cl_h); + bg_height = MIN(settings.height.max, bg_height); cairo_surface_t *content = render_background(srf, cl, cl_next, dim.y, dim.w, bg_height, dim.corner_radius, corners, &bg_width, scale); cairo_t *c = cairo_create(content); From 87e089bf46eac28117da8a37652a7b97c1194893 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 01:16:43 +0100 Subject: [PATCH 2/3] Fix height problem --- src/draw.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/draw.c b/src/draw.c index 67ad2424c..ea9a9950d 100644 --- a/src/draw.c +++ b/src/draw.c @@ -265,7 +265,7 @@ static void layout_setup(struct colored_layout *cl, int width, int height, doubl int icon_width = cl->icon ? get_icon_width(cl->icon, scale) + horizontal_padding : 0; int text_width = width - 2 * settings.h_padding - (cl->n->icon_position == ICON_TOP ? 0 : icon_width); int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; - int max_text_height = MAX(0, height - progress_bar_height - 2 * settings.padding); + int max_text_height = MAX(0, settings.height.max - progress_bar_height - 2 * settings.padding); layout_setup_pango(cl->l, text_width, max_text_height, cl->n->word_wrap, cl->n->ellipsize, cl->n->alignment); } @@ -490,7 +490,6 @@ static int layout_get_height(struct colored_layout *cl, double scale) h_progress_bar = settings.progress_bar_height + settings.padding; } - return (cl->n->icon_position == ICON_TOP && cl->n->icon) ? h_icon + h_text + h_progress_bar + vertical_padding : MAX(h_text, h_icon) + h_progress_bar; @@ -924,9 +923,6 @@ static struct dimensions layout_render(cairo_surface_t *srf, double scale = output->get_scale(); const int cl_h = layout_get_height(cl, scale); - int h_text = 0; - get_text_size(cl->l, NULL, &h_text, scale); - int bg_width = 0; int bg_height = MAX(settings.height.min, 2 * settings.padding + cl_h); bg_height = MIN(settings.height.max, bg_height); From e4e5171ca40bbb0de2a06a94c2dc2b72a71a1afe Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 01:32:59 +0100 Subject: [PATCH 3/3] Fix functional tests --- src/draw.c | 2 +- test/functional-tests/dunstrc.hot_reload | 20 ++++++++++++++++++++ test/functional-tests/dunstrc.vertical_align | 2 ++ test/functional-tests/test.sh | 10 ++++++---- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 test/functional-tests/dunstrc.hot_reload diff --git a/src/draw.c b/src/draw.c index ea9a9950d..a5b855077 100644 --- a/src/draw.c +++ b/src/draw.c @@ -791,7 +791,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int if (settings.vertical_alignment == VERTICAL_CENTER) { text_y = h_without_progress_bar / 2 - text_h / 2; } else if (settings.vertical_alignment == VERTICAL_BOTTOM) { - text_y = h_without_progress_bar + settings.padding - text_h; + text_y = h_without_progress_bar - settings.padding - text_h; if (text_y < 0) text_y = settings.padding; } // else VERTICAL_TOP diff --git a/test/functional-tests/dunstrc.hot_reload b/test/functional-tests/dunstrc.hot_reload new file mode 100644 index 000000000..d1a4a7a6d --- /dev/null +++ b/test/functional-tests/dunstrc.hot_reload @@ -0,0 +1,20 @@ +[urgency_low] + background = "#222222" + foreground = "#888888" + timeout = 10 + +[urgency_normal] + background = "#285577" + foreground = "#ffffff" + timeout = 10 + +[urgency_critical] + background = "#900000" + foreground = "#ffffff" + timeout = 0 + +[global] + 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/ + background = "#8f00f8" + icon_position = off + format = "REFORMAT %s\n%b" diff --git a/test/functional-tests/dunstrc.vertical_align b/test/functional-tests/dunstrc.vertical_align index b451c01f8..463e8b38e 100644 --- a/test/functional-tests/dunstrc.vertical_align +++ b/test/functional-tests/dunstrc.vertical_align @@ -7,11 +7,13 @@ background = "#285577" foreground = "#ffffff" timeout = 10 + default_icon = dialog-information [urgency_critical] background = "#900000" foreground = "#ffffff" timeout = 0 + default_icon = dialog-information [hide] category = .*hide.* diff --git a/test/functional-tests/test.sh b/test/functional-tests/test.sh index 43c5cedf1..bec97d246 100755 --- a/test/functional-tests/test.sh +++ b/test/functional-tests/test.sh @@ -157,7 +157,7 @@ function width { } function test_height { - tmp_dunstrc dunstrc.default "height = $1" + tmp_dunstrc dunstrc.default "height = (0, $1)" start_dunst dunstrc.tmp $DUNSTIFY -a "dunst tester" -u c "height = $1" $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 { echo "dynamic_height" echo "###################################" - for max in 50 100 200 ""; do + for max in 50 100 200 300 ""; do for min in 50 100 200 ""; do [[ $min -gt $max ]] && continue @@ -336,14 +336,14 @@ function vertical_align { for valign in top center bottom; do for padding_case in "${padding_cases[@]}"; do - read vertical horizontal icon height label <<<"$padding_case" + read vertical horizontal icon height_min label <<<"$padding_case" padding_settings=" padding = $vertical horizontal_padding = $horizontal text_icon_padding = $icon vertical_alignment = $valign - height = ($height, ) + height = ($height_min, ) " tmp_dunstrc dunstrc.vertical_align "$padding_settings" @@ -353,6 +353,7 @@ function vertical_align { for alignment in left center right; do category="icon-$position-alignment-$alignment" $DUNSTIFY -a "dunst tester" --hints string:category:$category -u n "$category"$'\n'"emphasis: $label"$'\n'"vertical alignment: $valign" + echo $category done done @@ -363,6 +364,7 @@ function vertical_align { for alignment in left center right; do category="icon-$position-alignment-$alignment-hide" $DUNSTIFY -a "dunst tester" --hints string:category:$category -u n "$category"$'\n'"emphasis: $label"$'\n'"vertical alignment: $valign" + echo $category done done