pidgin/pidgin

Cleanup blist popovers on close

18 months ago, Elliott Sales de Andrade
c3c64590319f
Parents 55a099a1e619
Children 27f355b8b497
Cleanup blist popovers on close

Every time you right click on a blist node, a new popover is created. Since
it's attached to the widget, it 'leaks' until the blist is closed, and causes
several warnings when the widget is finalized.

Testing Done:
Right clicked on a few nodes, and then closed the buddy list. No warnings about extra children were raised. Also tried a few menu items to make sure they triggered Remove/Set Custom Icon/etc.

Reviewed at https://reviews.imfreedom.org/r/2046/
--- a/pidgin/gtkblist.c Mon Nov 07 23:27:06 2022 -0600
+++ b/pidgin/gtkblist.c Mon Nov 07 23:28:31 2022 -0600
@@ -1465,6 +1465,20 @@
}
static gboolean
+pidgin_blist_popover_closed_idle_cb(gpointer data) {
+ gtk_widget_unparent(GTK_WIDGET(data));
+ return G_SOURCE_REMOVE;
+}
+
+static void
+pidgin_blist_popover_closed_cb(GtkPopover *self, G_GNUC_UNUSED gpointer data) {
+ /* We cannot unparent this immediately on close, as it will be garbage
+ * collected, and the selected action will not run.
+ */
+ g_idle_add(G_SOURCE_FUNC(pidgin_blist_popover_closed_idle_cb), self);
+}
+
+static gboolean
pidgin_blist_show_context_menu(GtkWidget *tv, PurpleBlistNode *node,
gdouble x, gdouble y)
{
@@ -1592,6 +1606,8 @@
&(const GdkRectangle){(gint)x, (gint)y, 1, 1});
gtk_popover_popup(GTK_POPOVER(popover_menu));
+ g_signal_connect(popover_menu, "closed",
+ G_CALLBACK(pidgin_blist_popover_closed_cb), NULL);
handled = TRUE;
}