From 007d83c6ee20ec4d39aa2d7a4ff3fb3158bc5fb3 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 15 May 2018 22:10:51 +0100 Subject: [PATCH] backend: allow multiple backends in WLR_BACKENDS --- backend/backend.c | 33 +++++++++++++++++++++++++-------- docs/env_vars.md | 16 +++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 0ea42cf5..a66cb5f3 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -1,3 +1,4 @@ +#define _POSIX_C_SOURCE 200809L #include #include #include @@ -138,16 +139,32 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } - const char *name = getenv("WLR_BACKEND"); - if (name) { - struct wlr_backend *subbackend = attempt_backend_by_name(display, name); - if (subbackend) { - wlr_multi_backend_add(backend, subbackend); - return backend; - } else { - wlr_log(L_ERROR, "unrecognized backend '%s'", name); + char *names = getenv("WLR_BACKENDS"); + if (names) { + names = strdup(names); + if (names == NULL) { + wlr_log(L_ERROR, "allocation failed"); return NULL; } + + char *saveptr; + char *name = strtok_r(names, ",", &saveptr); + while (name != NULL) { + struct wlr_backend *subbackend = + attempt_backend_by_name(display, name); + if (subbackend == NULL) { + wlr_log(L_ERROR, "unrecognized backend '%s'", name); + return NULL; + } + + if (!wlr_multi_backend_add(backend, subbackend)) { + return NULL; + } + + name = strtok_r(NULL, ",", &saveptr); + } + + return backend; } if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") || diff --git a/docs/env_vars.md b/docs/env_vars.md index db85d4c5..3f1926d3 100644 --- a/docs/env_vars.md +++ b/docs/env_vars.md @@ -2,20 +2,26 @@ wlroots reads these environment variables wlroots specific ---------------- -* *WLR_DRM_DEVICES*: specifies the DRM devices (as a colon separated list) instead of auto probing them. The first existing device in this list is considered the primary DRM device. -* *WLR_DRM_NO_ATOMIC*: set to 1 to use legacy DRM interface instead of atomic mode setting +* *WLR_DRM_DEVICES*: specifies the DRM devices (as a colon separated list) + instead of auto probing them. The first existing device in this list is + considered the primary DRM device. +* *WLR_DRM_NO_ATOMIC*: set to 1 to use legacy DRM interface instead of atomic + mode setting * *WLR_LIBINPUT_NO_DEVICES*: set to 1 to not fail without any input devices -* *WLR_BACKEND*: force a specific backend to be used (one of: wayland, x11, headless) +* *WLR_BACKENDS*: comma-separated list of backends to use (available backends: + wayland, x11, headless) * *WLR_WL_OUTPUTS*: when using the wayland backend specifies the number of outputs * *WLR_X11_OUTPUTS*: when using the X11 backend specifies the number of outputs rootston specific ------------------ -* *XKB_DEFAULT_RULES*, *XKB_DEFAULT_MODEL*, *XKB_DEFAULT_LAYOUT*, *XKB_DEFAULT_VARIANT*, *XKB_DEFAULT_OPTIONS*: xkb setup +* *XKB_DEFAULT_RULES*, *XKB_DEFAULT_MODEL*, *XKB_DEFAULT_LAYOUT*, + *XKB_DEFAULT_VARIANT*, *XKB_DEFAULT_OPTIONS*: xkb setup generic ------- * *DISPLAY*: if set probe X11 backend in *wlr_backend_autocreate* -* *WAYLAND_DISPLAY*, *_WAYLAND_DISPLAY*, *WAYLAND_SOCKET*: if set probe Wayland backend in *wlr_backend_autocreate* +* *WAYLAND_DISPLAY*, *_WAYLAND_DISPLAY*, *WAYLAND_SOCKET*: if set probe Wayland + backend in *wlr_backend_autocreate* * *XCURSOR_PATH*: directory where xcursors are located * *XDG_RUNTIME_DIR*: used to store non persistent temporary files