From a6a80850b729eefaafac325256023ee92b21be34 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 9 Aug 2021 17:57:19 +0300 Subject: util: add wlr_addon --- util/addon.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 2 files changed, 50 insertions(+) create mode 100644 util/addon.c (limited to 'util') diff --git a/util/addon.c b/util/addon.c new file mode 100644 index 00000000..7de54a73 --- /dev/null +++ b/util/addon.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#include "wlr/util/addon.h" + +void wlr_addon_set_init(struct wlr_addon_set *set) { + wl_list_init(&set->addons); +} + +void wlr_addon_set_finish(struct wlr_addon_set *set) { + struct wlr_addon *addon, *tmp; + wl_list_for_each_safe(addon, tmp, &set->addons, link) { + wlr_addon_finish(addon); + addon->impl->destroy(addon); + } +} + +void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set, + const void *owner, const struct wlr_addon_interface *impl) { + assert(owner); + struct wlr_addon *iter; + wl_list_for_each(iter, &set->addons, link) { + if (iter->owner == addon->owner) { + assert(0 && "Can't have two addons with the same owner"); + } + } + wl_list_insert(&set->addons, &addon->link); + addon->owner = owner; + addon->impl = impl; +} + +void wlr_addon_finish(struct wlr_addon *addon) { + if (addon->owner) { + addon->owner = NULL; + wl_list_remove(&addon->link); + } +} + +struct wlr_addon *wlr_addon_find_by_owner(struct wlr_addon_set *set, + const void *owner) { + struct wlr_addon *addon; + wl_list_for_each(addon, &set->addons, link) { + if (addon->owner == owner) { + return addon; + } + } + return NULL; +} diff --git a/util/meson.build b/util/meson.build index c2b46749..a416490f 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,4 +1,5 @@ wlr_files += files( + 'addon.c', 'array.c', 'box.c', 'global.c', -- cgit v1.2.3