mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-21 20:35:58 +01:00
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().
This commit is contained in:
parent
5717e27c06
commit
d23d8ed3ba
1 changed files with 15 additions and 9 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue