Skip to content

Commit

Permalink
visibility-group: Use a GWeakNotify instead of the destroy signal
Browse files Browse the repository at this point in the history
for automatic widget removal.

This doesn't depend on the widget still being a valid object
when the notify function is called, only a valid pointer.
  • Loading branch information
mtwebster committed Jun 8, 2024
1 parent aa78988 commit 3b82a66
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions libxapp/xapp-visibility-group.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#define DEBUG_FLAG XAPP_DEBUG_VISIBILITY_GROUP
#include "xapp-debug.h"

static void widget_destroyed (XAppVisibilityGroup *group, GObject *object);

XAppVisibilityGroup *xapp_visibility_group_copy (const XAppVisibilityGroup *group);
void xapp_visibility_group_free (XAppVisibilityGroup *group);

Expand Down Expand Up @@ -43,8 +41,8 @@ xapp_visibility_group_copy (const XAppVisibilityGroup *group)
}

static void
widget_destroyed (XAppVisibilityGroup *group,
GObject *object)
widget_disposed (XAppVisibilityGroup *group,
GObject *object)
{
DEBUG ("Widget destroyed callback: %p", object);
group->widgets = g_slist_remove (group->widgets, (gpointer) object);
Expand All @@ -61,8 +59,7 @@ add_one_widget (XAppVisibilityGroup *group,
DEBUG ("Add one widget: %p", widget);

group->widgets = g_slist_prepend (group->widgets, (gpointer) widget);

g_signal_connect (widget, "destroy", G_CALLBACK (widget_destroyed), group);
g_object_weak_ref (G_OBJECT (widget), (GWeakNotify) widget_disposed, group);

g_object_set (widget,
"visible", group->visible,
Expand Down Expand Up @@ -93,7 +90,7 @@ remove_one_widget (XAppVisibilityGroup *group,

DEBUG ("Remove one widget: %p", widget);

g_signal_handlers_disconnect_by_func (widget, widget_destroyed, group);
g_object_weak_unref (G_OBJECT (widget), (GWeakNotify) widget_disposed, group);
group->widgets = g_slist_remove (group->widgets, ptr->data);

return TRUE;
Expand All @@ -106,7 +103,7 @@ remove_widgets (XAppVisibilityGroup *group)

for (l = group->widgets; l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_func (GTK_WIDGET (l->data), widget_destroyed, group);
remove_one_widget (group, GTK_WIDGET (l->data));
}

g_clear_pointer (&group->widgets, g_slist_free);
Expand Down

0 comments on commit 3b82a66

Please sign in to comment.