logo

badwolf

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

badwolf.c: Append tab on WebKit create signal

Diffstat:

Mbadwolf.c47+++++++++++++++++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -26,6 +26,22 @@ struct Client struct Window *window; }; +static gboolean WebViewCb_close(WebKitWebView *webView, GtkWidget *window); +static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason); +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__estimated_load_progress(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); +static gboolean WebViewCb_mouse_target_changed(WebKitWebView *webView, WebKitHitTestResult *hit, guint modifiers, gpointer user_data); +static WebKitWebView *WebViewCb_create(WebKitWebView *webView, WebKitNavigationAction *navigation_action, gpointer user_data); +static gboolean locationCb_activate(GtkEntry *location, gpointer user_data); +static gboolean javascriptCb_toggled(GtkButton *javascript, gpointer user_data); +static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_data); +static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer user_data); +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); +int main(int argc, char *argv[]); + static gboolean WebViewCb_close(WebKitWebView *webView, GtkWidget *window) { (void)webView; @@ -123,6 +139,23 @@ static gboolean WebViewCb_mouse_target_changed(WebKitWebView *webView, return TRUE; } +static WebKitWebView *WebViewCb_create(WebKitWebView *webView, WebKitNavigationAction *navigation_action, gpointer user_data) +{ + (void)webView; + (void)navigation_action; + struct Window *window = (struct Window *)user_data; + struct Client *browser = new_browser(window, NULL); + + gtk_widget_show_all(browser->box); + + if(gtk_notebook_append_page(GTK_NOTEBOOK(window->notebook), browser->box, NULL) == -1) { + return NULL; + } else { + gtk_widget_draw(window->notebook, NULL); + return browser->webView; + } +} + static gboolean locationCb_activate(GtkEntry *location, gpointer user_data) { const char *target_url; @@ -173,7 +206,8 @@ static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer u return TRUE; } -static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data) { +static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data) +{ struct Client *browser = (struct Client *)user_data; WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); const gchar *search_text = gtk_entry_get_text(GTK_ENTRY(search)); @@ -183,7 +217,8 @@ static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer u return TRUE; } -static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data) { +static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data) +{ (void)search; struct Client *browser = (struct Client *)user_data; WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); @@ -197,6 +232,8 @@ struct Client *new_browser(struct Window *window, gchar *target_url) { struct Client *browser = malloc(sizeof(struct Client)); + if(target_url == NULL) { target_url = "about:blank"; } + browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); @@ -242,6 +279,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url) "notify::estimated-load-progress", G_CALLBACK(WebViewCb_notify__estimated_load_progress), browser); + g_signal_connect(browser->webView, "create", G_CALLBACK(WebViewCb_create), window); g_signal_connect(browser->search, "next-match", G_CALLBACK(SearchEntryCb_next__match), browser); g_signal_connect(browser->search, "previous-match", G_CALLBACK(SearchEntryCb_previous__match), browser); @@ -274,19 +312,16 @@ 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); + 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);