[Window] Focus the VteTerminal when pulled down
authorIra W. Snyder <devel@irasnyder.com>
Wed, 16 Jan 2008 21:07:43 +0000 (13:07 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Wed, 16 Jan 2008 21:07:43 +0000 (13:07 -0800)
This has the PULL_DOWN code automatically focus the VteTerminal
so that the user can begin typing. This was originally handled by
a callback, but this seems not to be necessary. It seems easier to
handle it in the PULL_DOWN code.

tilda-window.c

index b735532..fb2f0e8 100644 (file)
@@ -2,6 +2,31 @@
 #include "tilda-window.h"
 #include "tilda-window-dbus-glue.h"
 
+/**
+ * Find the TildaTerminal corresponding to the currently selected
+ * tab in self->notebook. This could go away if TildaTerminal were
+ * a proper subclass of GtkWidget.
+ */
+static TildaTerminal *
+tilda_window_find_current_terminal (TildaWindow *self)
+{
+       gint i;
+       TildaTerminal *ret;
+       gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
+       GtkWidget *box = gtk_notebook_get_nth_page (GTK_NOTEBOOK(self->notebook), current_page);
+
+       for (i=0; i<self->terms->len; ++i)
+       {
+               ret = g_ptr_array_index (self->terms, i);
+
+               if (ret->hbox == box)
+                       return ret;
+       }
+
+       g_printerr ("FIXME: unable to find current terminal!\n");
+       return NULL;
+}
+
 static gint
 tilda_window_find_next_free_terminal_number (TildaWindow *tw)
 {
@@ -135,6 +160,7 @@ static void
 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
 {
        TildaWindow *self = TILDA_WINDOW(data);
+       TildaTerminal *tt;
        g_print ("tilda_window_keybinding_cb() called! -- window %d\n", self->number);
 
        // FIXME: this doesn't handle animation!
@@ -145,6 +171,10 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
                        /* Pull Down */
                        tomboy_window_present_hardcore (GTK_WINDOW(self->window));
                        self->state = WINDOW_DOWN;
+
+                       // Focusing the term here works perfectly, near as I can tell
+                       tt = tilda_window_find_current_terminal (self);
+                       gtk_widget_grab_focus (GTK_WIDGET(tt->vte_term));
                        break;
 
                case WINDOW_DOWN: