diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-10-04 17:36:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 17:36:39 +0200 |
commit | 841d04db994b0a05d7688a0ecaa9b2e29131f026 (patch) | |
tree | 71d1e442666f05fd0312acd672383c6440c63ff0 /backend/backend.c | |
parent | 0d23fb7b6dc79b82301f3c049e05d1556a187b0f (diff) | |
parent | b4d46aa9c255ccb6f121b3657f6910c29e02d704 (diff) |
Merge pull request #1262 from nyorain/session_fix
Improve session handling
Diffstat (limited to 'backend/backend.c')
-rw-r--r-- | backend/backend.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/backend/backend.c b/backend/backend.c index 78b90007..2d6464b7 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -15,6 +15,7 @@ #include <wlr/backend/wayland.h> #include <wlr/config.h> #include <wlr/util/log.h> +#include "backend/multi.h" /* WLR_HAS_X11_BACKEND needs to be after wlr/config.h */ #ifdef WLR_HAS_X11_BACKEND @@ -56,6 +57,13 @@ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) { return NULL; } +struct wlr_session *wlr_backend_get_session(struct wlr_backend *backend) { + if (backend->impl->get_session) { + return backend->impl->get_session(backend); + } + return NULL; +} + static size_t parse_outputs_env(const char *name) { const char *outputs_str = getenv(name); if (outputs_str == NULL) { @@ -158,10 +166,12 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, return attempt_headless_backend(display, create_renderer_func); } else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) { // DRM and libinput need a session - *session = wlr_session_create(display); if (!*session) { - wlr_log(WLR_ERROR, "failed to start a session"); - return NULL; + *session = wlr_session_create(display); + if (!*session) { + wlr_log(WLR_ERROR, "failed to start a session"); + return NULL; + } } if (strcmp(name, "libinput") == 0) { @@ -178,13 +188,12 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, wlr_renderer_create_func_t create_renderer_func) { struct wlr_backend *backend = wlr_multi_backend_create(display); + struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend; if (!backend) { wlr_log(WLR_ERROR, "could not allocate multibackend"); return NULL; } - struct wlr_session *session = NULL; - char *names = getenv("WLR_BACKENDS"); if (names) { names = strdup(names); @@ -197,12 +206,12 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, char *saveptr; char *name = strtok_r(names, ",", &saveptr); while (name != NULL) { - struct wlr_backend *subbackend = - attempt_backend_by_name(display, backend, &session, name, create_renderer_func); + struct wlr_backend *subbackend = attempt_backend_by_name(display, + backend, &multi->session, name, create_renderer_func); if (subbackend == NULL) { wlr_log(WLR_ERROR, "failed to start backend '%s'", name); wlr_backend_destroy(backend); - wlr_session_destroy(session); + wlr_session_destroy(multi->session); free(names); return NULL; } @@ -210,7 +219,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, if (!wlr_multi_backend_add(backend, subbackend)) { wlr_log(WLR_ERROR, "failed to add backend '%s'", name); wlr_backend_destroy(backend); - wlr_session_destroy(session); + wlr_session_destroy(multi->session); free(names); return NULL; } @@ -245,29 +254,30 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, #endif // Attempt DRM+libinput - session = wlr_session_create(display); - if (!session) { + multi->session = wlr_session_create(display); + if (!multi->session) { wlr_log(WLR_ERROR, "Failed to start a DRM session"); wlr_backend_destroy(backend); return NULL; } - struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); + struct wlr_backend *libinput = wlr_libinput_backend_create(display, + multi->session); if (!libinput) { wlr_log(WLR_ERROR, "Failed to start libinput backend"); wlr_backend_destroy(backend); - wlr_session_destroy(session); + wlr_session_destroy(multi->session); return NULL; } wlr_multi_backend_add(backend, libinput); - struct wlr_backend *primary_drm = - attempt_drm_backend(display, backend, session, create_renderer_func); + struct wlr_backend *primary_drm = attempt_drm_backend(display, backend, + multi->session, create_renderer_func); if (!primary_drm) { wlr_log(WLR_ERROR, "Failed to open any DRM device"); wlr_backend_destroy(libinput); wlr_backend_destroy(backend); - wlr_session_destroy(session); + wlr_session_destroy(multi->session); return NULL; } |