img: remove "theme" member from lab_img

lab_img.theme member was referenced by "modifier" functions when drawing a
hover effect on button buffers or rounding the button buffer for corner
buttons, but this can be prone to use-after-free and was not very clean
because theme and lab_img were referencing each other.

Instead, let's just reference rc.theme in the modifier functions and
remove theme from lab_img.
This commit is contained in:
tokyo4j 2025-01-03 23:57:40 +09:00 committed by Consolatis
parent 956b271f9b
commit 90a8c3e793
3 changed files with 15 additions and 20 deletions

View file

@ -16,7 +16,6 @@ enum lab_img_type {
};
struct lab_img {
struct theme *theme; /* Used by modifier functions */
struct wl_array modifiers; /* lab_img_modifier_func_t */
struct lab_img_cache *cache;
};
@ -33,8 +32,7 @@ struct lab_img *lab_img_load(enum lab_img_type type, const char *path,
*/
struct lab_img *lab_img_load_from_bitmap(const char *bitmap, float *rgba);
typedef void (*lab_img_modifier_func_t)(struct theme *theme, cairo_t *cairo,
int w, int h);
typedef void (*lab_img_modifier_func_t)(cairo_t *cairo, int w, int h);
/**
* lab_img_copy() - Copy lab_img
@ -55,8 +53,7 @@ struct lab_img *lab_img_copy(struct lab_img *img);
* after the image is rendered on a buffer with lab_img_render(). For example,
* hover effects for window buttons can be drawn over the rendered image.
*/
void lab_img_add_modifier(struct lab_img *img, lab_img_modifier_func_t modifier,
struct theme *theme);
void lab_img_add_modifier(struct lab_img *img, lab_img_modifier_func_t modifier);
/**
* lab_img_render() - Render lab_img to a buffer