From c63f3659c54f70398100fcec13fd5f69d408689e Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Sat, 4 Mar 2023 22:42:40 +0300 Subject: [PATCH] layer-shell: use unified map logic --- include/wlr/types/wlr_layer_shell_v1.h | 16 +-------- types/scene/layer_shell_v1.c | 8 ++--- types/wlr_layer_shell_v1.c | 50 ++++++++------------------ 3 files changed, 19 insertions(+), 55 deletions(-) diff --git a/include/wlr/types/wlr_layer_shell_v1.h b/include/wlr/types/wlr_layer_shell_v1.h index d94b5923..e15b30c2 100644 --- a/include/wlr/types/wlr_layer_shell_v1.h +++ b/include/wlr/types/wlr_layer_shell_v1.h @@ -84,7 +84,7 @@ struct wlr_layer_surface_v1 { char *namespace; - bool added, configured, mapped; + bool added, configured; struct wl_list configure_list; struct wlr_layer_surface_v1_state current, pending; @@ -97,20 +97,6 @@ struct wlr_layer_surface_v1 { * mapped. */ struct wl_signal destroy; - /** - * The map signal indicates that the client has configured itself and is - * ready to be rendered by the compositor. - */ - struct wl_signal map; - /** - * The unmap signal indicates that the surface is no longer in a state where - * it should be rendered by the compositor. This might happen if the surface - * no longer has a displayable buffer because either the surface has been - * hidden or is about to be destroyed. It is guaranteed that the unmap signal - * is raised before the destroy signal if the layer surface is destroyed - * while mapped. - */ - struct wl_signal unmap; /** * The new_popup signal is raised when a new popup is created. The data * parameter passed to the listener is a pointer to the new diff --git a/types/scene/layer_shell_v1.c b/types/scene/layer_shell_v1.c index 3ed616a9..67fdda28 100644 --- a/types/scene/layer_shell_v1.c +++ b/types/scene/layer_shell_v1.c @@ -129,7 +129,7 @@ void wlr_scene_layer_surface_v1_configure( wlr_scene_node_set_position(&scene_layer_surface->tree->node, box.x, box.y); wlr_layer_surface_v1_configure(layer_surface, box.width, box.height); - if (layer_surface->mapped && state->exclusive_zone > 0) { + if (layer_surface->surface->mapped && state->exclusive_zone > 0) { layer_surface_exclusive_zone(state, usable_area); } } @@ -171,16 +171,16 @@ struct wlr_scene_layer_surface_v1 *wlr_scene_layer_surface_v1_create( scene_layer_surface->layer_surface_map.notify = scene_layer_surface_handle_layer_surface_map; - wl_signal_add(&layer_surface->events.map, + wl_signal_add(&layer_surface->surface->events.map, &scene_layer_surface->layer_surface_map); scene_layer_surface->layer_surface_unmap.notify = scene_layer_surface_handle_layer_surface_unmap; - wl_signal_add(&layer_surface->events.unmap, + wl_signal_add(&layer_surface->surface->events.unmap, &scene_layer_surface->layer_surface_unmap); wlr_scene_node_set_enabled(&scene_layer_surface->tree->node, - layer_surface->mapped); + layer_surface->surface->mapped); return scene_layer_surface; } diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c index 359bcc6a..82b87bc9 100644 --- a/types/wlr_layer_shell_v1.c +++ b/types/wlr_layer_shell_v1.c @@ -264,23 +264,6 @@ static const struct zwlr_layer_surface_v1_interface layer_surface_implementation .set_layer = layer_surface_set_layer, }; -static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) { - surface->configured = surface->mapped = false; - - // TODO: probably need to ungrab before this event - wl_signal_emit_mutable(&surface->events.unmap, surface); - - struct wlr_xdg_popup *popup, *popup_tmp; - wl_list_for_each_safe(popup, popup_tmp, &surface->popups, link) { - wlr_xdg_popup_destroy(popup); - } - - struct wlr_layer_surface_v1_configure *configure, *tmp; - wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { - layer_surface_configure_destroy(configure); - } -} - static void layer_surface_resource_destroy(struct wl_resource *resource) { struct wlr_layer_surface_v1 *surface = wlr_layer_surface_v1_from_resource(resource); @@ -351,32 +334,32 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) { if (!surface->added) { surface->added = true; - assert(!surface->configured); - assert(!surface->mapped); wl_signal_emit_mutable(&surface->shell->events.new_surface, surface); // Return early here as the compositor may have closed this layer surface // in response to the new_surface event. return; } - if (surface->configured && wlr_surface_has_buffer(surface->surface) && - !surface->mapped) { - surface->mapped = true; - wl_signal_emit_mutable(&surface->events.map, surface); + if (surface->configured && wlr_surface_has_buffer(wlr_surface)) { + wlr_surface_map(wlr_surface); } } -static void layer_surface_role_precommit(struct wlr_surface *wlr_surface, - const struct wlr_surface_state *state) { +static void layer_surface_role_unmap(struct wlr_surface *wlr_surface) { struct wlr_layer_surface_v1 *surface = wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface); assert(surface != NULL); - if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) { - // This is a NULL commit - if (surface->configured && surface->mapped) { - layer_surface_unmap(surface); - } + surface->configured = false; + + struct wlr_xdg_popup *popup, *popup_tmp; + wl_list_for_each_safe(popup, popup_tmp, &surface->popups, link) { + wlr_xdg_popup_destroy(popup); + } + + struct wlr_layer_surface_v1_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + layer_surface_configure_destroy(configure); } } @@ -385,9 +368,6 @@ static void layer_surface_role_destroy(struct wlr_surface *wlr_surface) { wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface); assert(surface != NULL); - if (surface->configured && surface->mapped) { - layer_surface_unmap(surface); - } wl_signal_emit_mutable(&surface->events.destroy, surface); wl_resource_set_user_data(surface->resource, NULL); free(surface->namespace); @@ -397,7 +377,7 @@ static void layer_surface_role_destroy(struct wlr_surface *wlr_surface) { static const struct wlr_surface_role layer_surface_role = { .name = "zwlr_layer_surface_v1", .commit = layer_surface_role_commit, - .precommit = layer_surface_role_precommit, + .unmap = layer_surface_role_unmap, .destroy = layer_surface_role_destroy, }; @@ -458,8 +438,6 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, wl_list_init(&surface->popups); wl_signal_init(&surface->events.destroy); - wl_signal_init(&surface->events.map); - wl_signal_init(&surface->events.unmap); wl_signal_init(&surface->events.new_popup); wlr_log(WLR_DEBUG, "new layer_surface %p (res %p)",