aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-05-15 00:07:41 +0100
committeremersion <contact@emersion.fr>2018-05-19 09:08:59 +0100
commita1631dd9ee148ac2adfe664be44b0e463e29950a (patch)
treecc1108b65f2ca8e72cebf9ef7052fcd218040a43 /backend
parent98088e78df054553ec846043ee913d0dcf39de16 (diff)
backend: add WLR_BACKEND env variable
Diffstat (limited to 'backend')
-rw-r--r--backend/backend.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/backend/backend.c b/backend/backend.c
index 20bf42b3..0ea42cf5 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <wayland-server.h>
#include <wlr/backend/drm.h>
+#include <wlr/backend/headless.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/libinput.h>
#include <wlr/backend/multi.h>
@@ -101,6 +102,35 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
}
#endif
+static struct wlr_backend *attempt_headless_backend(
+ struct wl_display *display) {
+ struct wlr_backend *backend = wlr_headless_backend_create(display);
+ if (backend == NULL) {
+ return NULL;
+ }
+
+ size_t outputs = parse_outputs_env("WLR_HEADLESS_OUTPUTS");
+ for (size_t i = 0; i < outputs; ++i) {
+ wlr_headless_add_output(backend, 1280, 720);
+ }
+
+ return backend;
+}
+
+static struct wlr_backend *attempt_backend_by_name(struct wl_display *display,
+ const char *name) {
+ if (strcmp(name, "wayland") == 0) {
+ return attempt_wl_backend(display);
+#ifdef WLR_HAS_X11_BACKEND
+ } else if (strcmp(name, "x11") == 0) {
+ return attempt_x11_backend(display, NULL);
+#endif
+ } else if (strcmp(name, "headless") == 0) {
+ return attempt_headless_backend(display);
+ }
+ return NULL;
+}
+
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
struct wlr_backend *backend = wlr_multi_backend_create(display);
if (!backend) {
@@ -108,6 +138,18 @@ 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);
+ return NULL;
+ }
+ }
+
if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") ||
getenv("WAYLAND_SOCKET")) {
struct wlr_backend *wl_backend = attempt_wl_backend(display);