mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-12-16 08:56:26 -05:00
Rework session handling
Sessions can now be retrieved from a backend in a more general manner. Multi-backend gets back its `session` field that contains the session if one was created, removing the interfacing from multi backend with the drm backend directly. This adds the possibility to use sessions even without the drm backend. It additionally fixes the bug that 2 session objects got created when WLR_BACKENDS were set to "libinput,drm". To allow vt switching without drm backend (and drm fd) on logind, start listening to PropertiesChanged signals from dbus and parse the session "Active" property when no master fd was created (this does not change current drm backend behaviour in any way).
This commit is contained in:
parent
5b687b4a96
commit
7b52388424
9 changed files with 189 additions and 43 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue