aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-09-12 08:28:28 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-09-12 08:28:28 +0100
commit2eaef802061836dd83bbf753174fcb8488b2d8cd (patch)
tree33fcd285cc70a6cea257b1f3b6d24121d340a270 /swaybar/render.c
parentMerge pull request #2620 from ianyfan/commands (diff)
downloadsway-2eaef802061836dd83bbf753174fcb8488b2d8cd.tar.gz
sway-2eaef802061836dd83bbf753174fcb8488b2d8cd.tar.zst
sway-2eaef802061836dd83bbf753174fcb8488b2d8cd.zip
i3bar: count references to blocks
This prevents blocks from being destroyed before their hotspots are destroyed, in case it is used for a pending click event that fires between the bar receiving a new status, which destroys the block, and the bar rendering the new status, which destroys the hotspot; this problem can be easily produced by scrolling on a block that immediately causes a new status to be sent, with multiple outputs
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index 7303e70f..2d848bfa 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -115,6 +115,10 @@ static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output
115 return i3bar_block_send_click(status, block, x, y, button); 115 return i3bar_block_send_click(status, block, x, y, button);
116} 116}
117 117
118static void i3bar_block_unref_callback(void *data) {
119 i3bar_block_unref(data);
120}
121
118static uint32_t render_status_block(cairo_t *cairo, 122static uint32_t render_status_block(cairo_t *cairo,
119 struct swaybar_config *config, struct swaybar_output *output, 123 struct swaybar_config *config, struct swaybar_output *output,
120 struct i3bar_block *block, double *x, 124 struct i3bar_block *block, double *x,
@@ -179,8 +183,9 @@ static uint32_t render_status_block(cairo_t *cairo,
179 hotspot->width = width; 183 hotspot->width = width;
180 hotspot->height = height; 184 hotspot->height = height;
181 hotspot->callback = block_hotspot_callback; 185 hotspot->callback = block_hotspot_callback;
182 hotspot->destroy = NULL; 186 hotspot->destroy = i3bar_block_unref_callback;
183 hotspot->data = block; 187 hotspot->data = block;
188 block->ref_count++;
184 wl_list_insert(&output->hotspots, &hotspot->link); 189 wl_list_insert(&output->hotspots, &hotspot->link);
185 190
186 double pos = *x; 191 double pos = *x;