From ed0bba581bdf0dd24e48de69ef51cf2420a50289 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 23 Nov 2023 13:58:36 +0100 Subject: [PATCH] backend/wayland: take wl_event_loop instead of wl_display --- backend/backend.c | 3 ++- backend/wayland/backend.c | 16 +++++++--------- backend/wayland/output.c | 5 ++--- examples/embedded.c | 3 ++- include/backend/wayland.h | 4 ++-- include/wlr/backend/wayland.h | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index fbd7bd16..9b384068 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -194,7 +194,8 @@ static struct wlr_auto_backend_monitor *auto_backend_monitor_create( } static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { - struct wlr_backend *backend = wlr_wl_backend_create(display, NULL); + struct wl_event_loop *loop = wl_display_get_event_loop(display); + struct wlr_backend *backend = wlr_wl_backend_create(loop, NULL); if (backend == NULL) { return NULL; } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index ebf36a8b..78803ffc 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -480,7 +480,7 @@ static void backend_destroy(struct wlr_backend *backend) { wlr_backend_finish(backend); - wl_list_remove(&wl->local_display_destroy.link); + wl_list_remove(&wl->event_loop_destroy.link); wl_event_source_remove(wl->remote_display_src); @@ -561,13 +561,12 @@ bool wlr_backend_is_wl(struct wlr_backend *b) { return b->impl == &backend_impl; } -static void handle_display_destroy(struct wl_listener *listener, void *data) { - struct wlr_wl_backend *wl = - wl_container_of(listener, wl, local_display_destroy); +static void handle_event_loop_destroy(struct wl_listener *listener, void *data) { + struct wlr_wl_backend *wl = wl_container_of(listener, wl, event_loop_destroy); backend_destroy(&wl->backend); } -struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, +struct wlr_backend *wlr_wl_backend_create(struct wl_event_loop *loop, struct wl_display *remote_display) { wlr_log(WLR_INFO, "Creating wayland backend"); @@ -579,7 +578,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, wlr_backend_init(&wl->backend, &backend_impl); - wl->local_display = display; + wl->event_loop = loop; wl_list_init(&wl->outputs); wl_list_init(&wl->seats); wl_list_init(&wl->buffers); @@ -644,7 +643,6 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, zwp_linux_dmabuf_feedback_v1_destroy(linux_dmabuf_feedback_v1); } - struct wl_event_loop *loop = wl_display_get_event_loop(wl->local_display); int fd = wl_display_get_fd(wl->remote_display); wl->remote_display_src = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, dispatch_events, wl); @@ -666,8 +664,8 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, wl->drm_fd = -1; } - wl->local_display_destroy.notify = handle_display_destroy; - wl_display_add_destroy_listener(display, &wl->local_display_destroy); + wl->event_loop_destroy.notify = handle_event_loop_destroy; + wl_event_loop_add_destroy_listener(loop, &wl->event_loop_destroy); const char *token = getenv("XDG_ACTIVATION_TOKEN"); if (token != NULL) { diff --git a/backend/wayland/output.c b/backend/wayland/output.c index ee82ff95..3df269c9 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -774,7 +774,7 @@ static struct wlr_wl_output *output_create(struct wlr_wl_backend *backend, wlr_output_state_set_custom_mode(&state, 1280, 720, 0); wlr_output_init(wlr_output, &backend->backend, &output_impl, - wl_display_get_event_loop(backend->local_display), &state); + backend->event_loop, &state); wlr_output_state_finish(&state); wlr_output->adaptive_sync_status = WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED; @@ -871,9 +871,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) { &xdg_toplevel_listener, output); wl_surface_commit(output->surface); - struct wl_event_loop *event_loop = wl_display_get_event_loop(backend->local_display); while (!output->configured) { - int ret = wl_event_loop_dispatch(event_loop, -1); + int ret = wl_event_loop_dispatch(backend->event_loop, -1); if (ret < 0) { wlr_log(WLR_ERROR, "wl_event_loop_dispatch() failed"); goto error; diff --git a/examples/embedded.c b/examples/embedded.c index 1e52e892..7b33d839 100644 --- a/examples/embedded.c +++ b/examples/embedded.c @@ -159,7 +159,8 @@ int main(int argc, char *argv[]) { init_egl(remote_display); struct wl_display *local_display = wl_display_create(); - struct wlr_backend *backend = wlr_wl_backend_create(local_display, remote_display); + struct wl_event_loop *event_loop = wl_display_get_event_loop(local_display); + struct wlr_backend *backend = wlr_wl_backend_create(event_loop, remote_display); struct wlr_renderer *renderer = wlr_renderer_autocreate(backend); wlr_renderer_init_wl_display(renderer, local_display); struct wlr_allocator *allocator = wlr_allocator_autocreate(backend, renderer); diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 098d1dc1..f8fb66ba 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -20,12 +20,12 @@ struct wlr_wl_backend { /* local state */ bool started; - struct wl_display *local_display; + struct wl_event_loop *event_loop; struct wl_list outputs; int drm_fd; struct wl_list buffers; // wlr_wl_buffer.link size_t requested_outputs; - struct wl_listener local_display_destroy; + struct wl_listener event_loop_destroy; char *activation_token; /* remote state */ diff --git a/include/wlr/backend/wayland.h b/include/wlr/backend/wayland.h index a30bac25..f402693a 100644 --- a/include/wlr/backend/wayland.h +++ b/include/wlr/backend/wayland.h @@ -15,7 +15,7 @@ struct wlr_input_device; * The remote_display argument is an existing libwayland-client struct wl_display * to use. Leave it NULL to create a new connection to the compositor. */ -struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, +struct wlr_backend *wlr_wl_backend_create(struct wl_event_loop *loop, struct wl_display *remote_display); /**