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.
This commit is contained in:
Simon Ser 2023-08-12 08:24:08 +02:00 committed by Isaac Freund
parent 63792b38e4
commit 6a7463bb8e
6 changed files with 22 additions and 9 deletions

View File

@ -221,7 +221,7 @@ int main(int argc, char *argv[]) {
wlr_compositor_create(server.wl_display, 5, server.renderer); 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); wl_list_init(&server.outputs);
server.new_output.notify = server_handle_new_output; server.new_output.notify = server_handle_new_output;

View File

@ -273,7 +273,7 @@ int main(int argc, char *argv[]) {
.display = display, .display = display,
}; };
state.layout = wlr_output_layout_create(); state.layout = wlr_output_layout_create(display);
clock_gettime(CLOCK_MONOTONIC, &state.ts_last); clock_gettime(CLOCK_MONOTONIC, &state.ts_last);
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL); 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); wlr_texture_destroy(state.cat_texture);
wl_display_destroy(state.display); wl_display_destroy(state.display);
wlr_output_layout_destroy(state.layout);
} }

View File

@ -351,7 +351,7 @@ int main(int argc, char *argv[]) {
state.allocator = wlr_allocator_autocreate(wlr, state.renderer); state.allocator = wlr_allocator_autocreate(wlr, state.renderer);
state.cursor = wlr_cursor_create(); 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_attach_output_layout(state.cursor, state.layout);
//wlr_cursor_map_to_region(state.cursor, state.config->cursor.mapped_box); //wlr_cursor_map_to_region(state.cursor, state.config->cursor.mapped_box);
wl_list_init(&state.devices); wl_list_init(&state.devices);
@ -415,5 +415,4 @@ int main(int argc, char *argv[]) {
wlr_xcursor_manager_destroy(state.xcursor_manager); wlr_xcursor_manager_destroy(state.xcursor_manager);
wlr_cursor_destroy(state.cursor); wlr_cursor_destroy(state.cursor);
wlr_output_layout_destroy(state.layout);
} }

View File

@ -26,6 +26,7 @@ struct wlr_box;
*/ */
struct wlr_output_layout { struct wlr_output_layout {
struct wl_list outputs; struct wl_list outputs;
struct wl_display *display;
struct { struct {
struct wl_signal add; // struct wlr_output_layout_output struct wl_signal add; // struct wlr_output_layout_output
@ -34,6 +35,10 @@ struct wlr_output_layout {
} events; } events;
void *data; void *data;
// private state
struct wl_listener display_destroy;
}; };
struct wlr_output_layout_output { struct wlr_output_layout_output {
@ -57,7 +62,7 @@ struct wlr_output_layout_output {
struct wl_listener commit; 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); void wlr_output_layout_destroy(struct wlr_output_layout *layout);

View File

@ -891,7 +891,7 @@ int main(int argc, char *argv[]) {
/* Creates an output layout, which a wlroots utility for working with an /* Creates an output layout, which a wlroots utility for working with an
* arrangement of screens in a physical layout. */ * 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 /* Configure a listener to be notified when new outputs are available on the
* backend. */ * backend. */
@ -1007,7 +1007,6 @@ int main(int argc, char *argv[]) {
wl_display_destroy_clients(server.wl_display); wl_display_destroy_clients(server.wl_display);
wlr_scene_node_destroy(&server.scene->tree.node); wlr_scene_node_destroy(&server.scene->tree.node);
wlr_xcursor_manager_destroy(server.cursor_mgr); wlr_xcursor_manager_destroy(server.cursor_mgr);
wlr_output_layout_destroy(server.output_layout);
wl_display_destroy(server.wl_display); wl_display_destroy(server.wl_display);
return 0; return 0;
} }

View File

@ -9,17 +9,27 @@
static const struct wlr_addon_interface addon_impl; 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)); struct wlr_output_layout *layout = calloc(1, sizeof(*layout));
if (layout == NULL) { if (layout == NULL) {
return NULL; return NULL;
} }
wl_list_init(&layout->outputs); wl_list_init(&layout->outputs);
layout->display = display;
wl_signal_init(&layout->events.add); wl_signal_init(&layout->events.add);
wl_signal_init(&layout->events.change); wl_signal_init(&layout->events.change);
wl_signal_init(&layout->events.destroy); 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; return layout;
} }
@ -45,6 +55,7 @@ void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
output_layout_output_destroy(l_output); output_layout_output_destroy(l_output);
} }
wl_list_remove(&layout->display_destroy.link);
free(layout); free(layout);
} }