diff --git a/src/c2.c b/src/c2.c index d0ef507f..287a66cf 100644 --- a/src/c2.c +++ b/src/c2.c @@ -1675,3 +1675,18 @@ bool c2_match(session_t *ps, const struct managed_win *w, const c2_lptr_t *condl return false; } + +/// Iterate over all conditions in a condition linked list. Call the callback for each of +/// the conditions. If the callback returns true, the iteration stops early. +void c2_list_foreach(const c2_lptr_t *condlist, c2_list_foreach_cb_t cb, void *data) { + for (auto i = condlist; i; condlist = condlist->next) { + if (cb(i, data)) { + break; + } + } +} + +/// Return user data stored in a condition. +void *c2_list_get_data(const c2_lptr_t *condlist) { + return condlist->data; +} diff --git a/src/c2.h b/src/c2.h index d6b1d372..7a9c3545 100644 --- a/src/c2.h +++ b/src/c2.h @@ -12,6 +12,7 @@ #pragma once #include +#include typedef struct _c2_lptr c2_lptr_t; typedef struct session session_t; @@ -21,6 +22,20 @@ c2_lptr_t *c2_parse(c2_lptr_t **pcondlst, const char *pattern, void *data); c2_lptr_t *c2_free_lptr(c2_lptr_t *lp); -bool c2_match(session_t *ps, const struct managed_win *w, const c2_lptr_t *condlst, void **pdata); +bool c2_match(session_t *ps, const struct managed_win *w, const c2_lptr_t *condlst, + void **pdata); bool c2_list_postprocess(session_t *ps, c2_lptr_t *list); +typedef bool (*c2_list_foreach_cb_t)(const c2_lptr_t *cond, void *data); +void c2_list_foreach(const c2_lptr_t *list, c2_list_foreach_cb_t cb, void *data); +/// Return user data stored in a condition. +void *c2_list_get_data(const c2_lptr_t *condlist); + +/** + * Destroy a condition list. + */ +static inline void c2_list_free(c2_lptr_t **pcondlst) { + while ((*pcondlst = c2_free_lptr(*pcondlst))) { + } + *pcondlst = NULL; +} diff --git a/src/picom.c b/src/picom.c index 81fb334d..7f03286a 100644 --- a/src/picom.c +++ b/src/picom.c @@ -2164,16 +2164,16 @@ static void session_destroy(session_t *ps) { list_init_head(&ps->window_stack); // Free blacklists - free_wincondlst(&ps->o.shadow_blacklist); - free_wincondlst(&ps->o.shadow_clip_list); - free_wincondlst(&ps->o.fade_blacklist); - free_wincondlst(&ps->o.focus_blacklist); - free_wincondlst(&ps->o.invert_color_list); - free_wincondlst(&ps->o.blur_background_blacklist); - free_wincondlst(&ps->o.opacity_rules); - free_wincondlst(&ps->o.paint_blacklist); - free_wincondlst(&ps->o.unredir_if_possible_blacklist); - free_wincondlst(&ps->o.rounded_corners_blacklist); + c2_list_free(&ps->o.shadow_blacklist); + c2_list_free(&ps->o.shadow_clip_list); + c2_list_free(&ps->o.fade_blacklist); + c2_list_free(&ps->o.focus_blacklist); + c2_list_free(&ps->o.invert_color_list); + c2_list_free(&ps->o.blur_background_blacklist); + c2_list_free(&ps->o.opacity_rules); + c2_list_free(&ps->o.paint_blacklist); + c2_list_free(&ps->o.unredir_if_possible_blacklist); + c2_list_free(&ps->o.rounded_corners_blacklist); // Free tracked atom list { diff --git a/src/picom.h b/src/picom.h index 0ba04dda..7ee289bd 100644 --- a/src/picom.h +++ b/src/picom.h @@ -84,14 +84,6 @@ static inline bool array_wid_exists(const xcb_window_t *arr, int count, xcb_wind return false; } -/** - * Destroy a condition list. - */ -static inline void free_wincondlst(c2_lptr_t **pcondlst) { - while ((*pcondlst = c2_free_lptr(*pcondlst))) - continue; -} - #ifndef CONFIG_OPENGL static inline void free_paint_glx(session_t *ps attr_unused, paint_t *p attr_unused) { }