logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: ced6d8f90c54c8d0277b46712384d28839359aa1
parent: 99364d71485e8d2e33d0bf6234c72b79f3a06608
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 11 Mar 2019 09:09:10 +0100

badwolf.c: Add playing icon on tabs

Diffstat:

Mbadwolf.c46+++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -37,6 +37,9 @@ static gboolean WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); static gboolean WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); +static gboolean +WebViewCb_notify__is__playing__audio(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); +void webView_tab_label_change(struct Client *browser); static gboolean WebViewCb_notify__estimated_load_progress(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); @@ -105,17 +108,24 @@ static gboolean WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser) { (void)browser; - GtkWidget *label = gtk_label_new(title); + GtkWidget *tab_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + GtkWidget *label = gtk_label_new(title); + GtkWidget *playing = + gtk_image_new_from_icon_name("media-playback-start-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_label_set_width_chars(GTK_LABEL(label), 25); gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE); gtk_label_set_single_line_mode(GTK_LABEL(label), TRUE); - gtk_widget_set_tooltip_text(label, title); + gtk_box_pack_start(GTK_BOX(tab_box), playing, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(tab_box), label, TRUE, TRUE, 0); + + gtk_widget_set_tooltip_text(tab_box, title); - gtk_widget_show_all(label); + gtk_widget_show_all(tab_box); + gtk_widget_set_visible(playing, webkit_web_view_is_playing_audio(browser->webView)); - return label; + return tab_box; } static gboolean @@ -123,9 +133,29 @@ WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user { (void)webView; (void)pspec; - const gchar *title; struct Client *browser = (struct Client *)user_data; + webView_tab_label_change(browser); + + return TRUE; +} + +static gboolean +WebViewCb_notify__is__playing__audio(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data) +{ + (void)webView; + (void)pspec; + struct Client *browser = (struct Client *)user_data; + + webView_tab_label_change(browser); + + return TRUE; +} + +void webView_tab_label_change(struct Client *browser) +{ + const gchar *title; + title = webkit_web_view_get_title(browser->webView); if(title == NULL) title = webkit_web_view_get_uri(browser->webView); @@ -134,8 +164,6 @@ WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user gtk_notebook_set_tab_label( GTK_NOTEBOOK(browser->window->notebook), browser->box, badwolf_new_tab_box(title, browser)); - - return TRUE; } static gboolean WebViewCb_notify__estimated_load_progress(WebKitWebView *webView, @@ -328,6 +356,10 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web g_signal_connect(browser->webView, "notify::uri", G_CALLBACK(WebViewCb_notify__uri), browser); g_signal_connect(browser->webView, "notify::title", G_CALLBACK(WebViewCb_notify__title), browser); g_signal_connect(browser->webView, + "notify::is-playing-audio", + G_CALLBACK(WebViewCb_notify__is__playing__audio), + browser); + g_signal_connect(browser->webView, "mouse-target-changed", G_CALLBACK(WebViewCb_mouse_target_changed), browser);