From 6a7463bb8e29c55b906dd66e2ce3625dcccbd3f4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 12 Aug 2023 08:24:08 +0200 Subject: [PATCH] output-layout: take wl_display in constructor The output layout creates and destroys wl_output globals. We will soon need the wl_display to do so. --- examples/fullscreen-shell.c | 2 +- examples/output-layout.c | 3 +-- examples/pointer.c | 3 +-- include/wlr/types/wlr_output_layout.h | 7 ++++++- tinywl/tinywl.c | 3 +-- types/wlr_output_layout.c | 13 ++++++++++++- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/fullscreen-shell.c b/examples/fullscreen-shell.c index 5c36b8b1..afc3c876 100644 --- a/examples/fullscreen-shell.c +++ b/examples/fullscreen-shell.c @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) { wlr_compositor_create(server.wl_display, 5, server.renderer); - server.output_layout = wlr_output_layout_create(); + server.output_layout = wlr_output_layout_create(server.wl_display); wl_list_init(&server.outputs); server.new_output.notify = server_handle_new_output; diff --git a/examples/output-layout.c b/examples/output-layout.c index de5217e4..7d02dc9c 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -273,7 +273,7 @@ int main(int argc, char *argv[]) { .display = display, }; - state.layout = wlr_output_layout_create(); + state.layout = wlr_output_layout_create(display); clock_gettime(CLOCK_MONOTONIC, &state.ts_last); struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); @@ -303,5 +303,4 @@ int main(int argc, char *argv[]) { wlr_texture_destroy(state.cat_texture); wl_display_destroy(state.display); - wlr_output_layout_destroy(state.layout); } diff --git a/examples/pointer.c b/examples/pointer.c index 5d9de33b..3600dc7b 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -351,7 +351,7 @@ int main(int argc, char *argv[]) { state.allocator = wlr_allocator_autocreate(wlr, state.renderer); state.cursor = wlr_cursor_create(); - state.layout = wlr_output_layout_create(); + state.layout = wlr_output_layout_create(display); wlr_cursor_attach_output_layout(state.cursor, state.layout); //wlr_cursor_map_to_region(state.cursor, state.config->cursor.mapped_box); wl_list_init(&state.devices); @@ -415,5 +415,4 @@ int main(int argc, char *argv[]) { wlr_xcursor_manager_destroy(state.xcursor_manager); wlr_cursor_destroy(state.cursor); - wlr_output_layout_destroy(state.layout); } diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 26bb79b0..40c7fb93 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -26,6 +26,7 @@ struct wlr_box; */ struct wlr_output_layout { struct wl_list outputs; + struct wl_display *display; struct { struct wl_signal add; // struct wlr_output_layout_output @@ -34,6 +35,10 @@ struct wlr_output_layout { } events; void *data; + + // private state + + struct wl_listener display_destroy; }; struct wlr_output_layout_output { @@ -57,7 +62,7 @@ struct wlr_output_layout_output { struct wl_listener commit; }; -struct wlr_output_layout *wlr_output_layout_create(void); +struct wlr_output_layout *wlr_output_layout_create(struct wl_display *display); void wlr_output_layout_destroy(struct wlr_output_layout *layout); diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index e3e8f237..5a57addd 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -891,7 +891,7 @@ int main(int argc, char *argv[]) { /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ - server.output_layout = wlr_output_layout_create(); + server.output_layout = wlr_output_layout_create(server.wl_display); /* Configure a listener to be notified when new outputs are available on the * backend. */ @@ -1007,7 +1007,6 @@ int main(int argc, char *argv[]) { wl_display_destroy_clients(server.wl_display); wlr_scene_node_destroy(&server.scene->tree.node); wlr_xcursor_manager_destroy(server.cursor_mgr); - wlr_output_layout_destroy(server.output_layout); wl_display_destroy(server.wl_display); return 0; } diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index e0bd7026..94ba779e 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -9,17 +9,27 @@ static const struct wlr_addon_interface addon_impl; -struct wlr_output_layout *wlr_output_layout_create(void) { +static void output_layout_handle_display_destroy(struct wl_listener *listener, + void *data) { + struct wlr_output_layout *layout = wl_container_of(listener, layout, display_destroy); + wlr_output_layout_destroy(layout); +} + +struct wlr_output_layout *wlr_output_layout_create(struct wl_display *display) { struct wlr_output_layout *layout = calloc(1, sizeof(*layout)); if (layout == NULL) { return NULL; } wl_list_init(&layout->outputs); + layout->display = display; wl_signal_init(&layout->events.add); wl_signal_init(&layout->events.change); wl_signal_init(&layout->events.destroy); + layout->display_destroy.notify = output_layout_handle_display_destroy; + wl_display_add_destroy_listener(display, &layout->display_destroy); + return layout; } @@ -45,6 +55,7 @@ void wlr_output_layout_destroy(struct wlr_output_layout *layout) { output_layout_output_destroy(l_output); } + wl_list_remove(&layout->display_destroy.link); free(layout); }