From 7e4f6faaaaec77acc168e904e6392d6a9def48c6 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 27 May 2024 14:22:50 +0200 Subject: [PATCH] wayland/surface: Send unmapped signal when the surface goes away This was the intention anwyway but it didn't work properly because GObject::dispose removes all signal handlers and we unmap surfaces in WaylandShellSurface::finalize. Move all the unmanaging and unmapping to the dispose vfunc where we can still run all the signal handlers. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3501 Part-of: (cherry picked from commit 4eacf97678dfc868939db53c3e1b6850bea4f113) --- src/wayland/meta-wayland-shell-surface.c | 6 +++--- src/wayland/meta-wayland-surface.c | 25 +++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/wayland/meta-wayland-shell-surface.c b/src/wayland/meta-wayland-shell-surface.c index ee086561a..d1f40e85b 100644 --- a/src/wayland/meta-wayland-shell-surface.c +++ b/src/wayland/meta-wayland-shell-surface.c @@ -314,13 +314,13 @@ meta_wayland_shell_surface_destroy_window (MetaWaylandShellSurface *shell_surfac } static void -meta_wayland_shell_surface_finalize (GObject *object) +meta_wayland_shell_surface_dispose (GObject *object) { MetaWaylandShellSurface *shell_surface = META_WAYLAND_SHELL_SURFACE (object); meta_wayland_shell_surface_destroy_window (shell_surface); - G_OBJECT_CLASS (meta_wayland_shell_surface_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_wayland_shell_surface_parent_class)->dispose (object); } static void @@ -337,7 +337,7 @@ meta_wayland_shell_surface_class_init (MetaWaylandShellSurfaceClass *klass) MetaWaylandActorSurfaceClass *actor_surface_class = META_WAYLAND_ACTOR_SURFACE_CLASS (klass); - object_class->finalize = meta_wayland_shell_surface_finalize; + object_class->dispose = meta_wayland_shell_surface_dispose; surface_role_class->assigned = meta_wayland_shell_surface_assigned; surface_role_class->pre_apply_state = diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index a6454641d..f4d83552f 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -1516,7 +1516,7 @@ meta_wayland_surface_notify_unmapped (MetaWaylandSurface *surface) } static void -meta_wayland_surface_finalize (GObject *object) +meta_wayland_surface_dispose (GObject *object) { MetaWaylandSurface *surface = META_WAYLAND_SURFACE (object); MetaWaylandCompositor *compositor = surface->compositor; @@ -1533,7 +1533,11 @@ meta_wayland_surface_finalize (GObject *object) } if (surface->buffer_held) - meta_wayland_buffer_dec_use_count (surface->buffer); + { + meta_wayland_buffer_dec_use_count (surface->buffer); + surface->buffer_held = FALSE; + } + g_clear_object (&surface->applied_state.texture); g_clear_object (&surface->buffer); @@ -1544,10 +1548,13 @@ meta_wayland_surface_finalize (GObject *object) meta_wayland_compositor_remove_presentation_feedback_surface (compositor, surface); - g_hash_table_foreach (surface->outputs, - surface_output_disconnect_signals, - surface); - g_hash_table_destroy (surface->outputs); + if (surface->outputs) + { + g_hash_table_foreach (surface->outputs, + surface_output_disconnect_signals, + surface); + } + g_clear_pointer (&surface->outputs, g_hash_table_destroy); wl_list_for_each_safe (cb, next, &surface->unassigned.pending_frame_callback_list, @@ -1562,9 +1569,9 @@ meta_wayland_surface_finalize (GObject *object) g_clear_pointer (&surface->applied_state.subsurface_branch_node, g_node_destroy); - g_hash_table_destroy (surface->shortcut_inhibited_seats); + g_clear_pointer (&surface->shortcut_inhibited_seats, g_hash_table_destroy); - G_OBJECT_CLASS (meta_wayland_surface_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_wayland_surface_parent_class)->dispose (object); } static void @@ -1866,7 +1873,7 @@ meta_wayland_surface_class_init (MetaWaylandSurfaceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = meta_wayland_surface_finalize; + object_class->dispose = meta_wayland_surface_dispose; object_class->get_property = meta_wayland_surface_get_property; obj_props[PROP_SCANOUT_CANDIDATE] =