logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: 27c9445f5713ffe04d936785b9dfc5caab0cebcd
parent: 968d5ebfaed8befa83f9d17dc5c7876a66a78922
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  9 Mar 2019 11:25:46 +0100

badwolf.c: Add new-tab Button on Notebook

Diffstat:

Mbadwolf.c19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -10,6 +10,7 @@ struct Window { GtkWidget *main_window; GtkWidget *notebook; + GtkWidget *new_tab; }; struct Client @@ -40,6 +41,7 @@ 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); +void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data); int main(int argc, char *argv[]); static gboolean WebViewCb_close(WebKitWebView *webView, GtkWidget *window) @@ -308,6 +310,18 @@ struct Client *new_browser(struct Window *window, gchar *target_url) return browser; } +void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data) +{ + (void)new_tab; + struct Window *window = (struct Window *)user_data; + struct Client *browser = new_browser(window, NULL); + + gtk_widget_show_all(browser->box); + + gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), browser->box, NULL); + gtk_widget_draw(window->notebook, NULL); +} + int main(int argc, char *argv[]) { struct Window *window = malloc(sizeof(struct Client)); @@ -319,12 +333,17 @@ int main(int argc, char *argv[]) window->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window->notebook = gtk_notebook_new(); + window->new_tab = gtk_button_new_from_icon_name("tab-new", GTK_ICON_SIZE_SMALL_TOOLBAR); + + gtk_notebook_set_action_widget(GTK_NOTEBOOK(window->notebook), window->new_tab, GTK_PACK_END); gtk_container_add(GTK_CONTAINER(window->main_window), window->notebook); gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url)->box, NULL); 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); + gtk_widget_show(window->new_tab); gtk_widget_show_all(window->main_window); gtk_main(); return 0;