wlr-foreign-toplevel-management-v1: Simply leave and destroy code

We send the output_leave event and destroy a toplevel_output both if our
output_leave listener is called, or if the underlying wlr_output is
destroyed.

We somewhat clumsily reused the output_leave listener, which meant that
even though we had the toplevel output, we went out of our way to let
the output_leave handler find said toplevel_output again.

Simplify both pathways by adding a toplevel_output_leave function.
Should have no functional changes.
This commit is contained in:
Kenny Levinsen 2025-05-06 00:39:05 +02:00
parent e57dd9c5ef
commit aef4de2ced

View file

@ -273,12 +273,27 @@ static void toplevel_handle_output_bind(struct wl_listener *listener,
toplevel_update_idle_source(toplevel_output->toplevel);
}
static void toplevel_output_destroy(
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output) {
wl_list_remove(&toplevel_output->link);
wl_list_remove(&toplevel_output->output_bind.link);
wl_list_remove(&toplevel_output->output_destroy.link);
free(toplevel_output);
}
static void toplevel_output_leave(
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output) {
struct wlr_foreign_toplevel_handle_v1 *toplevel = toplevel_output->toplevel;
struct wlr_output *output = toplevel_output->output;
toplevel_send_output(toplevel, output, false);
toplevel_output_destroy(toplevel_output);
}
static void toplevel_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output =
wl_container_of(listener, toplevel_output, output_destroy);
wlr_foreign_toplevel_handle_v1_output_leave(toplevel_output->toplevel,
toplevel_output->output);
toplevel_output_leave(toplevel_output);
}
void wlr_foreign_toplevel_handle_v1_output_enter(
@ -310,33 +325,18 @@ void wlr_foreign_toplevel_handle_v1_output_enter(
toplevel_send_output(toplevel, output, true);
}
static void toplevel_output_destroy(
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output) {
wl_list_remove(&toplevel_output->link);
wl_list_remove(&toplevel_output->output_bind.link);
wl_list_remove(&toplevel_output->output_destroy.link);
free(toplevel_output);
}
void wlr_foreign_toplevel_handle_v1_output_leave(
struct wlr_foreign_toplevel_handle_v1 *toplevel,
struct wlr_output *output) {
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output_iterator;
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output = NULL;
wl_list_for_each(toplevel_output_iterator, &toplevel->outputs, link) {
if (toplevel_output_iterator->output == output) {
toplevel_output = toplevel_output_iterator;
break;
toplevel_output_leave(toplevel_output_iterator);
return;
}
}
if (toplevel_output) {
toplevel_send_output(toplevel, output, false);
toplevel_output_destroy(toplevel_output);
} else {
// XXX: log an error? crash?
}
// XXX: log an error? crash?
}
static void fill_array_from_toplevel_state(struct wl_array *states,