aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/drm/backend.c19
-rw-r--r--backend/drm/renderer.c4
-rw-r--r--backend/libinput/backend.c25
-rw-r--r--backend/multi/backend.c1
-rw-r--r--backend/session/session.c13
-rw-r--r--backend/wayland/backend.c16
-rw-r--r--backend/x11/backend.c139
7 files changed, 141 insertions, 76 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 87a4f708..6be5e5d5 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -34,6 +34,10 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_output_destroy(&conn->output);
}
+ wl_list_remove(&drm->display_destroy.link);
+ wl_list_remove(&drm->session_signal.link);
+ wl_list_remove(&drm->drm_invalidated.link);
+
wlr_drm_resources_free(drm);
wlr_drm_renderer_finish(&drm->renderer);
wlr_session_close_file(drm->session, drm->fd);
@@ -57,7 +61,8 @@ bool wlr_backend_is_drm(struct wlr_backend *b) {
}
static void session_signal(struct wl_listener *listener, void *data) {
- struct wlr_drm_backend *drm = wl_container_of(listener, drm, session_signal);
+ struct wlr_drm_backend *drm =
+ wl_container_of(listener, drm, session_signal);
struct wlr_session *session = data;
if (session->active) {
@@ -84,7 +89,8 @@ static void session_signal(struct wl_listener *listener, void *data) {
}
static void drm_invalidated(struct wl_listener *listener, void *data) {
- struct wlr_drm_backend *drm = wl_container_of(listener, drm, drm_invalidated);
+ struct wlr_drm_backend *drm =
+ wl_container_of(listener, drm, drm_invalidated);
char *name = drmGetDeviceNameFromFd2(drm->fd);
wlr_log(L_DEBUG, "%s invalidated", name);
@@ -93,6 +99,12 @@ static void drm_invalidated(struct wl_listener *listener, void *data) {
wlr_drm_scan_connectors(drm);
}
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_drm_backend *drm =
+ wl_container_of(listener, drm, display_destroy);
+ wlr_drm_backend_destroy(&drm->backend);
+}
+
struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
struct wlr_session *session, int gpu_fd, struct wlr_backend *parent) {
assert(display && session && gpu_fd >= 0);
@@ -150,6 +162,9 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
wlr_log(L_INFO, "Failed to bind egl/wl display: %s", egl_error());
}
+ drm->display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(display, &drm->display_destroy);
+
return &drm->backend;
error_event:
diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c
index 87064914..8a8d7d1f 100644
--- a/backend/drm/renderer.c
+++ b/backend/drm/renderer.c
@@ -39,7 +39,7 @@ bool wlr_drm_renderer_init(struct wlr_drm_backend *drm,
return true;
error_egl:
- wlr_egl_free(&renderer->egl);
+ wlr_egl_finish(&renderer->egl);
error_gbm:
gbm_device_destroy(renderer->gbm);
return false;
@@ -51,7 +51,7 @@ void wlr_drm_renderer_finish(struct wlr_drm_renderer *renderer) {
}
wlr_renderer_destroy(renderer->wlr_rend);
- wlr_egl_free(&renderer->egl);
+ wlr_egl_finish(&renderer->egl);
gbm_device_destroy(renderer->gbm);
}
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c
index 1028e238..c9352051 100644
--- a/backend/libinput/backend.c
+++ b/backend/libinput/backend.c
@@ -43,10 +43,12 @@ static void wlr_libinput_log(struct libinput *libinput_context,
}
static bool wlr_libinput_backend_start(struct wlr_backend *_backend) {
- struct wlr_libinput_backend *backend = (struct wlr_libinput_backend *)_backend;
+ struct wlr_libinput_backend *backend =
+ (struct wlr_libinput_backend *)_backend;
wlr_log(L_DEBUG, "Initializing libinput");
- backend->libinput_context = libinput_udev_create_context(&libinput_impl, backend,
- backend->session->udev);
+
+ backend->libinput_context = libinput_udev_create_context(&libinput_impl,
+ backend, backend->session->udev);
if (!backend->libinput_context) {
wlr_log(L_ERROR, "Failed to create libinput context");
return false;
@@ -99,6 +101,7 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) {
}
struct wlr_libinput_backend *backend =
(struct wlr_libinput_backend *)_backend;
+
for (size_t i = 0; i < backend->wlr_device_lists.length; i++) {
struct wl_list *wlr_devices = backend->wlr_device_lists.items[i];
struct wlr_input_device *wlr_dev, *next;
@@ -108,6 +111,10 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) {
}
free(wlr_devices);
}
+
+ wl_list_remove(&backend->display_destroy.link);
+ wl_list_remove(&backend->session_signal.link);
+
wlr_list_finish(&backend->wlr_device_lists);
wl_event_source_remove(backend->input_event);
libinput_unref(backend->libinput_context);
@@ -124,7 +131,8 @@ bool wlr_backend_is_libinput(struct wlr_backend *b) {
}
static void session_signal(struct wl_listener *listener, void *data) {
- struct wlr_libinput_backend *backend = wl_container_of(listener, backend, session_signal);
+ struct wlr_libinput_backend *backend =
+ wl_container_of(listener, backend, session_signal);
struct wlr_session *session = data;
if (!backend->libinput_context) {
@@ -138,6 +146,12 @@ static void session_signal(struct wl_listener *listener, void *data) {
}
}
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_libinput_backend *backend =
+ wl_container_of(listener, backend, display_destroy);
+ wlr_libinput_backend_destroy(&backend->backend);
+}
+
struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
struct wlr_session *session) {
assert(display && session);
@@ -160,6 +174,9 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
backend->session_signal.notify = session_signal;
wl_signal_add(&session->session_signal, &backend->session_signal);
+ backend->display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(display, &backend->display_destroy);
+
return &backend->backend;
error_backend:
free(backend);
diff --git a/backend/multi/backend.c b/backend/multi/backend.c
index c35303e0..fc0c5b81 100644
--- a/backend/multi/backend.c
+++ b/backend/multi/backend.c
@@ -35,7 +35,6 @@ static void multi_backend_destroy(struct wlr_backend *_backend) {
wlr_backend_destroy(sub->backend);
free(sub);
}
- wlr_session_destroy(backend->session);
free(backend);
}
diff --git a/backend/session/session.c b/backend/session/session.c
index 657558fd..0ed54499 100644
--- a/backend/session/session.c
+++ b/backend/session/session.c
@@ -58,6 +58,12 @@ out:
return 1;
}
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_session *session =
+ wl_container_of(listener, session, display_destroy);
+ wlr_session_destroy(session);
+}
+
struct wlr_session *wlr_session_create(struct wl_display *disp) {
struct wlr_session *session = NULL;
const struct session_impl **iter;
@@ -100,6 +106,9 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) {
goto error_mon;
}
+ session->display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(disp, &session->display_destroy);
+
return session;
error_mon:
@@ -107,7 +116,7 @@ error_mon:
error_udev:
udev_unref(session->udev);
error_session:
- wlr_session_destroy(session);
+ session->impl->destroy(session);
return NULL;
}
@@ -116,6 +125,8 @@ void wlr_session_destroy(struct wlr_session *session) {
return;
}
+ wl_list_remove(&session->display_destroy.link);
+
wl_event_source_remove(session->udev_event);
udev_monitor_unref(session->mon);
udev_unref(session->udev);
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index 39ecc10f..6ebc6615 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -79,10 +79,12 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) {
wlr_input_device_destroy(input_device);
}
+ wl_list_remove(&backend->local_display_destroy.link);
+
free(backend->seat_name);
wl_event_source_remove(backend->remote_display_src);
- wlr_egl_free(&backend->egl);
+ wlr_egl_finish(&backend->egl);
if (backend->seat) wl_seat_destroy(backend->seat);
if (backend->shm) wl_shm_destroy(backend->shm);
if (backend->shell) zxdg_shell_v6_destroy(backend->shell);
@@ -150,6 +152,12 @@ void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend,
box->height = max_y - min_y;
}
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_wl_backend *backend =
+ wl_container_of(listener, backend, local_display_destroy);
+ wlr_wl_backend_destroy(&backend->backend);
+}
+
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
wlr_log(L_INFO, "Creating wayland backend");
@@ -176,8 +184,12 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
return false;
}
- wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT, WL_SHM_FORMAT_ARGB8888, backend->remote_display);
+ wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT,
+ WL_SHM_FORMAT_ARGB8888, backend->remote_display);
wlr_egl_bind_display(&backend->egl, backend->local_display);
+ backend->local_display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(display, &backend->local_display_destroy);
+
return &backend->backend;
}
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 5a6e90b5..c116e78e 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -183,69 +183,6 @@ static void init_atom(struct wlr_x11_backend *x11, struct wlr_x11_atom *atom,
atom->reply = xcb_intern_atom_reply(x11->xcb_conn, atom->cookie, NULL);
}
-struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
- const char *x11_display) {
- struct wlr_x11_backend *x11 = calloc(1, sizeof(*x11));
- if (!x11) {
- return NULL;
- }
-
- wlr_backend_init(&x11->backend, &backend_impl);
- x11->wl_display = display;
-
- x11->xlib_conn = XOpenDisplay(x11_display);
- if (!x11->xlib_conn) {
- wlr_log(L_ERROR, "Failed to open X connection");
- return NULL;
- }
-
- x11->xcb_conn = XGetXCBConnection(x11->xlib_conn);
- if (!x11->xcb_conn || xcb_connection_has_error(x11->xcb_conn)) {
- wlr_log(L_ERROR, "Failed to open xcb connection");
- goto error_x11;
- }
-
- XSetEventQueueOwner(x11->xlib_conn, XCBOwnsEventQueue);
-
- int fd = xcb_get_file_descriptor(x11->xcb_conn);
- struct wl_event_loop *ev = wl_display_get_event_loop(display);
- int events = WL_EVENT_READABLE | WL_EVENT_ERROR | WL_EVENT_HANGUP;
- x11->event_source = wl_event_loop_add_fd(ev, fd, events, x11_event, x11);
- if (!x11->event_source) {
- wlr_log(L_ERROR, "Could not create event source");
- goto error_x11;
- }
-
- x11->frame_timer = wl_event_loop_add_timer(ev, signal_frame, x11);
-
- x11->screen = xcb_setup_roots_iterator(xcb_get_setup(x11->xcb_conn)).data;
-
- if (!wlr_egl_init(&x11->egl, EGL_PLATFORM_X11_KHR,
- x11->screen->root_visual, x11->xlib_conn)) {
- goto error_event;
- }
-
- wlr_input_device_init(&x11->keyboard_dev, WLR_INPUT_DEVICE_KEYBOARD,
- NULL, "X11 keyboard", 0, 0);
- wlr_keyboard_init(&x11->keyboard, NULL);
- x11->keyboard_dev.keyboard = &x11->keyboard;
-
- wlr_input_device_init(&x11->pointer_dev, WLR_INPUT_DEVICE_POINTER,
- NULL, "X11 pointer", 0, 0);
- wlr_pointer_init(&x11->pointer, NULL);
- x11->pointer_dev.pointer = &x11->pointer;
-
- return &x11->backend;
-
-error_event:
- wl_event_source_remove(x11->event_source);
-error_x11:
- xcb_disconnect(x11->xcb_conn);
- XCloseDisplay(x11->xlib_conn);
- free(x11);
- return NULL;
-}
-
static bool wlr_x11_backend_start(struct wlr_backend *backend) {
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
struct wlr_x11_output *output = &x11->output;
@@ -306,8 +243,10 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) {
struct wlr_x11_output *output = &x11->output;
wlr_output_destroy(&output->wlr_output);
+ wl_list_remove(&x11->display_destroy.link);
+
wl_event_source_remove(x11->frame_timer);
- wlr_egl_free(&x11->egl);
+ wlr_egl_finish(&x11->egl);
xcb_disconnect(x11->xcb_conn);
free(x11);
@@ -328,6 +267,78 @@ static struct wlr_backend_impl backend_impl = {
.get_egl = wlr_x11_backend_get_egl,
};
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_x11_backend *x11 =
+ wl_container_of(listener, x11, display_destroy);
+ wlr_x11_backend_destroy(&x11->backend);
+}
+
+struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
+ const char *x11_display) {
+ struct wlr_x11_backend *x11 = calloc(1, sizeof(*x11));
+ if (!x11) {
+ return NULL;
+ }
+
+ wlr_backend_init(&x11->backend, &backend_impl);
+ x11->wl_display = display;
+
+ x11->xlib_conn = XOpenDisplay(x11_display);
+ if (!x11->xlib_conn) {
+ wlr_log(L_ERROR, "Failed to open X connection");
+ return NULL;
+ }
+
+ x11->xcb_conn = XGetXCBConnection(x11->xlib_conn);
+ if (!x11->xcb_conn || xcb_connection_has_error(x11->xcb_conn)) {
+ wlr_log(L_ERROR, "Failed to open xcb connection");
+ goto error_x11;
+ }
+
+ XSetEventQueueOwner(x11->xlib_conn, XCBOwnsEventQueue);
+
+ int fd = xcb_get_file_descriptor(x11->xcb_conn);
+ struct wl_event_loop *ev = wl_display_get_event_loop(display);
+ int events = WL_EVENT_READABLE | WL_EVENT_ERROR | WL_EVENT_HANGUP;
+ x11->event_source = wl_event_loop_add_fd(ev, fd, events, x11_event, x11);
+ if (!x11->event_source) {
+ wlr_log(L_ERROR, "Could not create event source");
+ goto error_x11;
+ }
+
+ x11->frame_timer = wl_event_loop_add_timer(ev, signal_frame, x11);
+
+ x11->screen = xcb_setup_roots_iterator(xcb_get_setup(x11->xcb_conn)).data;
+
+ if (!wlr_egl_init(&x11->egl, EGL_PLATFORM_X11_KHR,
+ x11->screen->root_visual, x11->xlib_conn)) {
+ goto error_event;
+ }
+
+ wlr_input_device_init(&x11->keyboard_dev, WLR_INPUT_DEVICE_KEYBOARD,
+ NULL, "X11 keyboard", 0, 0);
+ wlr_keyboard_init(&x11->keyboard, NULL);
+ x11->keyboard_dev.keyboard = &x11->keyboard;
+
+ wlr_input_device_init(&x11->pointer_dev, WLR_INPUT_DEVICE_POINTER,
+ NULL, "X11 pointer", 0, 0);
+ wlr_pointer_init(&x11->pointer, NULL);
+ x11->pointer_dev.pointer = &x11->pointer;
+
+ x11->display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(display, &x11->display_destroy);
+
+ return &x11->backend;
+
+error_event:
+ wl_event_source_remove(x11->event_source);
+error_x11:
+ xcb_disconnect(x11->xcb_conn);
+ XCloseDisplay(x11->xlib_conn);
+ free(x11);
+ return NULL;
+}
+
static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
int32_t height, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;