Changed ownership of wlr_session to the multi backend.

Currently breaks VT switching for examples.
master
Scott Anderson 7 years ago
parent 41b98f21e5
commit ae4478e17f

@ -62,8 +62,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
return backend; return backend;
} }
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
struct wlr_session *session) {
struct wlr_backend *backend; struct wlr_backend *backend;
if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) {
backend = attempt_wl_backend(display); backend = attempt_wl_backend(display);
@ -71,43 +70,61 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
return backend; return backend;
} }
} }
if (getenv("DISPLAY")) {
// TODO: X11 backend
return NULL;
}
// Attempt DRM+libinput // Attempt DRM+libinput
struct wlr_udev *udev;
if (!(udev = wlr_udev_create(display))) { struct wlr_session *session = wlr_session_start(display);
if (!session) {
wlr_log(L_ERROR, "Failed to start a DRM session");
return NULL;
}
struct wlr_udev *udev = wlr_udev_create(display);
if (!udev) {
wlr_log(L_ERROR, "Failed to start udev"); wlr_log(L_ERROR, "Failed to start udev");
goto error; goto error_session;
} }
int gpu = wlr_udev_find_gpu(udev, session); int gpu = wlr_udev_find_gpu(udev, session);
if (gpu == -1) { if (gpu == -1) {
wlr_log(L_ERROR, "Failed to open DRM device"); wlr_log(L_ERROR, "Failed to open DRM device");
goto error_udev; goto error_udev;
} }
backend = wlr_multi_backend_create();
backend = wlr_multi_backend_create(session, udev);
if (!backend) { if (!backend) {
goto error_gpu; goto error_gpu;
} }
struct wlr_backend *libinput =
wlr_libinput_backend_create(display, session, udev); struct wlr_backend *libinput = wlr_libinput_backend_create(display, session, udev);
if (!libinput) { if (!libinput) {
goto error_multi; goto error_multi;
} }
struct wlr_backend *drm =
wlr_drm_backend_create(display, session, udev, gpu); struct wlr_backend *drm = wlr_drm_backend_create(display, session, udev, gpu);
if (!drm) { if (!drm) {
goto error_libinput; goto error_libinput;
} }
wlr_multi_backend_add(backend, libinput); wlr_multi_backend_add(backend, libinput);
wlr_multi_backend_add(backend, drm); wlr_multi_backend_add(backend, drm);
return backend; return backend;
error_libinput: error_libinput:
wlr_backend_destroy(libinput); wlr_backend_destroy(libinput);
error_multi: error_multi:
wlr_backend_destroy(backend); wlr_backend_destroy(backend);
error_gpu: error_gpu:
close(gpu); wlr_session_close_file(session, gpu);
error_udev: error_udev:
wlr_udev_destroy(udev); wlr_udev_destroy(udev);
error: error_session:
wlr_session_finish(session);
return NULL; return NULL;
} }

@ -1,6 +1,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/udev.h>
#include <wlr/session.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "backend/multi.h" #include "backend/multi.h"
@ -31,6 +33,8 @@ static void multi_backend_destroy(struct wlr_backend_state *state) {
free(sub); free(sub);
} }
list_free(state->backends); list_free(state->backends);
wlr_session_finish(state->session);
wlr_udev_destroy(state->udev);
free(state); free(state);
} }
@ -39,21 +43,26 @@ struct wlr_backend_impl backend_impl = {
.destroy = multi_backend_destroy .destroy = multi_backend_destroy
}; };
struct wlr_backend *wlr_multi_backend_create() { struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session,
struct wlr_udev *udev) {
struct wlr_backend_state *state = struct wlr_backend_state *state =
calloc(1, sizeof(struct wlr_backend_state)); calloc(1, sizeof(struct wlr_backend_state));
if (!state) { if (!state) {
wlr_log(L_ERROR, "Backend allocation failed"); wlr_log(L_ERROR, "Backend allocation failed");
return NULL; return NULL;
} }
state->backends = list_create(); state->backends = list_create();
if (!state->backends) { if (!state->backends) {
free(state); free(state);
wlr_log(L_ERROR, "Backend allocation failed"); wlr_log(L_ERROR, "Backend allocation failed");
return NULL; return NULL;
} }
struct wlr_backend *backend = wlr_backend_create(&backend_impl, state); struct wlr_backend *backend = wlr_backend_create(&backend_impl, state);
state->backend = backend; state->backend = backend;
state->session = session;
state->udev = udev;
return backend; return backend;
} }

@ -440,12 +440,6 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
void compositor_init(struct compositor_state *state) { void compositor_init(struct compositor_state *state) {
state->display = wl_display_create(); state->display = wl_display_create();
state->event_loop = wl_display_get_event_loop(state->display); state->event_loop = wl_display_get_event_loop(state->display);
state->session = wlr_session_start(state->display);
if (!state->session
|| !state->display
|| !state->event_loop) {
exit(1);
}
wl_list_init(&state->keyboards); wl_list_init(&state->keyboards);
wl_list_init(&state->pointers); wl_list_init(&state->pointers);
@ -463,10 +457,8 @@ void compositor_init(struct compositor_state *state) {
wl_list_init(&state->output_remove.link); wl_list_init(&state->output_remove.link);
state->output_remove.notify = output_remove_notify; state->output_remove.notify = output_remove_notify;
struct wlr_backend *wlr = wlr_backend_autocreate( struct wlr_backend *wlr = wlr_backend_autocreate(state->display);
state->display, state->session);
if (!wlr) { if (!wlr) {
wlr_session_finish(state->session);
exit(1); exit(1);
} }
wl_signal_add(&wlr->events.input_add, &state->input_add); wl_signal_add(&wlr->events.input_add, &state->input_add);
@ -481,7 +473,6 @@ void compositor_init(struct compositor_state *state) {
if (!socket) { if (!socket) {
wlr_log_errno(L_ERROR, "Unable to open wayland socket"); wlr_log_errno(L_ERROR, "Unable to open wayland socket");
wlr_backend_destroy(wlr); wlr_backend_destroy(wlr);
wlr_session_finish(state->session);
exit(1); exit(1);
} }
@ -490,7 +481,6 @@ void compositor_init(struct compositor_state *state) {
if (!wlr_backend_init(state->backend)) { if (!wlr_backend_init(state->backend)) {
wlr_log(L_ERROR, "Failed to initialize backend"); wlr_log(L_ERROR, "Failed to initialize backend");
wlr_backend_destroy(wlr); wlr_backend_destroy(wlr);
wlr_session_finish(state->session);
exit(1); exit(1);
} }
} }
@ -498,6 +488,5 @@ void compositor_init(struct compositor_state *state) {
void compositor_run(struct compositor_state *state) { void compositor_run(struct compositor_state *state) {
wl_display_run(state->display); wl_display_run(state->display);
wlr_backend_destroy(state->backend); wlr_backend_destroy(state->backend);
wlr_session_finish(state->session);
wl_display_destroy(state->display); wl_display_destroy(state->display);
} }

@ -3,10 +3,14 @@
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/multi.h> #include <wlr/backend/multi.h>
#include <wlr/backend/udev.h>
#include <wlr/util/list.h> #include <wlr/util/list.h>
#include <wlr/session.h>
struct wlr_backend_state { struct wlr_backend_state {
struct wlr_backend *backend; struct wlr_backend *backend;
struct wlr_session *session;
struct wlr_udev *udev;
list_t *backends; list_t *backends;
}; };

@ -19,8 +19,7 @@ struct wlr_backend {
} events; } events;
}; };
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, struct wlr_backend *wlr_backend_autocreate(struct wl_display *display);
struct wlr_session *session);
bool wlr_backend_init(struct wlr_backend *backend); bool wlr_backend_init(struct wlr_backend *backend);
void wlr_backend_destroy(struct wlr_backend *backend); void wlr_backend_destroy(struct wlr_backend *backend);

@ -2,8 +2,11 @@
#define _WLR_BACKEND_MULTI_H #define _WLR_BACKEND_MULTI_H
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/backend/udev.h>
#include <wlr/session.h>
struct wlr_backend *wlr_multi_backend_create(); struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session,
struct wlr_udev *udev);
void wlr_multi_backend_add(struct wlr_backend *multi, void wlr_multi_backend_add(struct wlr_backend *multi,
struct wlr_backend *backend); struct wlr_backend *backend);

@ -30,6 +30,10 @@ struct wlr_session *wlr_session_start(struct wl_display *disp) {
} }
void wlr_session_finish(struct wlr_session *session) { void wlr_session_finish(struct wlr_session *session) {
if (!session) {
return;
}
session->impl->finish(session); session->impl->finish(session);
}; };
@ -42,5 +46,9 @@ void wlr_session_close_file(struct wlr_session *session, int fd) {
} }
bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) { bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) {
if (!session) {
return false;
}
return session->impl->change_vt(session, vt); return session->impl->change_vt(session, vt);
} }

Loading…
Cancel
Save