logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: 862a1e08583d5d48fbb369b3f9bf1d8a6781aefa
parent: 800e9ca61f003983ca69046ebe0d67d83572ef57
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  6 Apr 2019 03:55:04 +0200

Merge branch 'develop'

Diffstat:

Mbadwolf.c36++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -63,6 +63,7 @@ void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data); void closeCb_clicked(GtkButton *close, gpointer user_data); int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser); +gint get_tab_position(GtkContainer *notebook, GtkWidget *child); int main(int argc, char *argv[]); static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data) @@ -70,12 +71,8 @@ static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data) (void)webView; struct Client *browser = (struct Client *)user_data; GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); - GValue position = G_VALUE_INIT; - g_value_init(&position, G_TYPE_INT); - - gtk_container_child_get_property(GTK_CONTAINER(notebook), browser->box, "position", &position); - gtk_notebook_remove_page(notebook, g_value_get_int(&position)); + gtk_notebook_remove_page(notebook, get_tab_position(GTK_CONTAINER(notebook), browser->box)); gtk_widget_destroy(browser->box); @@ -175,6 +172,7 @@ WebViewCb_notify__is__playing__audio(WebKitWebView *webView, GParamSpec *pspec, void webView_tab_label_change(struct Client *browser) { const gchar *title; + GtkWidget *notebook = browser->window->notebook; title = webkit_web_view_get_title(browser->webView); @@ -183,7 +181,11 @@ void webView_tab_label_change(struct Client *browser) if(title == NULL) title = "BadWolf"; gtk_notebook_set_tab_label( - GTK_NOTEBOOK(browser->window->notebook), browser->box, badwolf_new_tab_box(title, browser)); + GTK_NOTEBOOK(notebook), browser->box, badwolf_new_tab_box(title, browser)); + + if(get_tab_position(GTK_CONTAINER(notebook), browser->box) == + gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))) + gtk_window_set_title(GTK_WINDOW(browser->window->main_window), title); } static gboolean WebViewCb_notify__estimated_load_progress(WebKitWebView *webView, @@ -456,6 +458,27 @@ void closeCb_clicked(GtkButton *close, gpointer user_data) webkit_web_view_try_close(browser->webView); } +static void +notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data) +{ + (void)page_num; + struct Window *window = (struct Window *)user_data; + GtkWidget *label = gtk_notebook_get_tab_label(notebook, page); + + // TODO: Maybe find a better way to store the title + gtk_window_set_title(GTK_WINDOW(window->main_window), gtk_widget_get_tooltip_text(label)); +} + +gint get_tab_position(GtkContainer *notebook, GtkWidget *child) +{ + GValue position = G_VALUE_INIT; + g_value_init(&position, G_TYPE_INT); + + gtk_container_child_get_property(notebook, child, "position", &position); + + return g_value_get_int(&position); +} + int main(int argc, char *argv[]) { struct Window *window = g_malloc(sizeof(struct Client)); @@ -497,6 +520,7 @@ int main(int argc, char *argv[]) g_signal_connect(window->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window->new_tab, "clicked", G_CALLBACK(new_tabCb_clicked), window); + g_signal_connect(window->notebook, "switch-page", G_CALLBACK(notebookCb_switch__page), window); gtk_widget_show(window->new_tab); gtk_widget_show_all(window->main_window);