Skip to content

Commit

Permalink
Merge pull request #1411 from bynect/fix-height
Browse files Browse the repository at this point in the history
Fix height problem
  • Loading branch information
bynect authored Dec 10, 2024
2 parents 5149aa7 + e4e5171 commit dd51cbf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
15 changes: 6 additions & 9 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -793,6 +792,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
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;
if (text_y < 0) text_y = settings.padding;
} // else VERTICAL_TOP

// icon positioning
Expand Down Expand Up @@ -923,12 +923,9 @@ 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 = 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);
Expand Down
20 changes: 20 additions & 0 deletions test/functional-tests/dunstrc.hot_reload
Original file line number Diff line number Diff line change
@@ -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 = "<b>REFORMAT %s</b>\n%b"
2 changes: 2 additions & 0 deletions test/functional-tests/dunstrc.vertical_align
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
10 changes: 6 additions & 4 deletions test/functional-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit dd51cbf

Please sign in to comment.