From 893434b2d4d2929636189ce45ba2e04dfd73817f Mon Sep 17 00:00:00 2001 From: tiosgz Date: Sat, 25 Sep 2021 16:40:12 +0000 Subject: [PATCH] for_each_surface: only iterate mapped surfaces These functions are used mostly for rendering, where including unmapped surfaces is undesired. This is a breaking change. However, few to no usages will have to be updated. --- include/wlr/types/wlr_layer_shell_v1.h | 5 ++++- include/wlr/types/wlr_surface.h | 6 +++--- include/wlr/types/wlr_xdg_shell.h | 14 ++++++++------ types/wlr_layer_shell_v1.c | 2 +- types/wlr_surface.c | 8 ++++++++ types/xdg_shell/wlr_xdg_surface.c | 2 +- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/wlr/types/wlr_layer_shell_v1.h b/include/wlr/types/wlr_layer_shell_v1.h index 7786779e..694fb3b2 100644 --- a/include/wlr/types/wlr_layer_shell_v1.h +++ b/include/wlr/types/wlr_layer_shell_v1.h @@ -143,7 +143,10 @@ bool wlr_surface_is_layer_surface(struct wlr_surface *surface); struct wlr_layer_surface_v1 *wlr_layer_surface_v1_from_wlr_surface( struct wlr_surface *surface); -/* Calls the iterator function for each sub-surface and popup of this surface */ +/** + * Calls the iterator function for each mapped sub-surface and popup of this + * surface (whether or not this surface is mapped). + */ void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface, wlr_surface_iterator_func_t iterator, void *user_data); diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index d743415f..f33ac5b1 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -264,9 +264,9 @@ void wlr_surface_get_extends(struct wlr_surface *surface, struct wlr_box *box); struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource); /** - * Call `iterator` on each surface in the surface tree, with the surface's - * position relative to the root surface. The function is called from root to - * leaves (in rendering order). + * Call `iterator` on each mapped surface in the surface tree (whether or not + * this surface is mapped), with the surface's position relative to the root + * surface. The function is called from root to leaves (in rendering order). */ void wlr_surface_for_each_surface(struct wlr_surface *surface, wlr_surface_iterator_func_t iterator, void *user_data); diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index d63132c4..cf42e82a 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -413,17 +413,19 @@ void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *surface, struct wlr_box *box); /** - * Call `iterator` on each surface and popup in the xdg-surface tree, with the - * surface's position relative to the root xdg-surface. The function is called - * from root to leaves (in rendering order). + * Call `iterator` on each mapped surface and popup in the xdg-surface tree + * (whether or not this xdg-surface is mapped), with the surface's position + * relative to the root xdg-surface. The function is called from root to leaves + * (in rendering order). */ void wlr_xdg_surface_for_each_surface(struct wlr_xdg_surface *surface, wlr_surface_iterator_func_t iterator, void *user_data); /** - * Call `iterator` on each popup's surface and popup's subsurface in the - * xdg-surface tree, with the surfaces's position relative to the root - * xdg-surface. The function is called from root to leaves (in rendering order). + * Call `iterator` on each mapped popup's surface and popup's subsurface in the + * xdg-surface tree (whether or not this xdg-surface is mapped), with the + * surfaces's position relative to the root xdg-surface. The function is called + * from root to leaves (in rendering order). */ void wlr_xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface, wlr_surface_iterator_func_t iterator, void *user_data); diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c index e10be5d3..a79cc956 100644 --- a/types/wlr_layer_shell_v1.c +++ b/types/wlr_layer_shell_v1.c @@ -506,7 +506,7 @@ void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *su struct wlr_xdg_popup *popup_state; wl_list_for_each(popup_state, &surface->popups, link) { struct wlr_xdg_surface *popup = popup_state->base; - if (!popup->configured) { + if (!popup->configured || !popup->mapped) { continue; } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index de4e9724..f481155a 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -1331,6 +1331,10 @@ static void surface_for_each_surface(struct wlr_surface *surface, int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) { struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->current.subsurfaces_below, current.link) { + if (!subsurface->mapped) { + continue; + } + struct wlr_subsurface_parent_state *state = &subsurface->current; int sx = state->x; int sy = state->y; @@ -1342,6 +1346,10 @@ static void surface_for_each_surface(struct wlr_surface *surface, int x, int y, iterator(surface, x, y, user_data); wl_list_for_each(subsurface, &surface->current.subsurfaces_above, current.link) { + if (!subsurface->mapped) { + continue; + } + struct wlr_subsurface_parent_state *state = &subsurface->current; int sx = state->x; int sy = state->y; diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index ae3426a2..d020e53d 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -583,7 +583,7 @@ static void xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface, struct wlr_xdg_popup *popup_state; wl_list_for_each(popup_state, &surface->popups, link) { struct wlr_xdg_surface *popup = popup_state->base; - if (!popup->configured) { + if (!popup->configured || !popup->mapped) { continue; }