diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 8659d8ecd..e6be4a20a 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -118,11 +118,27 @@ static void handle_subbackend_destroy(struct wl_listener *listener, subbackend_state_destroy(state); } +static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_backend *multi, + struct wlr_backend *backend) { + struct subbackend_state *sub = NULL; + wl_list_for_each(sub, &multi->backends, link) { + if (sub->backend == backend) { + return sub; + } + } + return NULL; +} + void wlr_multi_backend_add(struct wlr_backend *_multi, struct wlr_backend *backend) { assert(wlr_backend_is_multi(_multi)); - struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi; + + if (multi_backend_get_subbackend(multi, backend)) { + // already added + return; + } + struct subbackend_state *sub; if (!(sub = calloc(1, sizeof(struct subbackend_state)))) { wlr_log(L_ERROR, "Could not add backend: allocation failed"); @@ -149,6 +165,19 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, sub->output_remove.notify = output_remove_reemit; } +void wlr_multi_backend_remove(struct wlr_backend *_multi, + struct wlr_backend *backend) { + assert(wlr_backend_is_multi(_multi)); + struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi; + + struct subbackend_state *sub = + multi_backend_get_subbackend(multi, backend); + + if (sub) { + subbackend_state_destroy(sub); + } +} + struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { assert(wlr_backend_is_multi(_backend)); diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index fc53f3696..35f7c165c 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -9,6 +9,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); void wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); +void wlr_multi_backend_remove(struct wlr_backend *multi, + struct wlr_backend *backend); + bool wlr_backend_is_multi(struct wlr_backend *backend); struct wlr_session *wlr_multi_get_session(struct wlr_backend *base);