From 8806bcb782b2e3e415007441ee37858791dd2ad1 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 26 Apr 2019 20:11:00 +0200 Subject: Hook webView to commonCb_key_press_event --- badwolf.1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 49b7955..b97a01e 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -20,10 +20,22 @@ will probably get added at a later release. .Sh KEYBINDINGS For now it only has the default Webkit/GTK keybindings, which notably are (C for Control, S for Shift): .Bl -width Ds -tag -.It any C-PageUp, any C-PageDown, tabs arrows -When WebView isn't focused (bug to fix) this allows to move from one tab to another. -.It search C-g, search C-S-g +.It any C-PageUp / C-PageDown +Go to the previous/next tab +.It search C-g / C-S-g When the search box is focused it goes to the Next/Previous search term. +.It webview C-F4 +Closes the current tab +.It webview C-S-r / C-r +Reloads the current tab (with/without clearing cache) +.It webview C-f +Focuses on the search entry +.It webview C-l +Focuses on the location(URL) entry +.It webview C-t +Creates a new tab (unrelated, similar as pressing the button) +.It webview C-[ / C-] +Go back/forward in current tab’s history .El .Sh BUGS You can submit contributions or tickets to -- cgit v1.3.1-23-gd82d From 47c494da006c5a034f2cf3b26299c0edf46a840b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 26 Apr 2019 21:09:23 +0200 Subject: Add window-wide keybinds --- badwolf.1 | 2 +- badwolf.c | 67 ++++++++++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 23 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index b97a01e..bc82d74 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -32,7 +32,7 @@ Reloads the current tab (with/without clearing cache) Focuses on the search entry .It webview C-l Focuses on the location(URL) entry -.It webview C-t +.It window C-t, webview C-t Creates a new tab (unrelated, similar as pressing the button) .It webview C-[ / C-] Go back/forward in current tab’s history diff --git a/badwolf.c b/badwolf.c index 10a1ce4..aeca324 100644 --- a/badwolf.c +++ b/badwolf.c @@ -34,9 +34,12 @@ struct Client }; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); -static gboolean commonCb_key_press_event(struct Client *browser, GdkEvent *event); +static gboolean +commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); static gboolean WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data); +static gboolean +main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, gpointer user_data); @@ -90,31 +93,38 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data) } static gboolean -commonCb_key_press_event(struct Client *browser, GdkEvent *event) +commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser) { - GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); + GtkNotebook *notebook = GTK_NOTEBOOK(window->notebook); if(((GdkEventKey *)event)->state & GDK_CONTROL_MASK) { - switch(((GdkEventKey *)event)->keyval) + if(browser != NULL) + { + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_F4: webkit_web_view_try_close(browser->webView); return TRUE; + case GDK_KEY_r: + if(((GdkEventKey *)event)->state & GDK_SHIFT_MASK) + webkit_web_view_reload_bypass_cache(browser->webView); + else + webkit_web_view_reload(browser->webView); + + return TRUE; + case GDK_KEY_f: gtk_widget_grab_focus(browser->search); return TRUE; + case GDK_KEY_l: gtk_widget_grab_focus(browser->location); return TRUE; + case GDK_KEY_bracketleft: webkit_web_view_go_back(browser->webView); return TRUE; + case GDK_KEY_bracketright: webkit_web_view_go_forward(browser->webView); return TRUE; + } + } + else { - case GDK_KEY_F4: webkit_web_view_try_close(browser->webView); return TRUE; - case GDK_KEY_r: - if(((GdkEventKey *)event)->state & GDK_SHIFT_MASK) - webkit_web_view_reload_bypass_cache(browser->webView); - else - webkit_web_view_reload(browser->webView); - - return TRUE; - case GDK_KEY_f: gtk_widget_grab_focus(browser->search); return TRUE; - case GDK_KEY_l: gtk_widget_grab_focus(browser->location); return TRUE; - case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE; - case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE; - case GDK_KEY_t: - badwolf_new_tab(notebook, new_browser(browser->window, NULL, NULL)); - return TRUE; - case GDK_KEY_bracketleft: webkit_web_view_go_back(browser->webView); return TRUE; - case GDK_KEY_bracketright: webkit_web_view_go_forward(browser->webView); return TRUE; + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE; + case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE; + case GDK_KEY_t: badwolf_new_tab(notebook, new_browser(window, NULL, NULL)); return TRUE; + } } } @@ -127,11 +137,21 @@ WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user (void)webView; struct Client *browser = (struct Client *)user_data; - if(commonCb_key_press_event(browser, event)) return TRUE; + if(commonCb_key_press_event(browser->window, event, browser)) return TRUE; return FALSE; } +static gboolean +main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + (void)widget; + struct Window *window = (struct Window *)user_data; + + if(commonCb_key_press_event(window, event, NULL)) return TRUE; + + return FALSE; +} static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, @@ -605,6 +625,9 @@ main(int argc, char *argv[]) badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url, NULL)); + g_signal_connect( + window->main_window, "key-press-event", G_CALLBACK(main_windowCb_key_press_event), window); + 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); -- cgit v1.3.1-23-gd82d From 5d0681c28107c3a18b552f270743940da40808c8 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 26 Apr 2019 21:15:06 +0200 Subject: Hook browser->box to commonCb_key_press_event --- badwolf.1 | 20 ++++++++++---------- badwolf.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index bc82d74..e996fd1 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -22,20 +22,20 @@ For now it only has the default Webkit/GTK keybindings, which notably are (C for .Bl -width Ds -tag .It any C-PageUp / C-PageDown Go to the previous/next tab -.It search C-g / C-S-g -When the search box is focused it goes to the Next/Previous search term. -.It webview C-F4 +.It any C-t +Creates a new tab (unrelated, similar as pressing the button) +.It browser C-F4 Closes the current tab -.It webview C-S-r / C-r -Reloads the current tab (with/without clearing cache) -.It webview C-f +.It browser C-f Focuses on the search entry -.It webview C-l +.It browser C-l Focuses on the location(URL) entry -.It window C-t, webview C-t -Creates a new tab (unrelated, similar as pressing the button) -.It webview C-[ / C-] +.It browser C-S-r / C-r +Reloads the current tab (with/without clearing cache) +.It browser C-[ / C-] Go back/forward in current tab’s history +.It search C-g / C-S-g +When the search box is focused it goes to the Next/Previous search term. .El .Sh BUGS You can submit contributions or tickets to diff --git a/badwolf.c b/badwolf.c index aeca324..1fef34e 100644 --- a/badwolf.c +++ b/badwolf.c @@ -40,6 +40,7 @@ static gboolean WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data); static gboolean main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); +static gboolean boxCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, gpointer user_data); @@ -142,6 +143,17 @@ WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user return FALSE; } +static gboolean +boxCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + (void)widget; + struct Client *browser = (struct Client *)user_data; + + if(commonCb_key_press_event(browser->window, event, browser)) return TRUE; + + return FALSE; +} + static gboolean main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { @@ -513,6 +525,8 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web browser->search, "search-changed", G_CALLBACK(SearchEntryCb_search__changed), browser); g_signal_connect(browser->search, "stop-search", G_CALLBACK(SearchEntryCb_stop__search), browser); + g_signal_connect(browser->box, "key-press-event", G_CALLBACK(boxCb_key_press_event), browser); + if(related_web_view == NULL) webkit_web_view_load_uri(browser->webView, target_url); return browser; -- cgit v1.3.1-23-gd82d From 9c5a0d2b96d928364621cdd6eec7b93b10afec7c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 9 Apr 2019 15:11:22 +0200 Subject: badwolf.c: Add zoom on ctrl+scroll --- badwolf.1 | 10 +++++++++- badwolf.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index e996fd1..76dab96 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -18,7 +18,15 @@ Runtime configuration specific to .Nm will probably get added at a later release. .Sh KEYBINDINGS -For now it only has the default Webkit/GTK keybindings, which notably are (C for Control, S for Shift): +The following section lists the keybinding by their action, each item is described by the widget the focus is on or +.Aq any +if it works for the whole window, followed by the keybind it grabs. C is short for Control, S is short for Shift. +.Bl -width Ds -tag +.It webview C-Scroll +Zooms the webpage in/out. +.El +.Ss DEFAULT ONES +Here is a incomplete list of the default Webkit/GTK keybindings: .Bl -width Ds -tag .It any C-PageUp / C-PageDown Go to the previous/next tab diff --git a/badwolf.c b/badwolf.c index 1fef34e..e8cd46a 100644 --- a/badwolf.c +++ b/badwolf.c @@ -322,6 +322,26 @@ WebViewCb_mouse_target_changed(WebKitWebView *webView, return TRUE; } +static gboolean +WebViewCb_scroll_event(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + (void)widget; + struct Client *browser = (struct Client *)data; + gdouble delta_x, delta_y; + gfloat zoom; + + if(((GdkEventScroll *)event)->state & GDK_CONTROL_MASK) + { + gdk_event_get_scroll_deltas(event, &delta_x, &delta_y); + zoom = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(browser->webView)); + zoom -= delta_y * 0.1; + webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(browser->webView), zoom); + return TRUE; + } + + return FALSE; +} + static WebKitWebView * WebViewCb_create(WebKitWebView *related_web_view, WebKitNavigationAction *navigation_action, @@ -517,6 +537,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web g_signal_connect(browser->webView, "close", G_CALLBACK(WebViewCb_close), browser); g_signal_connect( browser->webView, "key-press-event", G_CALLBACK(WebViewCb_key_press_event), browser); + g_signal_connect(browser->webView, "scroll-event", G_CALLBACK(WebViewCb_scroll_event), browser); g_signal_connect(browser->search, "next-match", G_CALLBACK(SearchEntryCb_next__match), browser); g_signal_connect( -- cgit v1.3.1-23-gd82d From f57a127d718c116f0e11cb543fbcad2359df9c86 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 13 Apr 2019 20:57:35 +0200 Subject: badwolf.1: Add "search Escape" default binding --- badwolf.1 | 2 ++ 1 file changed, 2 insertions(+) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 76dab96..f039518 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -44,6 +44,8 @@ Reloads the current tab (with/without clearing cache) Go back/forward in current tab’s history .It search C-g / C-S-g When the search box is focused it goes to the Next/Previous search term. +.It search Escape +Cancels current search .El .Sh BUGS You can submit contributions or tickets to -- cgit v1.3.1-23-gd82d From 3ba43be13812acf9b8d12186d74468cd0e295b79 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 11 May 2019 07:57:07 +0200 Subject: Add a simple way to fix the URL It tries to load it as a file before trying a URL to avoid loading something meant as local. Closes: https://gitlab.com/lanodan/badWolf/issues/6 --- Makefile | 2 +- badwolf.1 | 2 +- badwolf.c | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'badwolf.1') diff --git a/Makefile b/Makefile index 74ddedd..7bd30db 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ TRANS = fr.mo CC = cc CFLAGS = -g -Wall -Wextra -CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" +CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_DEFAULT_SOURCE LIBS = `pkg-config --libs $(DEPS)` all: $(OBJS) $(TRANS) diff --git a/badwolf.1 b/badwolf.1 index f039518..0d0d75a 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -9,7 +9,7 @@ .Sh SYNOPSIS .Nm .Op Ar webkit/gtk options -.Op Ar url +.Op Ar url or path .Sh DESCRIPTION .Nm is a minimalist browser that care about privacy, it is based on WebKitGTK and thus also accepts WebKitGTK (and depdendencies) flags and environment variables, unfortunately there doesn't seems to be manpages for theses. diff --git a/badwolf.c b/badwolf.c index 1cdaab6..abc0fef 100644 --- a/badwolf.c +++ b/badwolf.c @@ -8,6 +8,7 @@ #include /* g_fprintf() */ #include #include /* LC_* */ +#include /* realpath() */ #include const gchar *homepage = "https://hacktivis.me/projects/badwolf"; @@ -36,6 +37,7 @@ struct Client GtkWidget *search; }; +gchar *ensure_uri_scheme(gchar *text); static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); static gboolean commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); @@ -80,6 +82,33 @@ static void notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data); gint get_tab_position(GtkContainer *notebook, GtkWidget *child); +gchar * +ensure_uri_scheme(gchar *text) +{ + if(text == NULL) return "about:blank"; + + char *scheme = g_uri_parse_scheme(text); + + if(scheme != NULL) + return text; + else + { + gchar *f; + char *path; + path = realpath(text, NULL); + + if(path != NULL) + { + f = g_strdup_printf("file://%s", path); + free(path); + } + else + f = g_strdup_printf("http://%s", text); + + return f; + } +} + static void badwolf_about_dialog(GtkWindow *main_window) { @@ -425,10 +454,10 @@ WebViewCb_create(WebKitWebView *related_web_view, static gboolean locationCb_activate(GtkEntry *location, gpointer user_data) { - const char *target_url; + char *target_url; struct Client *browser = (struct Client *)user_data; - target_url = gtk_entry_get_text(location); + target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location)); if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url); @@ -502,7 +531,7 @@ struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view) { struct Client *browser = g_malloc(sizeof(struct Client)); - if(target_url == NULL) target_url = "about:blank"; + target_url = ensure_uri_scheme(target_url); browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); -- cgit v1.3.1-23-gd82d From 346048a59fad3f6bfd2e3be4d821a8d89612b2d1 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 12 May 2019 05:48:58 +0200 Subject: badwolf.1: Fix history nav and default keybinds --- badwolf.1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 0d0d75a..1c7c739 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -24,12 +24,6 @@ if it works for the whole window, followed by the keybind it grabs. C is short f .Bl -width Ds -tag .It webview C-Scroll Zooms the webpage in/out. -.El -.Ss DEFAULT ONES -Here is a incomplete list of the default Webkit/GTK keybindings: -.Bl -width Ds -tag -.It any C-PageUp / C-PageDown -Go to the previous/next tab .It any C-t Creates a new tab (unrelated, similar as pressing the button) .It browser C-F4 @@ -40,8 +34,14 @@ Focuses on the search entry Focuses on the location(URL) entry .It browser C-S-r / C-r Reloads the current tab (with/without clearing cache) -.It browser C-[ / C-] +.It browser Alt-[ / C-] Go back/forward in current tab’s history +.El +.Ss DEFAULT ONES +Here is a incomplete list of the default Webkit/GTK keybindings: +.Bl -width Ds -tag +.It any C-PageUp / C-PageDown +Go to the previous/next tab .It search C-g / C-S-g When the search box is focused it goes to the Next/Previous search term. .It search Escape -- cgit v1.3.1-23-gd82d From fb531698c4e5f3c0c2f7a9151222ba8aaa6bd1e7 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 13 May 2019 10:42:01 +0200 Subject: badwolf.1: Reword C-t session bit --- badwolf.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'badwolf.1') diff --git a/badwolf.1 b/badwolf.1 index 1c7c739..54ce1ac 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -25,7 +25,7 @@ if it works for the whole window, followed by the keybind it grabs. C is short f .It webview C-Scroll Zooms the webpage in/out. .It any C-t -Creates a new tab (unrelated, similar as pressing the button) +Creates a new tab (in a new session, similar as pressing the button) .It browser C-F4 Closes the current tab .It browser C-f -- cgit v1.3.1-23-gd82d