changeset 18716:0873698f8cce

This fixes a few weird crashes in pygnt.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Jul 2007 15:58:08 +0000
parents 64a7b13d3b8d
children d3542cffbb42
files finch/libgnt/gntmain.c finch/libgnt/gntwm.c
diffstat 2 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntmain.c	Sun Jul 29 10:48:45 2007 +0000
+++ b/finch/libgnt/gntmain.c	Sun Jul 29 15:58:08 2007 +0000
@@ -517,7 +517,8 @@
 
 void gnt_screen_release(GntWidget *widget)
 {
-	gnt_wm_window_close(wm, widget);
+	if (wm)
+		gnt_wm_window_close(wm, widget);
 }
 
 void gnt_screen_update(GntWidget *widget)
@@ -564,7 +565,9 @@
 
 void gnt_quit()
 {
-	g_hash_table_destroy(wm->nodes); /* XXX: */
+	g_object_unref(G_OBJECT(wm));
+	wm = NULL;
+
 	update_panels();
 	doupdate();
 	gnt_uninit_colors();
--- a/finch/libgnt/gntwm.c	Sun Jul 29 10:48:45 2007 +0000
+++ b/finch/libgnt/gntwm.c	Sun Jul 29 15:58:08 2007 +0000
@@ -1137,9 +1137,37 @@
 }
 
 static void
+accumulate_windows(gpointer window, gpointer node, gpointer p)
+{
+	GList *list = *(GList**)p;
+	list = g_list_prepend(list, window);
+	*(GList**)p = list;
+}
+
+static void
+gnt_wm_destroy(GObject *obj)
+{
+	GntWM *wm = GNT_WM(obj);
+	GList *list = NULL;
+	g_hash_table_foreach(wm->nodes, accumulate_windows, &list);
+	g_list_foreach(list, gnt_widget_destroy, NULL);
+	g_list_free(list);
+	g_hash_table_destroy(wm->nodes);
+	wm->nodes = NULL;
+
+	while (wm->workspaces) {
+		g_object_unref(wm->workspaces->data);
+		wm->workspaces = g_list_delete_link(wm->workspaces, wm->workspaces);
+	}
+}
+
+static void
 gnt_wm_class_init(GntWMClass *klass)
 {
 	int i;
+	GObjectClass *gclass = G_OBJECT_CLASS(klass);
+
+	gclass->dispose = gnt_wm_destroy;
 
 	klass->new_window = gnt_wm_new_window_real;
 	klass->decorate_window = NULL;