X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda.c;h=854520a4e5498e76d0ad8df7d4130d5e7808f53c;hb=e7ae1f9774ab8aac7379b5c6a1d78cb2ba9754cf;hp=65a0df7f230dba1911977d3f10e99595f39ae0a8;hpb=ea7ec5693d350667c028e2e0f6d45da98f740125;p=tilda-gobject.git diff --git a/tilda.c b/tilda.c index 65a0df7..854520a 100644 --- a/tilda.c +++ b/tilda.c @@ -1,16 +1,15 @@ -#include #include +#include #include "tilda.h" -#include "tilda-window.h" -#include "tilda-terminal.h" +#include "tilda-controller.h" #include "tomboykeybinder.h" +/* Project-global variables */ DBusGConnection *dbus_connection; -GPtrArray *windows; static void -tilda_initialize_dbus () +tilda_dbus_init () { debug_enter (); @@ -56,75 +55,6 @@ 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; - } - } -} - static void tilda_parse_command_line (gint argc, gchar *argv[]) { @@ -171,11 +101,40 @@ tilda_parse_command_line (gint argc, gchar *argv[]) } } +static void +tilda_termination_handler (gint signum) +{ + debug_enter (); + debug_printf ("signum: %d\n", signum); + + gtk_main_quit (); +} + +/* Hook up all system signal handlers */ +static void +tilda_signal_handlers_init () +{ + struct sigaction sa; + + /* Hook up signal handlers */ + sa.sa_handler = tilda_termination_handler; + sigemptyset (&sa.sa_mask); + sa.sa_flags = 0; + + sigaction (SIGINT, &sa, NULL); + sigaction (SIGQUIT, &sa, NULL); + sigaction (SIGABRT, &sa, NULL); + sigaction (SIGTERM, &sa, NULL); + + /* SIGKILL cannot be caught according to sigaction(2) and signal(7) */ + /* sigaction (SIGKILL, &sa, NULL); */ +} + int main (int argc, char *argv[]) { debug_enter (); - TildaWindow *tw; + TildaController *tilda; #if ENABLE_NLS /* Gettext Initialization */ @@ -190,26 +149,26 @@ int main (int argc, char *argv[]) /* Initialize GTK+ (and the GObject system) */ gtk_init (&argc, &argv); + /* Hook up the signal handlers */ + tilda_signal_handlers_init (); + /* Initialize the keybinder */ tomboy_keybinder_init (); /* Start our connection to DBus */ - tilda_initialize_dbus (); + tilda_dbus_init (); - /* 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 = tilda_add_window (); + /* Create a TildaController, which manages TildaWindows, which in turn manages + * TildaTerminals. Exit when it does. */ + tilda = g_object_new (TILDA_TYPE_CONTROLLER, NULL); debug_printf ("Starting gtk_main()!\n"); gtk_main (); debug_printf ("Out of gtk_main(), going down\n"); + /* Unref the TildaController that controls this whole operation */ + g_object_unref (G_OBJECT(tilda)); + return 0; }