aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-08-12 08:35:54 +0200
committerIsaac Freund <mail@isaacfreund.com>2023-11-23 11:39:25 +0000
commitd23d8ed3ba4d56d3dc33a4ccc77c16b68f716f2d (patch)
treec0cdf802eece9df632bad1c39789573de5917bba
parent5717e27c06a89a64b3a168ed22682bf657b17ebf (diff)
output: setup display destroy listener in wlr_output_create_global()
The wl_display destroy listener cleans up the global (if any). wlr_output.display will go away, so setup the listener in wlr_output_create_global() instead of wlr_output_init().
-rw-r--r--types/output/output.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/types/output/output.c b/types/output/output.c
index ccb36c08..874b2b6d 100644
--- a/types/output/output.c
+++ b/types/output/output.c
@@ -128,15 +128,26 @@ static void output_bind(struct wl_client *wl_client, void *data,
wl_signal_emit_mutable(&output->events.bind, &evt);
}
+static void handle_display_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_output *output = wl_container_of(listener, output, display_destroy);
+ wlr_output_destroy_global(output);
+}
+
void wlr_output_create_global(struct wlr_output *output, struct wl_display *display) {
if (output->global != NULL) {
return;
}
+
output->global = wl_global_create(display,
&wl_output_interface, OUTPUT_VERSION, output, output_bind);
if (output->global == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate wl_output global");
+ return;
}
+
+ wl_list_remove(&output->display_destroy.link);
+ output->display_destroy.notify = handle_display_destroy;
+ wl_display_add_destroy_listener(display, &output->display_destroy);
}
void wlr_output_destroy_global(struct wlr_output *output) {
@@ -152,6 +163,9 @@ void wlr_output_destroy_global(struct wlr_output *output) {
wl_list_init(wl_resource_get_link(resource));
}
+ wl_list_remove(&output->display_destroy.link);
+ wl_list_init(&output->display_destroy.link);
+
wlr_global_destroy_safe(output->global);
output->global = NULL;
}
@@ -271,12 +285,6 @@ void wlr_output_set_description(struct wlr_output *output, const char *desc) {
wl_signal_emit_mutable(&output->events.description, output);
}
-static void handle_display_destroy(struct wl_listener *listener, void *data) {
- struct wlr_output *output =
- wl_container_of(listener, output, display_destroy);
- wlr_output_destroy_global(output);
-}
-
static void output_state_move(struct wlr_output_state *dst,
struct wlr_output_state *src) {
*dst = *src;
@@ -436,9 +444,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
}
wlr_addon_set_init(&output->addons);
-
- output->display_destroy.notify = handle_display_destroy;
- wl_display_add_destroy_listener(display, &output->display_destroy);
+ wl_list_init(&output->display_destroy.link);
if (state) {
output_apply_state(output, state);