Skip to content

Commit

Permalink
Fix vertical alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed May 1, 2024
1 parent 6fafffc commit 8225c09
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout
dim.h += progress_bar_height;
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.w = MAX(settings.width.min, dim.w);
dim.w = MIN(settings.width.max, dim.w);

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

cl->n->displayed_height = dim.h;
return dim;
}
Expand Down Expand Up @@ -711,7 +711,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
// alignment work correctly
layout_setup(cl, width, height, scale);

// NOTE: Includes the last padding
// NOTE: Includes paddings!
int h_without_progress_bar = height;
if (have_progress_bar(cl)) {
h_without_progress_bar -= settings.progress_bar_height + settings.padding;
Expand All @@ -727,7 +727,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
text_y = settings.padding;

if (settings.vertical_alignment == VERTICAL_CENTER) {
text_y += h_without_progress_bar / 2 - text_h / 2;
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;
} // else VERTICAL_TOP
Expand Down Expand Up @@ -765,6 +765,9 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
break;
}

if (image_y < settings.padding || image_y > h_without_progress_bar)
image_y = settings.padding;

// icon position
if (cl->n->icon_position == ICON_TOP) {
image_x = (width - image_width) / 2;
Expand Down
12 changes: 12 additions & 0 deletions test/functional-tests/dunstrc.vertical_align
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
category = .*icon-top.*
icon_position = top

[alignment-left]
category = .*alignment-left.*
alignment = left

[alignment-right]
category = .*alignment-right.*
alignment = right

[alignment-center]
category = .*alignment-center.*
alignment = center

[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/
enable_posix_regex = yes
Expand Down
8 changes: 4 additions & 4 deletions test/functional-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ function dynamic_height {
tmp_dunstrc dunstrc.vertical_align "height = ($min, $max)"
start_dunst dunstrc.tmp

$DUNSTIFY -a "dunst tester" -u l "text" "height min = $min"$'\n'"height max = $max"
$DUNSTIFY -a "dunst tester" -h int:value:$((RANDOM%100)) -u l "text+ progress bar" "height min = $min"$'\n'"height max = $max"
$DUNSTIFY -a "dunst tester" -u n "text + icon" "height min = $min"$'\n'"height max = $max"
$DUNSTIFY -a "dunst tester" -h int:value:$((RANDOM%100)) -u n "text + icon + progress bar" "height min = $min"$'\n'"height max = $max"
$DUNSTIFY -a "dunst tester" -u l "text" "height min = $min, max = $max"
$DUNSTIFY -a "dunst tester" -h int:value:$((RANDOM%100)) -u l "text + progress bar" "height min = $min, max = $max"
$DUNSTIFY -a "dunst tester" -u n "text + icon" "height min = $min, max = $max"
$DUNSTIFY -a "dunst tester" -h int:value:$((RANDOM%100)) -u n "text + icon + progress bar" "height min = $min, max = $max"

$DUNSTIFY -a "dunst tester" -h string:category:hide -u l "text hidden" "SHOULD BE NOT VISIBLE"
$DUNSTIFY -a "dunst tester" -h string:category:hide -h int:value:$((RANDOM%100)) -u l "text hidden + progress bar" "SHOULD BE NOT VISIBLE"
Expand Down

0 comments on commit 8225c09

Please sign in to comment.