GtkSourceView widget not destroyed

Hi everyone!

In my personal project, I am trying to destroy some GtkSourceView widgets. However, whenever I show line numbers, it seems that the widget is never collected when I remove it from its parent.

I managed to do the following MWE. In this small app, pressing <Ctrl>D should destroy the GtkSourceView widget. It does it when the line numbers are not shown, but it does not do it when they are. What am I doing wrong?

#include <gtksourceview/gtksource.h>

void should_appear ()
{
	g_print ("Why am I never printed?\n");
}

int destroy (GtkWidget * window, GVariant *, gpointer)
{
	GtkWidget * scrolledwindow = gtk_window_get_child (GTK_WINDOW (window));
	/* Adding this makes no difference :
	GtkWidget * sourceview = gtk_scrolled_window_get_child (GTK_SCROLLED_WINDOW (scrolledwindow));
	gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (sourceview), FALSE);*/
	
	gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), nullptr);
	
	return 0;
}

int app_activate (GtkApplication * application)
{
	GtkWidget * window = gtk_application_window_new (application);
	GtkWidget * scrolledwindow = gtk_scrolled_window_new ();
	
	gtk_window_set_child (GTK_WINDOW (window), scrolledwindow);
	
	GtkWidget * sourceview = gtk_source_view_new ();
	
	gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), sourceview);
	g_signal_connect (sourceview, "destroy", should_appear, nullptr);
	gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (sourceview), TRUE); //When removing this line, everything works as expected.
	
	GdkModifierType modifier;
	guint keyval;
	
	gtk_accelerator_parse ("<Ctrl>D", &keyval, &modifier);
	gtk_widget_class_add_binding (GTK_WIDGET_GET_CLASS (window), keyval, modifier, destroy, nullptr);
	
	gtk_window_present (GTK_WINDOW (window));
	
	return 0;
}

int main (int argc, char * * argv)
{
	gtk_init();
	gtk_source_init ();
	
	GtkApplication * application = gtk_application_new ("com.example.test", G_APPLICATION_NON_UNIQUE);
	
	g_signal_connect (application, "activate", G_CALLBACK (app_activate), nullptr);
	
	int result = g_application_run (G_APPLICATION (application), argc, argv);
	
	g_object_unref (application);
	gtk_source_finalize ();
	
	return result;
}

I am working with Debian Trixie, using their packages for GTKSourceView (5.16.0-1) and GTK (4.18.6+ds-2).

Hi,

Thanks for the report. I’m working on a patch.

Thanks! I was not sure this was a bug so I did not open a ticket on GitLab.