X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda.c;h=e13ca49d61d9720c4875b9c8cb768bf2687365a7;hb=3e2d4445566d732617d584a2cb4a2aef5573ecba;hp=e1459ddf8a76a7058034db5fb58da8a3c8df51a6;hpb=e1b2e8f7f88a9359ebb43efd3ff0513287ed7b0c;p=tilda-gobject.git diff --git a/tilda.c b/tilda.c index e1459dd..e13ca49 100644 --- a/tilda.c +++ b/tilda.c @@ -5,11 +5,14 @@ #include "tilda-terminal.h" DBusGConnection *dbus_connection; +GPtrArray *windows; static void tilda_initialize_dbus () { - const gchar service_name[] = "net.sourceforge.Tilda"; + debug_enter (); + + static const gchar service_name[] = "net.sourceforge.Tilda"; GError *error = NULL; DBusGProxy *driver_proxy; int request_ret; @@ -41,26 +44,103 @@ tilda_initialize_dbus () g_object_unref (driver_proxy); } +static gint +tilda_find_next_free_window_number () +{ + debug_enter (); + + gint i, j; + gboolean found; + + for (i=0; ilen; ++j) + { + TildaWindow *tw = g_ptr_array_index (windows, j); + + if (tw->number == i) + { + found = TRUE; + break; + } + } + + if (!found) + return i; + } + + return 0; +} + +static TildaWindow * +tilda_add_window () +{ + debug_enter (); + + TildaWindow *ret; + gint number; + + number = tilda_find_next_free_window_number (); + ret = g_object_new (TILDA_TYPE_WINDOW, "number", number, NULL); + + g_ptr_array_add (windows, ret); + + debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len-1); + return ret; +} + +static void +tilda_del_window (gint number) +{ + debug_enter (); + + gint i; + TildaWindow *win; + + for (i=0; ilen; ++i) + { + win = g_ptr_array_index (windows, i); + + if (win->number == 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)); + break; + } + } +} + int main (int argc, char *argv[]) { + debug_enter (); + TildaWindow *tw; /* Initialize GTK+ (and the GObject system) */ gtk_init (&argc, &argv); + /* Initialize the keybinder */ + tomboy_keybinder_init (); + /* Start our connection to DBus */ tilda_initialize_dbus (); + /* Initialize the array of windows */ + windows = g_ptr_array_new (); + /* Create a TildaWindow, run it, and exit when it does, basically. * * This is nothing like what the real main() will be, but it's * a good start for testing and integration of more of TildaWindow * and TildaTerminal. */ - tw = g_object_new (TILDA_TYPE_WINDOW, "number", 0, NULL); + tw = tilda_add_window (); + debug_printf ("Starting gtk_main()!\n"); gtk_main (); - - g_object_unref (G_OBJECT (tw)); + debug_printf ("Out of gtk_main(), going down\n"); return 0; }