mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 19:35:44 +02:00
bar: deal with NULL exposables
Allow modules to return NULL in begin_expose()
This commit is contained in:
parent
2bb70c6fcb
commit
4d05947985
2 changed files with 14 additions and 4 deletions
15
bar/bar.c
15
bar/bar.c
|
@ -36,19 +36,22 @@ calculate_widths(const struct private *b, int *left, int *center, int *right)
|
||||||
|
|
||||||
for (size_t i = 0; i < b->left.count; i++) {
|
for (size_t i = 0; i < b->left.count; i++) {
|
||||||
struct exposable *e = b->left.exps[i];
|
struct exposable *e = b->left.exps[i];
|
||||||
assert(e != NULL);
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
*left += b->left_spacing + e->width + b->right_spacing;
|
*left += b->left_spacing + e->width + b->right_spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < b->center.count; i++) {
|
for (size_t i = 0; i < b->center.count; i++) {
|
||||||
struct exposable *e = b->center.exps[i];
|
struct exposable *e = b->center.exps[i];
|
||||||
assert(e != NULL);
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
*center += b->left_spacing + e->width + b->right_spacing;
|
*center += b->left_spacing + e->width + b->right_spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < b->right.count; i++) {
|
for (size_t i = 0; i < b->right.count; i++) {
|
||||||
struct exposable *e = b->right.exps[i];
|
struct exposable *e = b->right.exps[i];
|
||||||
assert(e != NULL);
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
*right += b->left_spacing + e->width + b->right_spacing;
|
*right += b->left_spacing + e->width + b->right_spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +119,8 @@ expose(const struct bar *_bar)
|
||||||
int x = bar->border.width + bar->left_margin - bar->left_spacing;
|
int x = bar->border.width + bar->left_margin - bar->left_spacing;
|
||||||
for (size_t i = 0; i < bar->left.count; i++) {
|
for (size_t i = 0; i < bar->left.count; i++) {
|
||||||
const struct exposable *e = bar->left.exps[i];
|
const struct exposable *e = bar->left.exps[i];
|
||||||
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||||
}
|
}
|
||||||
|
@ -123,6 +128,8 @@ expose(const struct bar *_bar)
|
||||||
x = bar->width / 2 - center_width / 2 - bar->left_spacing;
|
x = bar->width / 2 - center_width / 2 - bar->left_spacing;
|
||||||
for (size_t i = 0; i < bar->center.count; i++) {
|
for (size_t i = 0; i < bar->center.count; i++) {
|
||||||
const struct exposable *e = bar->center.exps[i];
|
const struct exposable *e = bar->center.exps[i];
|
||||||
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||||
}
|
}
|
||||||
|
@ -135,6 +142,8 @@ expose(const struct bar *_bar)
|
||||||
|
|
||||||
for (size_t i = 0; i < bar->right.count; i++) {
|
for (size_t i = 0; i < bar->right.count; i++) {
|
||||||
const struct exposable *e = bar->right.exps[i];
|
const struct exposable *e = bar->right.exps[i];
|
||||||
|
if (e == NULL)
|
||||||
|
continue;
|
||||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||||
}
|
}
|
||||||
|
|
1
module.c
1
module.c
|
@ -23,6 +23,7 @@ struct exposable *
|
||||||
module_begin_expose(struct module *mod)
|
module_begin_expose(struct module *mod)
|
||||||
{
|
{
|
||||||
struct exposable *e = mod->content(mod);
|
struct exposable *e = mod->content(mod);
|
||||||
|
if (e != NULL)
|
||||||
e->begin_expose(e);
|
e->begin_expose(e);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue