+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);
+}
+
+gboolean
+menu_web_view(WebKitWebView *web_view, WebKitContextMenu *menu, GdkEvent *ev,
+ WebKitHitTestResult *ht, gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ GSimpleAction *action = NULL;
+ WebKitContextMenuItem *mi = NULL;
+ const gchar *uri = NULL;
+
+ (void)ev;
+
+ if (webkit_hit_test_result_context_is_link(ht))
+ uri = webkit_hit_test_result_get_link_uri(ht);
+ else if (webkit_hit_test_result_context_is_image(ht))
+ uri = webkit_hit_test_result_get_image_uri(ht);
+ else if (webkit_hit_test_result_context_is_media(ht))
+ uri = webkit_hit_test_result_get_media_uri(ht);
+
+ if (uri != NULL)
+ {
+ webkit_context_menu_append(menu, webkit_context_menu_item_new_separator());
+
+ if (c->external_handler_uri != NULL)
+ g_free(c->external_handler_uri);
+ c->external_handler_uri = g_strdup(uri);
+ action = g_simple_action_new("external_handler", NULL);
+ g_signal_connect(G_OBJECT(action), "activate",
+ G_CALLBACK(external_handler_run), data);
+ mi = webkit_context_menu_item_new_from_gaction(G_ACTION(action),
+ "Open with external handler",
+ NULL);
+ webkit_context_menu_append(menu, mi);
+ g_object_unref(action);
+ }
+
+ /* FALSE = Show the menu. (TRUE = Don't ever show it.) */
+ return FALSE;
+}
+
+gboolean
+quit_if_nothing_active(void)
+{
+ if (clients == 0)
+ {
+ if (downloads == 0)
+ {
+ gtk_main_quit();
+ return TRUE;
+ }
+ else
+ gtk_widget_show_all(dm.win);
+ }
+
+ return FALSE;
+}
+