Exit when out of terminals or windows
authorIra W. Snyder <devel@irasnyder.com>
Sat, 19 Jan 2008 22:37:15 +0000 (14:37 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sat, 19 Jan 2008 22:37:15 +0000 (14:37 -0800)
Previously, Tilda would continue to run even with no TildaTerminals
in the TildaWindow->terms array. A similar situation existed with the
Tilda->windows array.

This patch makes both places clean up after themselves and exit
their section when appropriate. The API isn't very good yet, it will
need to be improved in the future.

tilda-window.c
tilda.c
tilda.h

index c5ac71a..d994a57 100644 (file)
@@ -129,17 +129,17 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
                        if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1)
                                gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE);
 
-#if 0
-                       // FIXME FIXME FIXME: need to actually do the stuff below
-                       /* With no pages left, it's time to leave the program */
-                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
-                               gtk_main_quit ();
-#endif
-
                        /* Remove the term from our lists, then free it */
                        g_ptr_array_remove_fast (tw->terms, tt);
                        g_object_unref (G_OBJECT(tt));
 
+                       /* With no pages left, it's time to remove this window */
+                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
+                       {
+                               debug_printf ("no terminals left, closing window %d\n", tw->number);
+                               tilda_del_window (tw->number);
+                       }
+
                        /* Leave the loop, we're done */
                        break;
                }
diff --git a/tilda.c b/tilda.c
index 65a0df7..d1f6a2c 100644 (file)
--- a/tilda.c
+++ b/tilda.c
@@ -103,7 +103,7 @@ tilda_add_window ()
        return ret;
 }
 
-static void
+void
 tilda_del_window (gint number)
 {
        debug_enter ();
@@ -120,6 +120,13 @@ tilda_del_window (gint number)
                        debug_printf ("Deleting window 0x%x (number %d of %d)\n", win, win->number, windows->len-1);
                        g_ptr_array_remove_index (windows, i);
                        g_object_unref (G_OBJECT(win));
+
+                       if (windows->len == 0)
+                       {
+                               debug_printf ("No windows left, exiting...\n");
+                               gtk_main_quit ();
+                       }
+
                        break;
                }
        }
@@ -210,6 +217,9 @@ int main (int argc, char *argv[])
        gtk_main ();
        debug_printf ("Out of gtk_main(), going down\n");
 
+       /* Free the pointer array we allocated earlier */
+       g_ptr_array_free (windows, TRUE);
+
        return 0;
 }
 
diff --git a/tilda.h b/tilda.h
index 324d745..cff67cd 100644 (file)
--- a/tilda.h
+++ b/tilda.h
@@ -29,6 +29,9 @@
 /* Project-global variables */
 extern DBusGConnection *dbus_connection;
 
+/* API */
+void tilda_del_window (gint number);
+
 #endif /* TILDA_H */
 
 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */