mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-16 06:59:44 -05:00
xdg-{shell,decoration}: improve events
This commit changes the behavior of `new_*` signals to better match their names (see https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3608). wlr_xdg_shell.events.new_surface is now emitted when an xdg_surface is created, and wlr_xdg_shell.events.new_{toplevel,popup} events are introduced to get notified when an xdg_{toplevel,popup} is created. Same applies to `wlr_xdg_decoration_manager_v1.events.new_toplevel_decoration`. As a result, wlr_xdg_surface.added and wlr_xdg_toplevel_decoration_v1.added are removed, as we no longer need to track whether the corresponding event was emitted. Additionally, this commit changes the behavior of wlr_xdg_surface.events.destroy: it is now emitted when the xdg_surface is destroyed, as the name suggests. wlr_xdg_{toplevel,popup}.events.destroy events are added to get notified when an xdg_{toplevel,popup} is destroyed.
This commit is contained in:
parent
d61ec694b3
commit
c85838892d
12 changed files with 107 additions and 134 deletions
|
|
@ -63,7 +63,7 @@ static void toplevel_decoration_handle_resource_destroy(
|
|||
toplevel_decoration_from_resource(resource);
|
||||
wl_signal_emit_mutable(&decoration->events.destroy, decoration);
|
||||
wl_list_remove(&decoration->surface_commit.link);
|
||||
wl_list_remove(&decoration->surface_destroy.link);
|
||||
wl_list_remove(&decoration->toplevel_destroy.link);
|
||||
wl_list_remove(&decoration->surface_configure.link);
|
||||
wl_list_remove(&decoration->surface_ack_configure.link);
|
||||
struct wlr_xdg_toplevel_decoration_v1_configure *configure, *tmp;
|
||||
|
|
@ -74,10 +74,10 @@ static void toplevel_decoration_handle_resource_destroy(
|
|||
free(decoration);
|
||||
}
|
||||
|
||||
static void toplevel_decoration_handle_surface_destroy(
|
||||
static void toplevel_decoration_handle_toplevel_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||
wl_container_of(listener, decoration, surface_destroy);
|
||||
wl_container_of(listener, decoration, toplevel_destroy);
|
||||
|
||||
wl_resource_post_error(decoration->resource,
|
||||
ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ORPHANED,
|
||||
|
|
@ -145,15 +145,8 @@ static void toplevel_decoration_handle_surface_commit(
|
|||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||
wl_container_of(listener, decoration, surface_commit);
|
||||
struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager;
|
||||
|
||||
decoration->current = decoration->pending;
|
||||
|
||||
if (decoration->toplevel->base->added && !decoration->added) {
|
||||
decoration->added = true;
|
||||
wl_signal_emit_mutable(&manager->events.new_toplevel_decoration,
|
||||
decoration);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl;
|
||||
|
|
@ -223,30 +216,18 @@ static void decoration_manager_handle_get_toplevel_decoration(
|
|||
wl_signal_init(&decoration->events.destroy);
|
||||
wl_signal_init(&decoration->events.request_mode);
|
||||
|
||||
wl_signal_add(&toplevel->base->events.destroy,
|
||||
&decoration->surface_destroy);
|
||||
decoration->surface_destroy.notify =
|
||||
toplevel_decoration_handle_surface_destroy;
|
||||
wl_signal_add(&toplevel->base->events.configure,
|
||||
&decoration->surface_configure);
|
||||
decoration->surface_configure.notify =
|
||||
toplevel_decoration_handle_surface_configure;
|
||||
wl_signal_add(&toplevel->base->events.ack_configure,
|
||||
&decoration->surface_ack_configure);
|
||||
decoration->surface_ack_configure.notify =
|
||||
toplevel_decoration_handle_surface_ack_configure;
|
||||
wl_signal_add(&toplevel->base->surface->events.commit,
|
||||
&decoration->surface_commit);
|
||||
decoration->surface_commit.notify =
|
||||
toplevel_decoration_handle_surface_commit;
|
||||
wl_signal_add(&toplevel->events.destroy, &decoration->toplevel_destroy);
|
||||
decoration->toplevel_destroy.notify = toplevel_decoration_handle_toplevel_destroy;
|
||||
wl_signal_add(&toplevel->base->events.configure, &decoration->surface_configure);
|
||||
decoration->surface_configure.notify = toplevel_decoration_handle_surface_configure;
|
||||
wl_signal_add(&toplevel->base->events.ack_configure, &decoration->surface_ack_configure);
|
||||
decoration->surface_ack_configure.notify = toplevel_decoration_handle_surface_ack_configure;
|
||||
wl_signal_add(&toplevel->base->surface->events.commit, &decoration->surface_commit);
|
||||
decoration->surface_commit.notify = toplevel_decoration_handle_surface_commit;
|
||||
|
||||
wl_list_insert(&manager->decorations, &decoration->link);
|
||||
|
||||
if (toplevel->base->added) {
|
||||
decoration->added = true;
|
||||
wl_signal_emit_mutable(&manager->events.new_toplevel_decoration,
|
||||
decoration);
|
||||
}
|
||||
wl_signal_emit_mutable(&manager->events.new_toplevel_decoration, decoration);
|
||||
}
|
||||
|
||||
static const struct zxdg_decoration_manager_v1_interface
|
||||
|
|
|
|||
|
|
@ -40,15 +40,15 @@ static struct wlr_xdg_toplevel *verify_is_toplevel(struct wl_resource *resource,
|
|||
|
||||
static void destroy_imported_child(struct wlr_xdg_imported_child_v1 *child) {
|
||||
wl_list_remove(&child->xdg_toplevel_set_parent.link);
|
||||
wl_list_remove(&child->xdg_surface_destroy.link);
|
||||
wl_list_remove(&child->xdg_toplevel_destroy.link);
|
||||
wl_list_remove(&child->link);
|
||||
free(child);
|
||||
}
|
||||
|
||||
static void handle_child_xdg_surface_destroy(
|
||||
static void handle_child_xdg_toplevel_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_imported_child_v1 *child =
|
||||
wl_container_of(listener, child, xdg_surface_destroy);
|
||||
wl_container_of(listener, child, xdg_toplevel_destroy);
|
||||
destroy_imported_child(child);
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
child->surface = wlr_surface_child;
|
||||
child->xdg_surface_destroy.notify = handle_child_xdg_surface_destroy;
|
||||
child->xdg_toplevel_destroy.notify = handle_child_xdg_toplevel_destroy;
|
||||
child->xdg_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent;
|
||||
|
||||
if (!wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel)) {
|
||||
|
|
@ -110,10 +110,8 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
|
|||
}
|
||||
|
||||
wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel);
|
||||
wl_signal_add(&child_toplevel->base->events.destroy,
|
||||
&child->xdg_surface_destroy);
|
||||
wl_signal_add(&child_toplevel->events.set_parent,
|
||||
&child->xdg_toplevel_set_parent);
|
||||
wl_signal_add(&child_toplevel->events.destroy, &child->xdg_toplevel_destroy);
|
||||
wl_signal_add(&child_toplevel->events.set_parent, &child->xdg_toplevel_set_parent);
|
||||
|
||||
wl_list_insert(&imported->children, &child->link);
|
||||
}
|
||||
|
|
@ -173,7 +171,7 @@ static void destroy_imported(struct wlr_xdg_imported_v1 *imported) {
|
|||
static void destroy_exported(struct wlr_xdg_exported_v1 *exported) {
|
||||
wlr_xdg_foreign_exported_finish(&exported->base);
|
||||
|
||||
wl_list_remove(&exported->xdg_surface_destroy.link);
|
||||
wl_list_remove(&exported->xdg_toplevel_destroy.link);
|
||||
wl_list_remove(&exported->link);
|
||||
wl_resource_set_user_data(exported->resource, NULL);
|
||||
free(exported);
|
||||
|
|
@ -189,10 +187,9 @@ static void xdg_exported_handle_resource_destroy(
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_xdg_surface_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
static void handle_xdg_toplevel_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_exported_v1 *exported =
|
||||
wl_container_of(listener, exported, xdg_surface_destroy);
|
||||
wl_container_of(listener, exported, xdg_toplevel_destroy);
|
||||
|
||||
destroy_exported(exported);
|
||||
}
|
||||
|
|
@ -240,8 +237,8 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
|
|||
|
||||
zxdg_exported_v1_send_handle(exported->resource, exported->base.handle);
|
||||
|
||||
exported->xdg_surface_destroy.notify = handle_xdg_surface_destroy;
|
||||
wl_signal_add(&xdg_toplevel->base->events.destroy, &exported->xdg_surface_destroy);
|
||||
exported->xdg_toplevel_destroy.notify = handle_xdg_toplevel_destroy;
|
||||
wl_signal_add(&xdg_toplevel->base->events.destroy, &exported->xdg_toplevel_destroy);
|
||||
}
|
||||
|
||||
static const struct zxdg_exporter_v1_interface xdg_exporter_impl = {
|
||||
|
|
|
|||
|
|
@ -45,15 +45,15 @@ static struct wlr_xdg_toplevel *verify_is_toplevel(struct wl_resource *resource,
|
|||
|
||||
static void destroy_imported_child(struct wlr_xdg_imported_child_v2 *child) {
|
||||
wl_list_remove(&child->xdg_toplevel_set_parent.link);
|
||||
wl_list_remove(&child->xdg_surface_destroy.link);
|
||||
wl_list_remove(&child->xdg_toplevel_destroy.link);
|
||||
wl_list_remove(&child->link);
|
||||
free(child);
|
||||
}
|
||||
|
||||
static void handle_child_xdg_surface_destroy(
|
||||
static void handle_child_xdg_toplevel_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_imported_child_v2 *child =
|
||||
wl_container_of(listener, child, xdg_surface_destroy);
|
||||
wl_container_of(listener, child, xdg_toplevel_destroy);
|
||||
destroy_imported_child(child);
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
child->surface = wlr_surface_child;
|
||||
child->xdg_surface_destroy.notify = handle_child_xdg_surface_destroy;
|
||||
child->xdg_toplevel_destroy.notify = handle_child_xdg_toplevel_destroy;
|
||||
child->xdg_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent;
|
||||
|
||||
if (!wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel)) {
|
||||
|
|
@ -113,10 +113,8 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
|
|||
}
|
||||
|
||||
wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel);
|
||||
wl_signal_add(&child_toplevel->base->events.destroy,
|
||||
&child->xdg_surface_destroy);
|
||||
wl_signal_add(&child_toplevel->events.set_parent,
|
||||
&child->xdg_toplevel_set_parent);
|
||||
wl_signal_add(&child_toplevel->events.destroy, &child->xdg_toplevel_destroy);
|
||||
wl_signal_add(&child_toplevel->events.set_parent, &child->xdg_toplevel_set_parent);
|
||||
|
||||
wl_list_insert(&imported->children, &child->link);
|
||||
}
|
||||
|
|
@ -176,7 +174,7 @@ static void destroy_imported(struct wlr_xdg_imported_v2 *imported) {
|
|||
static void destroy_exported(struct wlr_xdg_exported_v2 *exported) {
|
||||
wlr_xdg_foreign_exported_finish(&exported->base);
|
||||
|
||||
wl_list_remove(&exported->xdg_surface_destroy.link);
|
||||
wl_list_remove(&exported->xdg_toplevel_destroy.link);
|
||||
wl_list_remove(&exported->link);
|
||||
wl_resource_set_user_data(exported->resource, NULL);
|
||||
free(exported);
|
||||
|
|
@ -192,10 +190,9 @@ static void xdg_exported_handle_resource_destroy(
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_xdg_surface_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
static void handle_xdg_toplevel_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_exported_v2 *exported =
|
||||
wl_container_of(listener, exported, xdg_surface_destroy);
|
||||
wl_container_of(listener, exported, xdg_toplevel_destroy);
|
||||
|
||||
destroy_exported(exported);
|
||||
}
|
||||
|
|
@ -243,8 +240,8 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
|
|||
|
||||
zxdg_exported_v2_send_handle(exported->resource, exported->base.handle);
|
||||
|
||||
exported->xdg_surface_destroy.notify = handle_xdg_surface_destroy;
|
||||
wl_signal_add(&xdg_toplevel->base->events.destroy, &exported->xdg_surface_destroy);
|
||||
exported->xdg_toplevel_destroy.notify = handle_xdg_toplevel_destroy;
|
||||
wl_signal_add(&xdg_toplevel->base->events.destroy, &exported->xdg_toplevel_destroy);
|
||||
}
|
||||
|
||||
static const struct zxdg_exporter_v2_interface xdg_exporter_impl = {
|
||||
|
|
|
|||
|
|
@ -415,6 +415,7 @@ void create_xdg_popup(struct wlr_xdg_surface *surface,
|
|||
&positioner->rules, &surface->popup->scheduled.geometry);
|
||||
surface->popup->scheduled.rules = positioner->rules;
|
||||
|
||||
wl_signal_init(&surface->popup->events.destroy);
|
||||
wl_signal_init(&surface->popup->events.reposition);
|
||||
|
||||
if (parent) {
|
||||
|
|
@ -426,6 +427,8 @@ void create_xdg_popup(struct wlr_xdg_surface *surface,
|
|||
}
|
||||
|
||||
set_xdg_surface_role_object(surface, surface->popup->resource);
|
||||
|
||||
wl_signal_emit_mutable(&surface->client->shell->events.new_popup, surface->popup);
|
||||
}
|
||||
|
||||
void reset_xdg_popup(struct wlr_xdg_popup *popup) {
|
||||
|
|
@ -460,14 +463,9 @@ void destroy_xdg_popup(struct wlr_xdg_popup *popup) {
|
|||
wlr_surface_unmap(popup->base->surface);
|
||||
reset_xdg_popup(popup);
|
||||
|
||||
// TODO: improve events
|
||||
if (popup->base->added) {
|
||||
wl_signal_emit_mutable(&popup->base->events.destroy, NULL);
|
||||
popup->base->added = false;
|
||||
}
|
||||
wl_signal_emit_mutable(&popup->events.destroy, NULL);
|
||||
|
||||
popup->base->popup = NULL;
|
||||
|
||||
wl_list_remove(&popup->link);
|
||||
wl_resource_set_user_data(popup->resource, NULL);
|
||||
free(popup);
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display,
|
|||
xdg_shell->global = global;
|
||||
|
||||
wl_signal_init(&xdg_shell->events.new_surface);
|
||||
wl_signal_init(&xdg_shell->events.new_toplevel);
|
||||
wl_signal_init(&xdg_shell->events.new_popup);
|
||||
wl_signal_init(&xdg_shell->events.destroy);
|
||||
|
||||
xdg_shell->display_destroy.notify = handle_display_destroy;
|
||||
|
|
|
|||
|
|
@ -307,12 +307,6 @@ static void xdg_surface_role_commit(struct wlr_surface *wlr_surface) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (!surface->added) {
|
||||
surface->added = true;
|
||||
wl_signal_emit_mutable(&surface->client->shell->events.new_surface,
|
||||
surface);
|
||||
}
|
||||
|
||||
if (wlr_surface_has_buffer(wlr_surface)) {
|
||||
wlr_surface_map(wlr_surface);
|
||||
}
|
||||
|
|
@ -392,6 +386,8 @@ void create_xdg_surface(struct wlr_xdg_client *client, struct wlr_surface *wlr_s
|
|||
wl_list_insert(&client->surfaces, &surface->link);
|
||||
|
||||
wlr_surface_set_role_object(wlr_surface, surface->resource);
|
||||
|
||||
wl_signal_emit_mutable(&surface->client->shell->events.new_surface, surface);
|
||||
}
|
||||
|
||||
bool set_xdg_surface_role(struct wlr_xdg_surface *surface, enum wlr_xdg_surface_role role) {
|
||||
|
|
@ -466,6 +462,8 @@ void destroy_xdg_surface(struct wlr_xdg_surface *surface) {
|
|||
destroy_xdg_surface_role_object(surface);
|
||||
reset_xdg_surface(surface);
|
||||
|
||||
wl_signal_emit_mutable(&surface->events.destroy, NULL);
|
||||
|
||||
wl_list_remove(&surface->link);
|
||||
|
||||
wl_resource_set_user_data(surface->resource, NULL);
|
||||
|
|
|
|||
|
|
@ -476,6 +476,7 @@ void create_xdg_toplevel(struct wlr_xdg_surface *surface,
|
|||
}
|
||||
surface->toplevel->base = surface;
|
||||
|
||||
wl_signal_init(&surface->toplevel->events.destroy);
|
||||
wl_signal_init(&surface->toplevel->events.request_maximize);
|
||||
wl_signal_init(&surface->toplevel->events.request_fullscreen);
|
||||
wl_signal_init(&surface->toplevel->events.request_minimize);
|
||||
|
|
@ -499,6 +500,8 @@ void create_xdg_toplevel(struct wlr_xdg_surface *surface,
|
|||
&xdg_toplevel_implementation, surface->toplevel, NULL);
|
||||
|
||||
set_xdg_surface_role_object(surface, surface->toplevel->resource);
|
||||
|
||||
wl_signal_emit_mutable(&surface->client->shell->events.new_toplevel, surface->toplevel);
|
||||
}
|
||||
|
||||
void reset_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) {
|
||||
|
|
@ -524,11 +527,7 @@ void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) {
|
|||
wlr_surface_unmap(toplevel->base->surface);
|
||||
reset_xdg_toplevel(toplevel);
|
||||
|
||||
// TODO: improve events
|
||||
if (toplevel->base->added) {
|
||||
wl_signal_emit_mutable(&toplevel->base->events.destroy, NULL);
|
||||
toplevel->base->added = false;
|
||||
}
|
||||
wl_signal_emit_mutable(&toplevel->events.destroy, NULL);
|
||||
|
||||
toplevel->base->toplevel = NULL;
|
||||
wl_resource_set_user_data(toplevel->resource, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue