From 53dec73ed2c6be7411551db5533860c928e557f4 Mon Sep 17 00:00:00 2001 From: Delgan Date: Sun, 31 Mar 2024 18:53:57 +0000 Subject: [PATCH] Fix miscalculation of list width in presence of empty particles --- CHANGELOG.md | 2 ++ particles/dynlist.c | 7 ++++--- particles/list.c | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44f1dad..b181fca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ * script: buffer overflow when reading large amounts of data. * i3/sway: module fails when reloading config file ([#361][361]). * Worked around bug in gcc causing a compilation error ([#350][350]). +* Miscalculation of list width in presence of empty particles ([#369][369]). [311]: https://codeberg.org/dnkl/yambar/issues/311 [302]: https://codeberg.org/dnkl/yambar/issues/302 @@ -55,6 +56,7 @@ [352]: https://codeberg.org/dnkl/yambar/issues/352 [361]: https://codeberg.org/dnkl/yambar/issues/361 [350]: https://codeberg.org/dnkl/yambar/issues/350 +[369]: https://codeberg.org/dnkl/yambar/issues/369 ### Security diff --git a/particles/dynlist.c b/particles/dynlist.c index 5b64dbe..85cad7b 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -71,7 +71,8 @@ dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, in for (size_t i = 0; i < e->count; i++) { const struct exposable *ee = e->exposables[i]; ee->expose(ee, pix, x + left_spacing, y, height); - x += left_spacing + e->widths[i] + right_spacing; + if (e->widths[i] > 0) + x += left_spacing + e->widths[i] + right_spacing; } } @@ -95,8 +96,8 @@ on_mouse(struct exposable *exposable, struct bar *bar, } return; } - - px += e->left_spacing + e->exposables[i]->width + e->right_spacing; + if (e->exposables[i]->width > 0) + px += e->left_spacing + e->exposables[i]->width + e->right_spacing; } LOG_DBG("on_mouse missed all sub-particles"); diff --git a/particles/list.c b/particles/list.c index a2c37c6..2887d3c 100644 --- a/particles/list.c +++ b/particles/list.c @@ -80,7 +80,8 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int for (size_t i = 0; i < e->count; i++) { const struct exposable *ee = e->exposables[i]; ee->expose(ee, pix, x + left_spacing, y, height); - x += left_spacing + e->widths[i] + right_spacing; + if (e->widths[i] > 0) + x += left_spacing + e->widths[i] + right_spacing; } } @@ -109,8 +110,8 @@ on_mouse(struct exposable *exposable, struct bar *bar, } return; } - - px += e->left_spacing + e->exposables[i]->width + e->right_spacing; + if (e->exposables[i]->width > 0) + px += e->left_spacing + e->exposables[i]->width + e->right_spacing; } /* We're between sub-particles (or in the left/right margin) */