diff --git a/bar/bar.c b/bar/bar.c index 21d95c5..b29936b 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -55,9 +55,16 @@ calculate_widths(const struct private *b, int *left, int *center, int *right) } /* No spacing on the edges (that's what the margins are for) */ - *left -= b->left_spacing + b->right_spacing; - *center -= b->left_spacing + b->right_spacing; - *right -= b->left_spacing + b->right_spacing; + if (*left > 0) + *left -= b->left_spacing + b->right_spacing; + if (*center > 0) + *center -= b->left_spacing + b->right_spacing; + if (*right > 0) + *right -= b->left_spacing + b->right_spacing; + + assert(*left >= 0); + assert(*center >= 0); + assert(*right >= 0); } static void @@ -99,6 +106,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->left.exps[i] = module_begin_expose(m); + assert(bar->left.exps[i]->width >= 0); } for (size_t i = 0; i < bar->center.count; i++) { @@ -107,6 +115,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->center.exps[i] = module_begin_expose(m); + assert(bar->center.exps[i]->width >= 0); } for (size_t i = 0; i < bar->right.count; i++) { @@ -115,6 +124,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->right.exps[i] = module_begin_expose(m); + assert(bar->right.exps[i]->width >= 0); } int left_width, center_width, right_width; @@ -196,7 +206,8 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, for (size_t i = 0; i < bar->left.count; i++) { struct exposable *e = bar->left.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { @@ -212,7 +223,8 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, for (size_t i = 0; i < bar->center.count; i++) { struct exposable *e = bar->center.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { @@ -224,15 +236,16 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, mx += e->width + bar->right_spacing; } - mx = bar->width - (right_width - + bar->left_spacing + + mx = bar->width - (right_width + + bar->left_spacing + bar->right_margin + bar->border.right_width); for (size_t i = 0; i < bar->right.count; i++) { struct exposable *e = bar->right.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { diff --git a/particles/dynlist.c b/particles/dynlist.c index 8c6319c..5b64dbe 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -1,6 +1,7 @@ #include "dynlist.h" #include +#include #define LOG_MODULE "dynlist" #include "../log.h" @@ -36,15 +37,24 @@ dynlist_begin_expose(struct exposable *exposable) const struct private *e = exposable->private; exposable->width = 0; + bool have_at_least_one = false; for (size_t i = 0; i < e->count; i++) { struct exposable *ee = e->exposables[i]; e->widths[i] = ee->begin_expose(ee); - exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + assert(e->widths[i] >= 0); + + if (e->widths[i] > 0) { + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + have_at_least_one = true; + } } - exposable->width -= e->left_spacing + e->right_spacing; + if (have_at_least_one) + exposable->width -= e->left_spacing + e->right_spacing; + else + assert(exposable->width == 0); return exposable->width; } diff --git a/particles/list.c b/particles/list.c index 9f03231..19ff15b 100644 --- a/particles/list.c +++ b/particles/list.c @@ -39,18 +39,29 @@ static int begin_expose(struct exposable *exposable) { const struct eprivate *e = exposable->private; + bool have_at_least_one = false; - exposable->width = exposable->particle->left_margin; + exposable->width = 0; for (size_t i = 0; i < e->count; i++) { struct exposable *ee = e->exposables[i]; e->widths[i] = ee->begin_expose(ee); - exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + assert(e->widths[i] >= 0); + + if (e->widths[i] > 0) { + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + have_at_least_one = true; + } } - exposable->width -= e->left_spacing + e->right_spacing; - exposable->width += exposable->particle->right_margin; + if (have_at_least_one) { + exposable->width -= e->left_spacing + e->right_spacing; + exposable->width += exposable->particle->left_margin; + exposable->width += exposable->particle->right_margin; + } else + assert(exposable->width == 0); + return exposable->width; } diff --git a/particles/map.c b/particles/map.c index e2d8c03..980bdd1 100644 --- a/particles/map.c +++ b/particles/map.c @@ -41,11 +41,13 @@ begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; - exposable->width = ( - exposable->particle->left_margin + - e->exposable->begin_expose(e->exposable) + - exposable->particle->right_margin); + int width = e->exposable->begin_expose(e->exposable); + assert(width >= 0); + if (width > 0) + width += exposable->particle->left_margin + exposable->particle->right_margin; + + exposable->width = width; return exposable->width; } diff --git a/particles/progress-bar.c b/particles/progress-bar.c index 52d1e74..7011feb 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -57,14 +57,27 @@ static int begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; + bool have_at_least_one = false; - /* Margins */ - exposable->width = exposable->particle->left_margin + - exposable->particle->right_margin; + exposable->width = 0; /* Sub-exposables */ - for (size_t i = 0; i < e->count; i++) - exposable->width += e->exposables[i]->begin_expose(e->exposables[i]); + for (size_t i = 0; i < e->count; i++) { + int width = e->exposables[i]->begin_expose(e->exposables[i]); + + assert(width >= 0); + if (width >= 0) { + exposable->width += width; + have_at_least_one = true; + } + } + + /* Margins */ + if (have_at_least_one) { + exposable->width = exposable->particle->left_margin + + exposable->particle->right_margin; + } else + assert(exposable->width == 0); return exposable->width; } diff --git a/particles/ramp.c b/particles/ramp.c index 3fa2fc8..1d4cb59 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -37,11 +37,13 @@ begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; - exposable->width = ( - exposable->particle->left_margin + - e->exposable->begin_expose(e->exposable) + - exposable->particle->right_margin); + int width = e->exposable->begin_expose(e->exposable); + assert(width >= 0); + if (width > 0) + width += exposable->particle->left_margin + exposable->particle->right_margin; + + exposable->width = width; return exposable->width; }