Skip to content

Commit 4ac7596

Browse files
committed
Fix vertical alignment
1 parent 6fafffc commit 4ac7596

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/draw.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout
245245
dim.h += progress_bar_height;
246246
dim.w = dim.text_width + icon_width + 2 * settings.h_padding;
247247

248+
if (have_progress_bar(cl))
249+
dim.w = MAX(settings.progress_bar_min_width, dim.w);
250+
248251
dim.h = MIN(settings.height.max, dim.h + settings.padding * 2);
249252
dim.h = MAX(settings.height.min, dim.h);
250253

251254
dim.w = MAX(settings.width.min, dim.w);
252255
dim.w = MIN(settings.width.max, dim.w);
253256

254-
if (have_progress_bar(cl))
255-
dim.w = MAX(settings.progress_bar_min_width, dim.w);
256-
257257
cl->n->displayed_height = dim.h;
258258
return dim;
259259
}
@@ -711,7 +711,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
711711
// alignment work correctly
712712
layout_setup(cl, width, height, scale);
713713

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

729729
if (settings.vertical_alignment == VERTICAL_CENTER) {
730-
text_y += h_without_progress_bar / 2 - text_h / 2;
730+
text_y = h_without_progress_bar / 2 - text_h / 2;
731731
} else if (settings.vertical_alignment == VERTICAL_BOTTOM) {
732732
text_y = h_without_progress_bar - settings.padding - text_h;
733733
} // else VERTICAL_TOP
@@ -743,21 +743,22 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
743743
// vertical alignment
744744
switch (settings.vertical_alignment) {
745745
case VERTICAL_TOP:
746-
if (cl->n->hide_text || cl->n->icon_position == ICON_TOP) {
746+
if (cl->n->icon_position == ICON_TOP) {
747+
// Shift text downward
747748
text_y += image_height + v_padding;
748749
}
749750
break;
750751
case VERTICAL_CENTER:
751-
if (cl->n->hide_text || cl->n->icon_position == ICON_TOP) {
752-
// Shift text downward
752+
if (cl->n->icon_position == ICON_TOP) {
753+
// Adjust text and image by half
753754
image_y -= (image_height + v_padding) / 2;
754755
text_y += (image_height + v_padding) / 2;
755756
} else {
756757
image_y += text_h / 2 - image_height / 2;
757758
}
758759
break;
759760
case VERTICAL_BOTTOM:
760-
if (cl->n->hide_text || cl->n->icon_position == ICON_TOP) {
761+
if (cl->n->icon_position == ICON_TOP) {
761762
image_y -= image_height + v_padding;
762763
} else {
763764
image_y -= image_height - text_h;

test/functional-tests/dunstrc.vertical_align

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
category = .*icon-top.*
3434
icon_position = top
3535

36+
[alignment-left]
37+
category = .*alignment-left.*
38+
alignment = left
39+
40+
[alignment-right]
41+
category = .*alignment-right.*
42+
alignment = right
43+
44+
[alignment-center]
45+
category = .*alignment-center.*
46+
alignment = center
47+
3648
[global]
3749
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/
3850
enable_posix_regex = yes

test/functional-tests/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ function dynamic_height {
296296
tmp_dunstrc dunstrc.vertical_align "height = ($min, $max)"
297297
start_dunst dunstrc.tmp
298298

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

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

0 commit comments

Comments
 (0)