From ce68bdb59d99b9969f948ece98f7c9fcd5fef731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 26 Dec 2018 16:37:11 +0100 Subject: [PATCH] exposable: add a 'width' member, set (at latest) in begin_expose() --- modules/i3/dynlist-exposable.c | 10 +++++----- particle.h | 4 +++- particles/list.c | 16 ++++++++++------ particles/string.c | 18 ++++++++---------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/modules/i3/dynlist-exposable.c b/modules/i3/dynlist-exposable.c index 8beac61..4f868e1 100644 --- a/modules/i3/dynlist-exposable.c +++ b/modules/i3/dynlist-exposable.c @@ -12,21 +12,21 @@ struct private { }; static int -dynlist_begin_expose(const struct exposable *exposable, cairo_t *cr) +dynlist_begin_expose(struct exposable *exposable, cairo_t *cr) { const struct private *e = exposable->private; - int width = 0; + 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, cr); - width += e->left_spacing + e->widths[i] + e->right_spacing; + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; } - width -= e->left_spacing + e->right_spacing; - return width; + exposable->width -= e->left_spacing + e->right_spacing; + return exposable->width; } static void diff --git a/particle.h b/particle.h index 22c928b..56f2222 100644 --- a/particle.h +++ b/particle.h @@ -26,8 +26,10 @@ struct exposable { const struct particle *particle; void *private; + int width; /* Should be set by begin_expose(), at latest */ + void (*destroy)(struct exposable *exposable); - int (*begin_expose)(const struct exposable *exposable, cairo_t *cr); + int (*begin_expose)(struct exposable *exposable, cairo_t *cr); void (*expose)(const struct exposable *exposable, cairo_t *cr, int x, int y, int height); }; diff --git a/particles/list.c b/particles/list.c index 45fb846..d4cfdb2 100644 --- a/particles/list.c +++ b/particles/list.c @@ -15,22 +15,22 @@ struct exposable_private { }; static int -begin_expose(const struct exposable *exposable, cairo_t *cr) +begin_expose(struct exposable *exposable, cairo_t *cr) { const struct exposable_private *e = exposable->private; - int width = exposable->particle->left_margin; + exposable->width = exposable->particle->left_margin; for (size_t i = 0; i < e->count; i++) { struct exposable *ee = e->exposables[i]; e->widths[i] = ee->begin_expose(ee, cr); - width += e->left_spacing + e->widths[i] + e->right_spacing; + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; } - width -= e->left_spacing + e->right_spacing; - width += exposable->particle->right_margin; - return width; + exposable->width -= e->left_spacing + e->right_spacing; + exposable->width += exposable->particle->right_margin; + return exposable->width; } static void @@ -38,6 +38,10 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) { const struct exposable_private *e = exposable->private; + const struct deco *deco = exposable->particle->deco; + if (deco != NULL) + deco->expose(deco, cr, x, y, exposable->width, height); + int left_margin = exposable->particle->left_margin; int left_spacing = e->left_spacing; int right_spacing = e->right_spacing; diff --git a/particles/string.c b/particles/string.c index 2d1f581..26d1914 100644 --- a/particles/string.c +++ b/particles/string.c @@ -12,7 +12,7 @@ struct private { }; static int -begin_expose(const struct exposable *exposable, cairo_t *cr) +begin_expose(struct exposable *exposable, cairo_t *cr) { const struct private *e = exposable->private; @@ -20,9 +20,11 @@ begin_expose(const struct exposable *exposable, cairo_t *cr) cairo_text_extents_t extents; cairo_scaled_font_text_extents(scaled, e->text, &extents); - return (exposable->particle->left_margin + - extents.x_advance + - exposable->particle->right_margin); + exposable->width = (exposable->particle->left_margin + + extents.x_advance + + exposable->particle->right_margin); + + return exposable->width; } static void @@ -47,12 +49,8 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) &clusters, &num_clusters, &cluster_flags); const struct deco *deco = exposable->particle->deco; - if (deco != NULL) { - int width = (exposable->particle->left_margin + - extents.x_advance + - exposable->particle->right_margin); - deco->expose(deco, cr, x, y, width, height); - } + if (deco != NULL) + deco->expose(deco, cr, x, y, exposable->width, height); cairo_set_source_rgba(cr, e->foreground.red,