From 910522262f9fa0fc9ad194620fe727dc23fe6a2c Mon Sep 17 00:00:00 2001 From: Nulo Date: Wed, 11 Aug 2021 17:03:34 -0300 Subject: [PATCH] Only add spacing if the module is not empty If the module is empty (width is 0) no spacing will be rendered for it. This makes modules that auto-hide (for example, network modules for interfaces not used all of the time) occupy no space in the bar. --- CHANGELOG.md | 5 +++++ bar/bar.c | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d27aea..b833b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ ### Changed + +* bar: hide spacing of modules which are empty (width = 0) + + ### Deprecated ### Removed ### Fixed @@ -36,6 +40,7 @@ * [paemuri](https://codeberg.org/paemuri) * [ericonr](https://codeberg.org/ericonr) +* [Nulo](https://nulo.in) ## 1.6.2 diff --git a/bar/bar.c b/bar/bar.c index 9d1b0cc..9d07830 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -38,17 +38,20 @@ calculate_widths(const struct private *b, int *left, int *center, int *right) for (size_t i = 0; i < b->left.count; i++) { struct exposable *e = b->left.exps[i]; - *left += b->left_spacing + e->width + b->right_spacing; + if (e->width > 0) + *left += b->left_spacing + e->width + b->right_spacing; } for (size_t i = 0; i < b->center.count; i++) { struct exposable *e = b->center.exps[i]; - *center += b->left_spacing + e->width + b->right_spacing; + if (e->width > 0) + *center += b->left_spacing + e->width + b->right_spacing; } for (size_t i = 0; i < b->right.count; i++) { struct exposable *e = b->right.exps[i]; - *right += b->left_spacing + e->width + b->right_spacing; + if (e->width > 0) + *right += b->left_spacing + e->width + b->right_spacing; } /* No spacing on the edges (that's what the margins are for) */ @@ -122,14 +125,16 @@ expose(const struct bar *_bar) for (size_t i = 0; i < bar->left.count; i++) { const struct exposable *e = bar->left.exps[i]; e->expose(e, pix, x + bar->left_spacing, y, bar->height); - x += bar->left_spacing + e->width + bar->right_spacing; + if (e->width > 0) + x += bar->left_spacing + e->width + bar->right_spacing; } x = bar->width / 2 - center_width / 2 - bar->left_spacing; for (size_t i = 0; i < bar->center.count; i++) { const struct exposable *e = bar->center.exps[i]; e->expose(e, pix, x + bar->left_spacing, y, bar->height); - x += bar->left_spacing + e->width + bar->right_spacing; + if (e->width > 0) + x += bar->left_spacing + e->width + bar->right_spacing; } x = bar->width - ( @@ -141,7 +146,8 @@ expose(const struct bar *_bar) for (size_t i = 0; i < bar->right.count; i++) { const struct exposable *e = bar->right.exps[i]; e->expose(e, pix, x + bar->left_spacing, y, bar->height); - x += bar->left_spacing + e->width + bar->right_spacing; + if (e->width > 0) + x += bar->left_spacing + e->width + bar->right_spacing; } bar->backend.iface->commit(_bar); @@ -190,6 +196,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; + mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL) @@ -204,6 +212,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; + mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL) @@ -222,6 +232,8 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, for (size_t i = 0; i < bar->right.count; i++) { struct exposable *e = bar->right.exps[i]; + if (e->width == 0) continue; + mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL)