X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=browser.c;h=76dcd8e1593bcf280d80c242f341e46331694f9a;hb=b42281984353ef004f759191d70522e94fbc2c42;hp=48ff8485e59782917889be1403d74c745ea2f388;hpb=fe194143ed6db650936baa3313bc1061a38049f5;p=chorizo.git diff --git a/browser.c b/browser.c index 48ff848..76dcd8e 100644 --- a/browser.c +++ b/browser.c @@ -22,6 +22,7 @@ static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction static void cooperation_setup(void); static void changed_download_progress(GObject *, GParamSpec *, gpointer); static void changed_load_progress(GObject *, GParamSpec *, gpointer); +static void changed_favicon(GObject *, GParamSpec *, gpointer); static void changed_title(GObject *, GParamSpec *, gpointer); static void changed_uri(GObject *, GParamSpec *, gpointer); static gboolean crashed_web_view(WebKitWebView *, gpointer); @@ -63,6 +64,7 @@ struct Client gchar *hover_uri; gchar *feed_html; GtkWidget *location; + GtkWidget *tabicon; GtkWidget *tablabel; GtkWidget *vbox; GtkWidget *web_view; @@ -97,6 +99,7 @@ static gboolean initial_wc_setup_done = FALSE; static GHashTable *keywords = NULL; static gchar *search_text = NULL; static GtkPositionType tab_pos = GTK_POS_TOP; +static gint tab_width_chars = 20; static gchar *user_agent = NULL; @@ -142,7 +145,7 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show) struct Client *c; WebKitWebContext *wc; gchar *f; - GtkWidget *evbox; + GtkWidget *evbox, *tabbox; if (uri != NULL && cooperative_instances && !cooperative_alone) { @@ -167,6 +170,8 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show) wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view)); webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom); + g_signal_connect(G_OBJECT(c->web_view), "notify::favicon", + G_CALLBACK(changed_favicon), c); g_signal_connect(G_OBJECT(c->web_view), "notify::title", G_CALLBACK(changed_title), c); g_signal_connect(G_OBJECT(c->web_view), "notify::uri", @@ -202,6 +207,8 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show) trust_user_certs(wc); + webkit_web_context_set_favicon_database_directory(wc, NULL); + initial_wc_setup_done = TRUE; } @@ -232,12 +239,21 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show) gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0); + c->tabicon = gtk_image_new_from_icon_name("text-html", GTK_ICON_SIZE_SMALL_TOOLBAR); + c->tablabel = gtk_label_new(__NAME__); gtk_label_set_ellipsize(GTK_LABEL(c->tablabel), PANGO_ELLIPSIZE_END); - gtk_label_set_width_chars(GTK_LABEL(c->tablabel), 20); + gtk_label_set_width_chars(GTK_LABEL(c->tablabel), tab_width_chars); + + /* XXX I don't own a HiDPI screen, so I don't know if scale_factor + * does the right thing. */ + tabbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, + 5 * gtk_widget_get_scale_factor(mw.win)); + gtk_box_pack_start(GTK_BOX(tabbox), c->tabicon, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(tabbox), c->tablabel, TRUE, TRUE, 0); evbox = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(evbox), c->tablabel); + gtk_container_add(GTK_CONTAINER(evbox), tabbox); g_signal_connect(G_OBJECT(evbox), "button-release-event", G_CALLBACK(button_tablabel), c); @@ -392,6 +408,34 @@ changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data) gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), p); } +void +changed_favicon(GObject *obj, GParamSpec *pspec, gpointer data) +{ + struct Client *c = (struct Client *)data; + cairo_surface_t *f; + int w, h, w_should, h_should; + GdkPixbuf *pb, *pb_scaled; + + f = webkit_web_view_get_favicon(WEBKIT_WEB_VIEW(c->web_view)); + if (f != NULL) + { + w = cairo_image_surface_get_width(f); + h = cairo_image_surface_get_height(f); + pb = gdk_pixbuf_get_from_surface(f, 0, 0, w, h); + if (pb != NULL) + { + w_should = 16 * gtk_widget_get_scale_factor(c->tabicon); + h_should = 16 * gtk_widget_get_scale_factor(c->tabicon); + pb_scaled = gdk_pixbuf_scale_simple(pb, w_should, h_should, + GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf(GTK_IMAGE(c->tabicon), pb_scaled); + + g_object_unref(pb_scaled); + g_object_unref(pb); + } + } +} + void changed_title(GObject *obj, GParamSpec *pspec, gpointer data) { @@ -690,6 +734,10 @@ grab_environment_configuration(void) tab_pos = GTK_POS_LEFT; } + e = g_getenv(__NAME_UPPERCASE__"_TAB_WIDTH_CHARS"); + if (e != NULL) + tab_width_chars = atoi(e); + e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT"); if (e != NULL) user_agent = g_strdup(e); @@ -1110,10 +1158,13 @@ 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, *evbox, *label; + GtkWidget *child, *tabbox, *evbox, *label; + GList *tabbox_children, *last; const gchar *text; if (idx == -1) @@ -1128,9 +1179,13 @@ mainwindow_title(gint idx) return; evbox = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child); - label = gtk_bin_get_child(GTK_BIN(evbox)); + 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