From 63b0c26474cd7a816a9cfba89c92a9b328d5bf63 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 11 Jan 2008 21:34:09 -0800 Subject: [PATCH] Make TildaWindow determine number correctly Rather than just using a static, monotonically increasing number for the TildaWindow numbers, actually have tilda figure out the correct number. --- tilda-terminal.c | 20 +++++++++++++ tilda-terminal.h | 2 +- tilda-window.c | 1 + tilda.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/tilda-terminal.c b/tilda-terminal.c index 60c169c..4238274 100644 --- a/tilda-terminal.c +++ b/tilda-terminal.c @@ -25,6 +25,7 @@ static GObjectClass *parent_class = NULL; enum tilda_terminal_properties { TILDA_TERMINAL_NUMBER = 1, TILDA_TERMINAL_WINDOW_NUMBER, + TILDA_TERMINAL_TW, /* All non-constructor-only properties */ TILDA_TERMINAL_BACKGROUND_IMAGE, @@ -78,6 +79,12 @@ tilda_terminal_set_property (GObject *object, g_print ("terminal parent window number: %d\n", self->window_number); break; + case TILDA_TERMINAL_TW: + self->parent_window = g_value_get_pointer (value); + g_print ("terminal parent window: 0x%x\n", self->parent_window); + g_print ("terminal parent window number (direct): %d\n", TILDA_WINDOW(self->parent_window)->number); + break; + case TILDA_TERMINAL_BACKGROUND_IMAGE: g_free (self->background_image); self->background_image = g_value_dup_string (value); @@ -167,6 +174,10 @@ tilda_terminal_get_property (GObject *object, g_value_set_int (value, self->window_number); break; + case TILDA_TERMINAL_TW: + g_value_set_pointer (value, self->parent_window); + break; + case TILDA_TERMINAL_BACKGROUND_IMAGE: g_value_set_string (value, self->background_image); break; @@ -328,6 +339,15 @@ tilda_terminal_class_init (gpointer g_class, TILDA_TERMINAL_WINDOW_NUMBER, pspec); + pspec = g_param_spec_pointer ("parent-window", + "Pointer to terminal's parent TildaWindow", + "Set the pointer to the terminal's parent TildaWindow", + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_TERMINAL_TW, + pspec); + pspec = g_param_spec_string ("background-image", "Terminal's background image", "Get/Set terminal's background image", diff --git a/tilda-terminal.h b/tilda-terminal.h index 3887617..d451ada 100644 --- a/tilda-terminal.h +++ b/tilda-terminal.h @@ -24,7 +24,7 @@ struct _TildaTerminal { /* Instance Members */ gint window_number; - //TildaWindow *tw; + GObject *parent_window; GtkWidget *vte_term; GtkWidget *scrollbar; GtkWidget *hbox; diff --git a/tilda-window.c b/tilda-window.c index 0b197f2..adbe624 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -10,6 +10,7 @@ tilda_window_add_term (TildaWindow *tw) TildaTerminal *tt = g_object_new (TILDA_TYPE_TERMINAL, "number", mynumber++, "window-number", tw->number, + "parent-window", tw, NULL); g_ptr_array_add (tw->terms, tt); diff --git a/tilda.c b/tilda.c index e1459dd..d6d60af 100644 --- a/tilda.c +++ b/tilda.c @@ -5,6 +5,7 @@ #include "tilda-terminal.h" DBusGConnection *dbus_connection; +GPtrArray *windows; static void tilda_initialize_dbus () @@ -41,6 +42,69 @@ tilda_initialize_dbus () g_object_unref (driver_proxy); } +static gint +tilda_find_next_free_window_number () +{ + 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 () +{ + 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); + + g_print ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len); + return ret; +} + +static void +tilda_del_window (gint number) +{ + gint i; + TildaWindow *win; + + for (i=0; ilen; ++i) + { + win = g_ptr_array_index (windows, i); + + if (win->number == number) + { + g_print ("Deleting window 0x%x (number %d)\n", win, win->number); + g_ptr_array_remove_index (windows, i); + g_object_unref (G_OBJECT(win)); + break; + } + } +} + int main (int argc, char *argv[]) { TildaWindow *tw; @@ -51,16 +115,23 @@ int main (int argc, char *argv[]) /* 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 (); + tw = tilda_add_window (); + tw = tilda_add_window (); - gtk_main (); + tilda_del_window (1); + + tw = tilda_add_window (); - g_object_unref (G_OBJECT (tw)); + gtk_main (); return 0; } -- 2.25.1