multibackend remove subbackend

This commit is contained in:
Tony Crisci 2017-12-19 18:49:00 -05:00
parent 6c75a184e7
commit 58e69c9ce1
2 changed files with 33 additions and 1 deletions

View File

@ -118,11 +118,27 @@ static void handle_subbackend_destroy(struct wl_listener *listener,
subbackend_state_destroy(state); 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, void wlr_multi_backend_add(struct wlr_backend *_multi,
struct wlr_backend *backend) { struct wlr_backend *backend) {
assert(wlr_backend_is_multi(_multi)); assert(wlr_backend_is_multi(_multi));
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_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; struct subbackend_state *sub;
if (!(sub = calloc(1, sizeof(struct subbackend_state)))) { if (!(sub = calloc(1, sizeof(struct subbackend_state)))) {
wlr_log(L_ERROR, "Could not add backend: allocation failed"); 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; 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) { struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) {
assert(wlr_backend_is_multi(_backend)); assert(wlr_backend_is_multi(_backend));

View File

@ -9,6 +9,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display);
void wlr_multi_backend_add(struct wlr_backend *multi, void wlr_multi_backend_add(struct wlr_backend *multi,
struct wlr_backend *backend); 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); bool wlr_backend_is_multi(struct wlr_backend *backend);
struct wlr_session *wlr_multi_get_session(struct wlr_backend *base); struct wlr_session *wlr_multi_get_session(struct wlr_backend *base);