From d1b39b58432c471c16e09103fd2c7850e3c41950 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 23 Nov 2023 14:17:39 +0100 Subject: [PATCH] backend: take wl_event_loop instead of wl_display in wlr_backend_autocreate() --- backend/backend.c | 39 +++++++++++++++---------------------- examples/cairo-buffer.c | 2 +- examples/fullscreen-shell.c | 2 +- examples/output-layers.c | 2 +- examples/output-layout.c | 2 +- examples/pointer.c | 2 +- examples/rotation.c | 2 +- examples/scene-graph.c | 2 +- examples/simple.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/wlr/backend.h | 2 +- tinywl/tinywl.c | 2 +- 13 files changed, 28 insertions(+), 35 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 5a7434b3a..0021dbae6 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -71,10 +71,9 @@ void wlr_backend_destroy(struct wlr_backend *backend) { } } -static struct wlr_session *session_create_and_wait(struct wl_display *disp) { +static struct wlr_session *session_create_and_wait(struct wl_event_loop *loop) { #if WLR_HAS_SESSION - struct wl_event_loop *event_loop = wl_display_get_event_loop(disp); - struct wlr_session *session = wlr_session_create(event_loop); + struct wlr_session *session = wlr_session_create(loop); if (!session) { wlr_log(WLR_ERROR, "Failed to start a session"); @@ -88,7 +87,7 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) { int64_t timeout = WAIT_SESSION_TIMEOUT; while (!session->active) { - int ret = wl_event_loop_dispatch(event_loop, (int)timeout); + int ret = wl_event_loop_dispatch(loop, (int)timeout); if (ret < 0) { wlr_log_errno(WLR_ERROR, "Failed to wait for session active: " "wl_event_loop_dispatch failed"); @@ -193,8 +192,7 @@ static struct wlr_auto_backend_monitor *auto_backend_monitor_create( return monitor; } -static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { - struct wl_event_loop *loop = wl_display_get_event_loop(display); +static struct wlr_backend *attempt_wl_backend(struct wl_event_loop *loop) { struct wlr_backend *backend = wlr_wl_backend_create(loop, NULL); if (backend == NULL) { return NULL; @@ -208,10 +206,9 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { return backend; } -static struct wlr_backend *attempt_x11_backend(struct wl_display *display, +static struct wlr_backend *attempt_x11_backend(struct wl_event_loop *loop, const char *x11_display) { #if WLR_HAS_X11_BACKEND - struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wlr_backend *backend = wlr_x11_backend_create(loop, x11_display); if (backend == NULL) { return NULL; @@ -229,9 +226,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display, #endif } -static struct wlr_backend *attempt_headless_backend( - struct wl_display *display) { - struct wl_event_loop *loop = wl_display_get_event_loop(display); +static struct wlr_backend *attempt_headless_backend(struct wl_event_loop *loop) { struct wlr_backend *backend = wlr_headless_backend_create(loop); if (backend == NULL) { return NULL; @@ -300,20 +295,20 @@ static struct wlr_backend *attempt_libinput_backend(struct wlr_session *session) #endif } -static bool attempt_backend_by_name(struct wl_display *display, +static bool attempt_backend_by_name(struct wl_event_loop *loop, struct wlr_backend *multi, char *name, struct wlr_session **session_ptr) { struct wlr_backend *backend = NULL; if (strcmp(name, "wayland") == 0) { - backend = attempt_wl_backend(display); + backend = attempt_wl_backend(loop); } else if (strcmp(name, "x11") == 0) { - backend = attempt_x11_backend(display, NULL); + backend = attempt_x11_backend(loop, NULL); } else if (strcmp(name, "headless") == 0) { - backend = attempt_headless_backend(display); + backend = attempt_headless_backend(loop); } else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) { // DRM and libinput need a session if (*session_ptr == NULL) { - *session_ptr = session_create_and_wait(display); + *session_ptr = session_create_and_wait(loop); if (*session_ptr == NULL) { wlr_log(WLR_ERROR, "failed to start a session"); return false; @@ -337,14 +332,13 @@ static bool attempt_backend_by_name(struct wl_display *display, return wlr_multi_backend_add(multi, backend); } -struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, +struct wlr_backend *wlr_backend_autocreate(struct wl_event_loop *loop, struct wlr_session **session_ptr) { if (session_ptr != NULL) { *session_ptr = NULL; } struct wlr_session *session = NULL; - struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wlr_backend *multi = wlr_multi_backend_create(loop); if (!multi) { wlr_log(WLR_ERROR, "could not allocate multibackend"); @@ -365,7 +359,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, char *saveptr; char *name = strtok_r(names, ",", &saveptr); while (name != NULL) { - if (!attempt_backend_by_name(display, multi, name, &session)) { + if (!attempt_backend_by_name(loop, multi, name, &session)) { wlr_log(WLR_ERROR, "failed to add backend '%s'", name); free(names); goto error; @@ -379,7 +373,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, } if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) { - struct wlr_backend *wl_backend = attempt_wl_backend(display); + struct wlr_backend *wl_backend = attempt_wl_backend(loop); if (!wl_backend) { goto error; } @@ -394,8 +388,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, const char *x11_display = getenv("DISPLAY"); if (x11_display) { - struct wlr_backend *x11_backend = - attempt_x11_backend(display, x11_display); + struct wlr_backend *x11_backend = attempt_x11_backend(loop, x11_display); if (!x11_backend) { goto error; } @@ -409,7 +402,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, } // Attempt DRM+libinput - session = session_create_and_wait(display); + session = session_create_and_wait(loop); if (!session) { wlr_log(WLR_ERROR, "Failed to start a DRM session"); goto error; diff --git a/examples/cairo-buffer.c b/examples/cairo-buffer.c index d92a2f13a..d46198787 100644 --- a/examples/cairo-buffer.c +++ b/examples/cairo-buffer.c @@ -125,7 +125,7 @@ int main(void) { struct server server = {0}; server.display = wl_display_create(); - server.backend = wlr_backend_autocreate(server.display, NULL); + server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.display), NULL); server.scene = wlr_scene_create(); server.renderer = wlr_renderer_autocreate(server.backend); diff --git a/examples/fullscreen-shell.c b/examples/fullscreen-shell.c index 9fa24c665..46923d9ff 100644 --- a/examples/fullscreen-shell.c +++ b/examples/fullscreen-shell.c @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) { struct fullscreen_server server = {0}; server.wl_display = wl_display_create(); - server.backend = wlr_backend_autocreate(server.wl_display, NULL); + server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.wl_display), NULL); server.renderer = wlr_renderer_autocreate(server.backend); wlr_renderer_init_wl_display(server.renderer, server.wl_display); server.allocator = wlr_allocator_autocreate(server.backend, diff --git a/examples/output-layers.c b/examples/output-layers.c index c8edc00fe..1b34d5845 100644 --- a/examples/output-layers.c +++ b/examples/output-layers.c @@ -286,7 +286,7 @@ int main(int argc, char *argv[]) { struct server server = {0}; server.wl_display = wl_display_create(); - server.backend = wlr_backend_autocreate(server.wl_display, NULL); + server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.wl_display), NULL); server.renderer = wlr_renderer_autocreate(server.backend); wlr_renderer_init_wl_shm(server.renderer, server.wl_display); diff --git a/examples/output-layout.c b/examples/output-layout.c index 07ae26bc4..4400685c3 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -275,7 +275,7 @@ int main(int argc, char *argv[]) { state.layout = wlr_output_layout_create(display); clock_gettime(CLOCK_MONOTONIC, &state.ts_last); - struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); + struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!wlr) { exit(1); } diff --git a/examples/pointer.c b/examples/pointer.c index 808c7b953..7d1f4e4bd 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -341,7 +341,7 @@ int main(int argc, char *argv[]) { .display = display }; - struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); + struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!wlr) { exit(1); } diff --git a/examples/rotation.c b/examples/rotation.c index e610de335..7ee8dc780 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -250,7 +250,7 @@ int main(int argc, char *argv[]) { }; wl_list_init(&state.outputs); - struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); + struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!wlr) { exit(1); } diff --git a/examples/scene-graph.c b/examples/scene-graph.c index be1070e91..cbc091369 100644 --- a/examples/scene-graph.c +++ b/examples/scene-graph.c @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) { struct server server = {0}; server.surface_offset = 0; server.display = wl_display_create(); - server.backend = wlr_backend_autocreate(server.display, NULL); + server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.display), NULL); server.scene = wlr_scene_create(); server.renderer = wlr_renderer_autocreate(server.backend); diff --git a/examples/simple.c b/examples/simple.c index 8fe494609..1a018829a 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -181,7 +181,7 @@ int main(void) { .last_frame = { 0 }, .display = display }; - struct wlr_backend *backend = wlr_backend_autocreate(display, NULL); + struct wlr_backend *backend = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!backend) { exit(1); } diff --git a/examples/tablet.c b/examples/tablet.c index c977d7fd5..c97cafe42 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -385,7 +385,7 @@ int main(int argc, char *argv[]) { }; wl_list_init(&state.tablet_pads); wl_list_init(&state.tablet_tools); - struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); + struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!wlr) { exit(1); } diff --git a/examples/touch.c b/examples/touch.c index 439a57209..f0aca30d4 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -274,7 +274,7 @@ int main(int argc, char *argv[]) { wl_list_init(&state.touch_points); wl_list_init(&state.touch); - struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); + struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL); if (!wlr) { exit(1); } diff --git a/include/wlr/backend.h b/include/wlr/backend.h index 24d8c6b52..e7d230b97 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -41,7 +41,7 @@ struct wlr_backend { * The multi-backend will be destroyed if one of the primary underlying * backends is destroyed (e.g. if the primary DRM device is unplugged). */ -struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, +struct wlr_backend *wlr_backend_autocreate(struct wl_event_loop *loop, struct wlr_session **session_ptr); /** * Start the backend. This may signal new_input or new_output immediately, but diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index bb1d9f576..bd21dd910 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -851,7 +851,7 @@ int main(int argc, char *argv[]) { * output hardware. The autocreate option will choose the most suitable * backend based on the current environment, such as opening an X11 window * if an X11 server is running. */ - server.backend = wlr_backend_autocreate(server.wl_display, NULL); + server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.wl_display), NULL); if (server.backend == NULL) { wlr_log(WLR_ERROR, "failed to create wlr_backend"); return 1;