aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Primak <vyivel@posteo.net>2021-08-11 13:35:20 +0300
committerSimon Ser <contact@emersion.fr>2021-08-11 18:12:57 +0200
commit111d4eafd795e603f652b426d2cb3dae1d8692dc (patch)
treeb022f3a94da8d7adc4a885755324c42ae5be6daf
parentdebd6c5f0b3dd864ae02cd3aa77123851c47d380 (diff)
util/addon: find both by owner and impl
This allows to have multiple addons of different types with the same owner.
-rw-r--r--include/wlr/util/addon.h4
-rw-r--r--types/wlr_output_layout.c2
-rw-r--r--util/addon.c18
3 files changed, 11 insertions, 13 deletions
diff --git a/include/wlr/util/addon.h b/include/wlr/util/addon.h
index 3ad71f54..382252ae 100644
--- a/include/wlr/util/addon.h
+++ b/include/wlr/util/addon.h
@@ -37,7 +37,7 @@ void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
const void *owner, const struct wlr_addon_interface *impl);
void wlr_addon_finish(struct wlr_addon *addon);
-struct wlr_addon *wlr_addon_find_by_owner(struct wlr_addon_set *set,
- const void *owner);
+struct wlr_addon *wlr_addon_find(struct wlr_addon_set *set, const void *owner,
+ const struct wlr_addon_interface *impl);
#endif
diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c
index 8a4e2d66..782f5b71 100644
--- a/types/wlr_output_layout.c
+++ b/types/wlr_output_layout.c
@@ -225,7 +225,7 @@ struct wlr_output_layout_output *wlr_output_layout_get(
struct wlr_output_layout *layout, struct wlr_output *reference) {
struct wlr_output_layout_output *l_output = NULL;
struct wlr_addon *addon =
- wlr_addon_find_by_owner(&reference->addons, layout);
+ wlr_addon_find(&reference->addons, layout, &addon_impl);
if (addon) {
l_output = wl_container_of(addon, l_output, addon);
}
diff --git a/util/addon.c b/util/addon.c
index 7de54a73..d9e13978 100644
--- a/util/addon.c
+++ b/util/addon.c
@@ -18,11 +18,11 @@ void wlr_addon_set_finish(struct wlr_addon_set *set) {
void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
const void *owner, const struct wlr_addon_interface *impl) {
- assert(owner);
+ assert(owner && impl);
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");
+ if (iter->owner == addon->owner && iter->impl == addon->impl) {
+ assert(0 && "Can't have two addons of the same type with the same owner");
}
}
wl_list_insert(&set->addons, &addon->link);
@@ -31,17 +31,15 @@ void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,
}
void wlr_addon_finish(struct wlr_addon *addon) {
- if (addon->owner) {
- addon->owner = NULL;
- wl_list_remove(&addon->link);
- }
+ wl_list_remove(&addon->link);
+ wl_list_init(&addon->link);
}
-struct wlr_addon *wlr_addon_find_by_owner(struct wlr_addon_set *set,
- const void *owner) {
+struct wlr_addon *wlr_addon_find(struct wlr_addon_set *set, const void *owner,
+ const struct wlr_addon_interface *impl) {
struct wlr_addon *addon;
wl_list_for_each(addon, &set->addons, link) {
- if (addon->owner == owner) {
+ if (addon->owner == owner && addon->impl == impl) {
return addon;
}
}