+void
+mainwindow_setup(void)
+{
+ mw.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(mw.win), 800, 600);
+ g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
+ gtk_window_set_title(GTK_WINDOW(mw.win), __NAME__);
+
+ mw.notebook = gtk_notebook_new();
+ gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
+ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(mw.notebook), tab_pos);
+ gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
+ g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
+ G_CALLBACK(mainwindow_title_before), NULL);
+}
+
+void
+mainwindow_title_before(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
+{
+ mainwindow_title(idx);
+}
+
+/* XXX I'd like to avoid traversing the widget hierarchy. Find a better
+ * way. */
+void
+mainwindow_title(gint idx)
+{
+ GtkWidget *child, *tabbox, *evbox, *label;
+ GList *tabbox_children, *last;
+ const gchar *text;
+
+ if (idx == -1)
+ {
+ idx = gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook));
+ if (idx == -1)
+ return;
+ }
+
+ child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
+ if (child == NULL)
+ return;
+
+ evbox = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
+ tabbox = gtk_bin_get_child(GTK_BIN(evbox));
+ tabbox_children = gtk_container_get_children(GTK_CONTAINER(tabbox));
+ last = g_list_last(tabbox_children);
+ label = last->data;
+ text = gtk_label_get_text(GTK_LABEL(label));
+ gtk_window_set_title(GTK_WINDOW(mw.win), text);
+ g_list_free(tabbox_children);
+}
+