From 668b2740ff0fed82f8e486b2abdb536cfe8c2da9 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Tue, 2 Aug 2022 18:26:46 +0200 Subject: [PATCH] Set mapped before firing map/unmap events This allows whatever the user calls from the signal handlers to react to observe the new state rather than the old, e.g. that a surface is no longer mapped in the unmap handler. --- types/data_device/wlr_drag.c | 2 +- types/wlr_input_method_v2.c | 2 +- types/wlr_layer_shell_v1.c | 3 ++- types/wlr_subcompositor.c | 4 ++-- types/xdg_shell/wlr_xdg_surface.c | 3 ++- xwayland/xwm.c | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index 9865d930..0843870d 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -112,8 +112,8 @@ static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) { icon->mapped = true; wlr_signal_emit_safe(&icon->events.map, icon); } else if (!mapped && icon->mapped) { - wlr_signal_emit_safe(&icon->events.unmap, icon); icon->mapped = false; + wlr_signal_emit_safe(&icon->events.unmap, icon); } } diff --git a/types/wlr_input_method_v2.c b/types/wlr_input_method_v2.c index fe156869..4a436e41 100644 --- a/types/wlr_input_method_v2.c +++ b/types/wlr_input_method_v2.c @@ -143,8 +143,8 @@ static void popup_surface_set_mapped( popup_surface->mapped = true; wlr_signal_emit_safe(&popup_surface->events.map, popup_surface); } else if (!mapped && popup_surface->mapped) { - wlr_signal_emit_safe(&popup_surface->events.unmap, popup_surface); popup_surface->mapped = false; + wlr_signal_emit_safe(&popup_surface->events.unmap, popup_surface); } } diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c index 038ea1d8..daee6290 100644 --- a/types/wlr_layer_shell_v1.c +++ b/types/wlr_layer_shell_v1.c @@ -262,6 +262,8 @@ static const struct zwlr_layer_surface_v1_interface layer_surface_implementation }; static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) { + surface->configured = surface->mapped = false; + // TODO: probably need to ungrab before this event wlr_signal_emit_safe(&surface->events.unmap, surface); @@ -275,7 +277,6 @@ static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) { layer_surface_configure_destroy(configure); } - surface->configured = surface->mapped = false; } static void layer_surface_destroy(struct wlr_layer_surface_v1 *surface) { diff --git a/types/wlr_subcompositor.c b/types/wlr_subcompositor.c index 9467ec3c..75902cac 100644 --- a/types/wlr_subcompositor.c +++ b/types/wlr_subcompositor.c @@ -229,8 +229,8 @@ static void subsurface_consider_map(struct wlr_subsurface *subsurface, } // Now we can map the subsurface - wlr_signal_emit_safe(&subsurface->events.map, subsurface); subsurface->mapped = true; + wlr_signal_emit_safe(&subsurface->events.map, subsurface); // Try mapping all children too struct wlr_subsurface *child; @@ -249,8 +249,8 @@ static void subsurface_unmap(struct wlr_subsurface *subsurface) { return; } - wlr_signal_emit_safe(&subsurface->events.unmap, subsurface); subsurface->mapped = false; + wlr_signal_emit_safe(&subsurface->events.unmap, subsurface); // Unmap all children struct wlr_subsurface *child; diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index 9ea8fa33..c40cf35e 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -29,6 +29,7 @@ static void xdg_surface_configure_destroy( void unmap_xdg_surface(struct wlr_xdg_surface *surface) { assert(surface->role != WLR_XDG_SURFACE_ROLE_NONE); + surface->configured = false; struct wlr_xdg_popup *popup, *popup_tmp; wl_list_for_each_safe(popup, popup_tmp, &surface->popups, link) { @@ -37,6 +38,7 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface) { // TODO: probably need to ungrab before this event if (surface->mapped) { + surface->mapped = false; wlr_signal_emit_safe(&surface->events.unmap, NULL); } @@ -56,7 +58,6 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface) { xdg_surface_configure_destroy(configure); } - surface->configured = surface->mapped = false; if (surface->configure_idle) { wl_event_source_remove(surface->configure_idle); surface->configure_idle = NULL; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b398f2ab..1bacd1ce 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -836,8 +836,8 @@ static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { } if (!surface->mapped && wlr_surface_has_buffer(surface->surface)) { - wlr_signal_emit_safe(&surface->events.map, surface); surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); xwm_set_net_client_list(surface->xwm); } } @@ -853,8 +853,8 @@ static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface, if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) { // This is a NULL commit if (surface->mapped) { - wlr_signal_emit_safe(&surface->events.unmap, surface); surface->mapped = false; + wlr_signal_emit_safe(&surface->events.unmap, surface); xwm_set_net_client_list(surface->xwm); } }