logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: d99a4249b78a0097043618a4ca39453044e42045
parent: e1d8015f772e81538e7dcc9a839e5e3fef1582ca
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 11 Mar 2019 04:19:02 +0100

badwolf.c: Move close-tab button to the toolbar

Diffstat:

Mbadwolf.c32+++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -23,6 +23,7 @@ struct Client GtkWidget *javascript; GtkWidget *location; GtkWidget *search; + GtkWidget *close; GtkWidget *statusbar; WebKitWebView *webView; @@ -43,8 +44,8 @@ static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer u static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data); static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data); struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view); -void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data); -void closeCb_clicked(GtkButton *close, gpointer user_data); +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); int main(int argc, char *argv[]); @@ -94,24 +95,16 @@ static gboolean WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, } GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser) { - GtkWidget *tab_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - GtkWidget *close = gtk_button_new_from_icon_name("window-close", GTK_ICON_SIZE_SMALL_TOOLBAR); + (void)browser; GtkWidget *label = gtk_label_new(title); - gtk_box_pack_start(GTK_BOX(tab_box), label, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(tab_box), close, TRUE, TRUE, 0); - - gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE); - - g_signal_connect(close, "clicked", G_CALLBACK(closeCb_clicked), browser); - 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_show_all(tab_box); + gtk_widget_show_all(label); - return tab_box; + return label; } static gboolean @@ -124,6 +117,8 @@ WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user title = webkit_web_view_get_title(browser->webView); + if(title == NULL) title = webkit_web_view_get_uri(browser->webView); + if(title == NULL) title = "BadWolf"; gtk_notebook_set_tab_label(GTK_NOTEBOOK(browser->window->notebook), browser->box, badwolf_new_tab_box(title, browser)); @@ -260,6 +255,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebVi browser->location = gtk_entry_new(); browser->search = gtk_search_entry_new(); browser->javascript = gtk_check_button_new(); + browser->close = gtk_button_new_from_icon_name("window-close", GTK_ICON_SIZE_SMALL_TOOLBAR); browser->statusbar = gtk_label_new(NULL); if(related_web_view == NULL) { @@ -277,6 +273,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebVi gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->javascript), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->location), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->search), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->close), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->toolbar), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->webView), TRUE, TRUE, 0); @@ -295,6 +292,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebVi g_signal_connect(browser->location, "activate", G_CALLBACK(locationCb_activate), browser); g_signal_connect(browser->javascript, "toggled", G_CALLBACK(javascriptCb_toggled), browser); + g_signal_connect(browser->close, "clicked", G_CALLBACK(closeCb_clicked), browser); g_signal_connect(browser->webView, "web-process-terminated", @@ -370,14 +368,10 @@ void closeCb_clicked(GtkButton *close, gpointer user_data) { (void)close; struct Client *browser = (struct Client *)user_data; - GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); - GValue *position; - - gtk_container_child_get_property(GTK_CONTAINER(notebook), browser->box, "position", position); + GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); - gint *page_pos = (gint *)g_value_peek_pointer(position); + gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook)); - gtk_notebook_remove_page(notebook, *page_pos); free(browser); }