diff --git a/src/background.c b/src/background.c index 8cc75370..ff6667c2 100644 --- a/src/background.c +++ b/src/background.c @@ -99,8 +99,13 @@ void background_draw(struct background* background, CGContextRef context) { draw_rect(context, background->bounds, &background->color, background->corner_radius, background->border_width, &background->border_color, false); } +void background_clear_pointers(struct background* background) { + image_clear_pointers(&background->image); +} + void background_destroy(struct background* background) { image_destroy(&background->image); + background_clear_pointers(background); } static bool background_parse_sub_domain(struct background* background, FILE* rsp, struct token property, char* message) { diff --git a/src/background.h b/src/background.h index c00233ad..8d3d1193 100644 --- a/src/background.h +++ b/src/background.h @@ -29,6 +29,9 @@ bool background_set_padding_right(struct background* background, uint32_t pad); void background_calculate_bounds(struct background* background, uint32_t x, uint32_t y); void background_draw(struct background* background, CGContextRef context); +void background_clear_pointers(struct background* background); +void background_destroy(struct background* background); + static bool background_parse_sub_domain(struct background* background, FILE* rsp, struct token property, char* message); #endif // !BACKGROUND_H diff --git a/src/bar_item.c b/src/bar_item.c index 2c155b76..cf50274d 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -27,6 +27,7 @@ void bar_item_clear_pointers(struct bar_item* bar_item) { bar_item->signal_args.env_vars.count = 0; text_clear_pointers(&bar_item->icon); text_clear_pointers(&bar_item->label); + background_clear_pointers(&bar_item->background); } void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ancestor) { @@ -52,6 +53,10 @@ void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ance bar_item_set_script(bar_item, string_copy(ancestor->script)); bar_item_set_click_script(bar_item, string_copy(ancestor->click_script)); + image_copy(&bar_item->background.image, ancestor->background.image.image_ref); + image_copy(&bar_item->icon.background.image, ancestor->icon.background.image.image_ref); + image_copy(&bar_item->label.background.image, ancestor->label.background.image.image_ref); + if (bar_item->type == BAR_COMPONENT_SPACE) { env_vars_set(&bar_item->signal_args.env_vars, string_copy("SELECTED"), string_copy("false")); env_vars_set(&bar_item->signal_args.env_vars, string_copy("SID"), string_copy(env_vars_get_value_for_key(&ancestor->signal_args.env_vars, "DID"))); diff --git a/src/image.c b/src/image.c index ca4b804e..1acf2236 100644 --- a/src/image.c +++ b/src/image.c @@ -63,6 +63,10 @@ bool image_data_equals(struct image* image, CFDataRef new_data_ref) { return equals; } +void image_copy(struct image* image, CGImageRef source) { + if (source) image->image_ref = CGImageCreateCopy(source); +} + bool image_set_image(struct image* image, CGImageRef new_image_ref, CGRect bounds, bool forced) { CFDataRef new_data_ref = CGDataProviderCopyData(CGImageGetDataProvider(new_image_ref)); @@ -100,9 +104,15 @@ void image_draw(struct image* image, CGContextRef context) { CGContextDrawImage(context, image->bounds, image->image_ref); } +void image_clear_pointers(struct image* image) { + image->image_ref = NULL; + image->data_ref = NULL; +} + void image_destroy(struct image* image) { CGImageRelease(image->image_ref); if (image->data_ref) CFRelease(image->data_ref); + image_clear_pointers(image); } static bool image_parse_sub_domain(struct image* image, FILE* rsp, struct token property, char* message) { diff --git a/src/image.h b/src/image.h index a2aa48ad..99dc68ef 100644 --- a/src/image.h +++ b/src/image.h @@ -15,10 +15,13 @@ struct image { void image_init(struct image* image); bool image_set_enabled(struct image* image, bool enabled); bool image_data_equals(struct image* image, CFDataRef new_data_ref); +void image_copy(struct image* image, CGImageRef source); bool image_set_image(struct image* image, CGImageRef new_image_ref, CGRect bounds, bool forced); bool image_load(struct image* image, char* path, FILE* rsp); void image_calculate_bounds(struct image* image, uint32_t x, uint32_t y); void image_draw(struct image* image, CGContextRef context); + +void image_clear_pointers(struct image* image); void image_destroy(struct image* image); #endif diff --git a/src/text.c b/src/text.c index 1f215dce..cc74c830 100644 --- a/src/text.c +++ b/src/text.c @@ -112,6 +112,7 @@ void text_clear_pointers(struct text* text) { text->font_name = NULL; text->font = NULL; text->line.line = NULL; + background_clear_pointers(&text->background); } uint32_t text_get_length(struct text* text, bool override) {