aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-11-23 14:53:06 +0100
committerKirill Primak <vyivel@eclair.cafe>2024-01-25 14:58:00 +0300
commit4ad6e6c2983216e91cec9987191c1099e8a108a8 (patch)
tree72ddb3b55ed6ba12a6d039e04792e0fbada34364 /backend
parentbe0b7845f74fd2f68e2b20802e39b81aa64cbd3e (diff)
backend: destroy multi backend when primary backend is
This makes it easy for compositors to handle situations where the DRM or libinput backend becomes unavailable. Compositors can listen the destroy event of the multi backend returned by wlr_backend_autocreate() and decide what to do.
Diffstat (limited to 'backend')
-rw-r--r--backend/backend.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/backend/backend.c b/backend/backend.c
index dcc68b3f..05a40c04 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -146,6 +146,53 @@ static size_t parse_outputs_env(const char *name) {
return outputs;
}
+/**
+ * Helper to destroy the multi backend when one of its nested backends is
+ * destroyed.
+ */
+struct wlr_auto_backend_monitor {
+ struct wlr_backend *multi;
+ struct wlr_backend *primary;
+
+ struct wl_listener multi_destroy;
+ struct wl_listener primary_destroy;
+};
+
+static void auto_backend_monitor_destroy(struct wlr_auto_backend_monitor *monitor) {
+ wl_list_remove(&monitor->multi_destroy.link);
+ wl_list_remove(&monitor->primary_destroy.link);
+ free(monitor);
+}
+
+static void monitor_handle_multi_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_auto_backend_monitor *monitor = wl_container_of(listener, monitor, multi_destroy);
+ auto_backend_monitor_destroy(monitor);
+}
+
+static void monitor_handle_primary_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_auto_backend_monitor *monitor = wl_container_of(listener, monitor, primary_destroy);
+ wlr_backend_destroy(monitor->multi);
+}
+
+static struct wlr_auto_backend_monitor *auto_backend_monitor_create(
+ struct wlr_backend *multi, struct wlr_backend *primary) {
+ struct wlr_auto_backend_monitor *monitor = calloc(1, sizeof(*monitor));
+ if (monitor == NULL) {
+ return NULL;
+ }
+
+ monitor->multi = multi;
+ monitor->primary = primary;
+
+ monitor->multi_destroy.notify = monitor_handle_multi_destroy;
+ wl_signal_add(&multi->events.destroy, &monitor->multi_destroy);
+
+ monitor->primary_destroy.notify = monitor_handle_primary_destroy;
+ wl_signal_add(&primary->events.destroy, &monitor->primary_destroy);
+
+ return monitor;
+}
+
static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
struct wlr_backend *backend = wlr_wl_backend_create(display, NULL);
if (backend == NULL) {
@@ -335,8 +382,12 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
if (!wl_backend) {
goto error;
}
-
wlr_multi_backend_add(multi, wl_backend);
+
+ if (!auto_backend_monitor_create(multi, wl_backend)) {
+ goto error;
+ }
+
goto success;
}
@@ -347,8 +398,12 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
if (!x11_backend) {
goto error;
}
-
wlr_multi_backend_add(multi, x11_backend);
+
+ if (!auto_backend_monitor_create(multi, x11_backend)) {
+ goto error;
+ }
+
goto success;
}
@@ -362,6 +417,9 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
struct wlr_backend *libinput = attempt_libinput_backend(display, session);
if (libinput) {
wlr_multi_backend_add(multi, libinput);
+ if (!auto_backend_monitor_create(multi, libinput)) {
+ goto error;
+ }
} else if (env_parse_bool("WLR_LIBINPUT_NO_DEVICES")) {
wlr_log(WLR_INFO, "WLR_LIBINPUT_NO_DEVICES is set, "
"starting without libinput backend");
@@ -377,6 +435,10 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
goto error;
}
+ if (!auto_backend_monitor_create(multi, primary_drm)) {
+ goto error;
+ }
+
success:
if (session_ptr != NULL) {
*session_ptr = session;