logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: ac614b3dad83a7c29a30c20a034f32a4553b8116
parent: e2bf7bf29ba2452f7a2404b5025c9d1212633017
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 15 Jan 2019 20:43:58 +0100

browser.c: Add tabbing to badwolf [WIP]

Diffstat:

Mbadwolf.c52++++++++++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -6,9 +6,14 @@ #include <gtk/gtk.h> #include <webkit2/webkit2.h> -struct Client +struct Window { GtkWidget *main_window; + GtkWidget *notebook; +}; + +struct Client +{ GtkWidget *box; GtkWidget *toolbar; @@ -18,6 +23,7 @@ struct Client GtkWidget *statusbar; WebKitWebView *webView; + struct Window *window; }; static gboolean WebViewCb_close(WebKitWebView *webView, GtkWidget *window) @@ -78,7 +84,7 @@ WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user if(title == NULL) title = "BadWolf"; - gtk_window_set_title(GTK_WINDOW(browser->main_window), title); + gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(browser->window->notebook), browser->box, title); return TRUE; } @@ -187,16 +193,11 @@ static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user return TRUE; } -int main(int argc, char *argv[]) +struct Client *new_browser(struct Window *window, gchar *target_url) { struct Client *browser = malloc(sizeof(struct Client)); - char *target_url = "about:blank"; - gtk_init(&argc, &argv); - - if(argv[1]) target_url = argv[1]; - - browser->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); browser->location = gtk_entry_new(); @@ -205,8 +206,6 @@ int main(int argc, char *argv[]) browser->statusbar = gtk_label_new(NULL); browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); - gtk_container_add(GTK_CONTAINER(browser->main_window), browser->box); - 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); @@ -225,13 +224,10 @@ int main(int argc, char *argv[]) gtk_entry_set_placeholder_text(GTK_ENTRY(browser->search), "search in current page"); gtk_entry_set_has_frame(GTK_ENTRY(browser->search), FALSE); - g_signal_connect(browser->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); - 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->webView, "close", G_CALLBACK(WebViewCb_close), browser->main_window); g_signal_connect(browser->webView, "web-process-terminated", G_CALLBACK(WebViewCb_web_process_terminated), @@ -269,8 +265,32 @@ int main(int argc, char *argv[]) webkit_web_view_load_uri(browser->webView, target_url); - gtk_widget_grab_focus(GTK_WIDGET(browser->webView)); - gtk_widget_show_all(browser->main_window); + // gtk_widget_grab_focus(GTK_WIDGET(browser->webView)); + + return browser; +} + +int main(int argc, char *argv[]) +{ + struct Window *window = malloc(sizeof(struct Client)); + gchar *target_url = "about:blank"; + struct Client *browser = NULL; + + gtk_init(&argc, &argv); + + if(argv[1]) target_url = argv[1]; + + browser = new_browser(window, target_url); + + window->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + window->notebook = gtk_notebook_new(); + + gtk_container_add(GTK_CONTAINER(window->main_window), window->notebook); + gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), browser->box, NULL); + + g_signal_connect(window->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + + gtk_widget_show_all(window->main_window); gtk_main(); return 0; }