X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda-window.c;h=1ac2a14ce3960eeaa8429fb57717c4de66ff499f;hb=1cb6e4d2f7d79497dd89828665de713a6175445c;hp=3bddd2d44cab328d52af1a4964c648e8de68c4ec;hpb=44782eff888e6eb99f44ca6dac9cb552fb31ca23;p=tilda-gobject.git diff --git a/tilda-window.c b/tilda-window.c index 3bddd2d..1ac2a14 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -1,6 +1,8 @@ -#include +#include /* for strcmp() */ +#include /* for gdk_x11_window_set_user_time() */ #include "tilda.h" +#include "tilda-controller.h" #include "tilda-window.h" #include "tilda-window-dbus-glue.h" #include "tomboykeybinder.h" @@ -34,10 +36,10 @@ tilda_window_find_current_terminal (TildaWindow *self) } static gint -tilda_window_find_next_free_terminal_number (TildaWindow *tw) +tilda_window_find_next_free_terminal_number (TildaWindow *self) { debug_enter (); - debug_assert (TILDA_IS_WINDOW(tw)); + debug_assert (TILDA_IS_WINDOW(self)); gint i, j; gboolean found; @@ -46,9 +48,9 @@ tilda_window_find_next_free_terminal_number (TildaWindow *tw) { found = FALSE; - for (j=0; jterms->len; ++j) + for (j=0; jterms->len; ++j) { - TildaTerminal *tt = g_ptr_array_index (tw->terms, j); + TildaTerminal *tt = g_ptr_array_index (self->terms, j); if (tt->number == i) { @@ -64,29 +66,48 @@ tilda_window_find_next_free_terminal_number (TildaWindow *tw) return 0; } -static gboolean -tilda_window_add_term (TildaWindow *tw) +/** + * Clean up and remove self completely from the program + * + * Should only be used by DBus... + */ +gboolean +tilda_window_close (TildaWindow *self) +{ + debug_enter (); + debug_assert (TILDA_IS_WINDOW(self)); + + tilda_controller_delete_window (TILDA_CONTROLLER(self->controller), self->number); + + return TRUE; +} + +gboolean +tilda_window_add_terminal (TildaWindow *self) { debug_enter (); - debug_assert (TILDA_IS_WINDOW(tw)); + debug_assert (TILDA_IS_WINDOW(self)); gint number; TildaTerminal *tt; - number = tilda_window_find_next_free_terminal_number (tw); + number = tilda_window_find_next_free_terminal_number (self); tt = g_object_new (TILDA_TYPE_TERMINAL, "number", number, - "parent-window", tw, + "parent-window", self, NULL); - g_ptr_array_add (tw->terms, tt); + g_ptr_array_add (self->terms, tt); GtkWidget *label = gtk_label_new ("Tilda"); - gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label); - gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END); - gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index); + gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(self->notebook), tt->hbox, label); + gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(self->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END); + gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), index); - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE); + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1) + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + + /* Focus the VTE Terminal */ + gtk_widget_grab_focus (tt->vte_term); return TRUE; } @@ -98,21 +119,21 @@ tilda_window_add_term (TildaWindow *tw) * Return: TRUE on success, FALSE otherwise. */ gboolean -tilda_window_remove_term (TildaWindow *tw, gint terminal_number) +tilda_window_remove_terminal (TildaWindow *self, gint terminal_number) { debug_enter (); - debug_assert (TILDA_IS_WINDOW(tw)); + debug_assert (TILDA_IS_WINDOW(self)); debug_assert (terminal_number >= 0); gint i; - for (i=0; iterms->len; ++i) + for (i=0; iterms->len; ++i) { - TildaTerminal *tt = g_ptr_array_index (tw->terms, i); + TildaTerminal *tt = g_ptr_array_index (self->terms, i); if (tt->number == terminal_number) { - gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(tw->notebook), tt->hbox); + gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(self->notebook), tt->hbox); /* Make sure the index was valid */ if (notebook_index == -1) @@ -122,21 +143,21 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number) } /* Actually remove the terminal */ - gtk_notebook_remove_page (GTK_NOTEBOOK (tw->notebook), notebook_index); + gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index); /* We should hide the tabs if there is only one tab left */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE); + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) == 1) + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->notebook), FALSE); /* Remove the term from our lists, then free it */ - g_ptr_array_remove_fast (tw->terms, tt); + g_ptr_array_remove_fast (self->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) + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) < 1) { - debug_printf ("no terminals left, closing window %d\n", tw->number); - tilda_del_window (tw->number); + debug_printf ("no terminals left, closing window %d\n", self->number); + tilda_controller_delete_window (TILDA_CONTROLLER(self->controller), self->number); } /* Leave the loop, we're done */ @@ -211,7 +232,12 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data) TildaWindow *self = TILDA_WINDOW(data); TildaTerminal *tt; - // FIXME: this doesn't handle animation! + /* This call sets the X11 window property _NET_WM_USER_TIME, which GTK+ normally + * sets for us. However, because this callback is activated via a global keybinding, + * we see the event before GDK / GTK+ does. Therefore, to get the focus, we must + * set the property ourselves. */ + gdk_x11_window_set_user_time (GTK_WIDGET(self->window)->window, + tomboy_keybinder_get_current_event_time()); switch (self->state) { @@ -230,8 +256,7 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data) "keep-above", self->keep_above, "stick", self->stick, NULL); - gtk_window_present_with_time (GTK_WINDOW(self->window), - tomboy_keybinder_get_current_event_time()); + gtk_widget_show (GTK_WIDGET(self->window)); /* Focusing the term here works perfectly, near as I can tell */ tt = tilda_window_find_current_terminal (self); @@ -287,7 +312,7 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key) return TRUE; } - g_printerr ("Keybinding unsuccessful. Reverting to original key\n"); + g_printerr (_("Bind key '%s' failed. Reverting to original keybinding\n"), self->key); /* Not successful, so rebind the old key, and return FALSE */ if (self->key != NULL && strcmp("",self->key) != 0) @@ -296,25 +321,25 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key) /* Check that it went ok */ if (!ret) - g_printerr ("Unable to bind original key as well! Oh shit...\n"); + g_printerr (_("Unable to re-bind original key '%s'. Oh shit...\n"), self->key); } else - g_printerr ("No original key to revert to!\n"); + g_printerr (_("No original key to revert to!\n")); return FALSE; } static void -tilda_window_dbus_register_object (TildaWindow *tw) +tilda_window_dbus_register_object (TildaWindow *self) { debug_enter (); - debug_assert (TILDA_IS_WINDOW(tw)); + debug_assert (TILDA_IS_WINDOW(self)); gchar *object_path; // Register this object with DBus - object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number); - dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw)); + object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", self->number); + dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(self)); g_free (object_path); } @@ -326,6 +351,7 @@ static GObjectClass *parent_class = NULL; enum tilda_window_properties { TILDA_WINDOW_NUMBER = 1, + TILDA_WINDOW_CONTROLLER, TILDA_WINDOW_KEY, @@ -364,6 +390,7 @@ tilda_window_instance_init (GTypeInstance *instance, /* Somewhat of a "poison" value, incase we don't set this */ self->number = 0xdeadbeef; + self->controller = NULL; self->state = WINDOW_UP; } @@ -383,6 +410,11 @@ tilda_window_set_property (GObject *object, debug_printf ("window number: %d\n", self->number); break; + case TILDA_WINDOW_CONTROLLER: + self->controller = g_value_get_pointer (value); + debug_printf ("window controller: 0x%x\n", self->controller); + break; + case TILDA_WINDOW_KEY: tilda_window_try_to_bind_key (self, g_value_get_string (value)); debug_printf ("window key %s\n", self->key); @@ -496,6 +528,10 @@ tilda_window_get_property (GObject *object, g_value_set_int (value, self->number); break; + case TILDA_WINDOW_CONTROLLER: + g_value_set_pointer (value, self->controller); + break; + case TILDA_WINDOW_KEY: g_value_set_string (value, self->key); break; @@ -582,8 +618,7 @@ tilda_window_constructor (GType type, /* Do other stuff here. The object is ready to go now, and all * ctor properties have been set. - * - * TODO: This is the place to do DBus-init */ + */ self = TILDA_WINDOW(obj); /* Register this object with DBus */ @@ -593,10 +628,13 @@ tilda_window_constructor (GType type, tilda_window_setup_real_transparency (self); gtk_container_add (GTK_CONTAINER(self->window), self->notebook); + g_object_set (G_OBJECT(self->notebook), "can-focus", FALSE, NULL); gtk_widget_show (self->notebook); // FIXME: Remove these, and replace with reads from the config system - g_object_set (G_OBJECT(self), "key", "F2", NULL); + gchar *mykey = g_strdup_printf ("F%d", self->number+3); // TERRIBLE HACK + g_object_set (G_OBJECT(self), "key", mykey, NULL); + g_free (mykey); g_object_set (G_OBJECT(self), "x-position", 0, "y-position", 0, NULL); g_object_set (G_OBJECT(self), "height", 400, "width", 1680, NULL); g_object_set (G_OBJECT(self), "keep-above", TRUE, "stick", TRUE, NULL); @@ -605,8 +643,8 @@ tilda_window_constructor (GType type, gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE); // FIXME: It should be configurable how many terms we add at startup - tilda_window_add_term (self); - tilda_window_add_term (self); + tilda_window_add_terminal (self); + tilda_window_add_terminal (self); /* Show us if we're ready. If not, just remain hidden. All sub-widgets must * be gtk_widget_show()n by this point. */ @@ -621,15 +659,6 @@ tilda_window_constructor (GType type, return obj; } -static void -my_unref (gpointer data, gpointer user_data) -{ - debug_enter (); - - // FIXME: This function should probably be eliminated. It /is/ rather ugly - g_object_unref (G_OBJECT(data)); -} - static void tilda_window_dispose (GObject *obj) { @@ -650,9 +679,13 @@ tilda_window_dispose (GObject *obj) * NOTE: See the following for how to deal with GtkObject-derived things: * http://library.gnome.org/devel/gtk/unstable/GtkObject.html */ - g_ptr_array_foreach (self->terms, my_unref, NULL); + g_ptr_array_foreach (self->terms, g_object_unref, NULL); gtk_widget_destroy (self->window); + /* Unbind if we were set */ + if (self->key) + tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb); + /* Chain up to the parent class */ G_OBJECT_CLASS (parent_class)->dispose (obj); } @@ -697,8 +730,8 @@ tilda_window_class_init (gpointer g_class, /* Install all of the properties */ pspec = g_param_spec_int ("number", - "Window number", - "Set window's number", + _("Window number"), + NULL, 0, // min value INT_MAX, // max value 0, // def value @@ -708,8 +741,17 @@ tilda_window_class_init (gpointer g_class, TILDA_WINDOW_NUMBER, pspec); + pspec = g_param_spec_pointer ("controller", + _("Pointer to window's controlling TildaController"), + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_WINDOW_CONTROLLER, + pspec); + pspec = g_param_spec_string ("key", - "Window's drop-down keybinding", + _("Window's drop-down keybinding"), NULL, NULL, G_PARAM_READWRITE); @@ -719,7 +761,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("height", - "Window's height", + _("Window's height"), NULL, 0, INT_MAX, @@ -731,7 +773,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("width", - "Window's width", + _("Window's width"), NULL, 0, INT_MAX, @@ -743,7 +785,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("x-position", - "Window's x position", + _("Window's x position"), NULL, 0, INT_MAX, @@ -755,7 +797,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("y-position", - "Window's y position", + _("Window's y position"), NULL, 0, INT_MAX, @@ -767,7 +809,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("tab-position", - "Window's tab position", + _("Position of window's tab bar"), NULL, 0, INT_MAX, @@ -779,7 +821,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("animation-orientation", - "Window's animation orientation", + _("Window's animation orientation"), NULL, 0, INT_MAX, @@ -791,7 +833,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_int ("animation-delay", - "Amount of time in milliseconds between animation intervals", + _("Amount of time in milliseconds between animation intervals"), NULL, 0, INT_MAX, @@ -803,7 +845,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("keep-above", - "Keep this window above all others", + _("Keep this window above all others"), NULL, FALSE, G_PARAM_READWRITE); @@ -813,7 +855,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("skip-taskbar-hint", - "Hide this window in the taskbar if TRUE", + _("Hide this window in the taskbar if TRUE"), NULL, FALSE, G_PARAM_READWRITE); @@ -823,7 +865,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("stick", - "Display this window on all workspaces", + _("Display this window on all workspaces"), NULL, FALSE, G_PARAM_READWRITE); @@ -833,7 +875,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("hidden-at-start", - "Hide the window when it is first created", + _("Hide the window when it is first created"), NULL, FALSE, G_PARAM_READWRITE); @@ -843,7 +885,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("centered-horizontally", - "Center the window horizontally", + _("Center the window horizontally"), NULL, FALSE, G_PARAM_READWRITE); @@ -853,7 +895,7 @@ tilda_window_class_init (gpointer g_class, pspec); pspec = g_param_spec_boolean ("centered-vertically", - "Center the window vertically", + _("Center the window vertically"), NULL, FALSE, G_PARAM_READWRITE);