From 71b8af9d8c050ae6a78b76faf118751e2dd5607a Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 2 Jul 2019 03:12:41 +0200 Subject: Prevent the statusbar label from resizing the window --- badwolf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 6677d99..9781d31 100644 --- a/badwolf.c +++ b/badwolf.c @@ -735,6 +735,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web gtk_widget_set_halign(browser->statusbar, GTK_ALIGN_START); gtk_label_set_single_line_mode(GTK_LABEL(browser->statuslabel), TRUE); + gtk_label_set_ellipsize(GTK_LABEL(browser->statuslabel), BADWOLF_STATUSLABEL_ELLIPSIZE); gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); gtk_entry_set_has_frame(GTK_ENTRY(browser->location), FALSE); -- cgit v1.3.1-23-gd82d From 8d79761a448e8b6391f4b348630017516aa07ab8 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 6 Jul 2019 13:50:28 +0200 Subject: Add toggling of caret browsing on F7 --- badwolf.1 | 2 ++ badwolf.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) (limited to 'badwolf.c') diff --git a/badwolf.1 b/badwolf.1 index 33b86c0..d2014a2 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -36,6 +36,8 @@ Focuses on the search entry Focuses on the location(URL) entry .It browser C-S-r / C-r, browser F5 Reloads the current tab (with/without clearing cache) +.It browser F7 +Toggles caret browsing. .It browser C-[ / C-] Go back/forward in current tab’s history .It any A-Left / A-Right diff --git a/badwolf.c b/badwolf.c index 9781d31..8b4f289 100644 --- a/badwolf.c +++ b/badwolf.c @@ -165,6 +165,17 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data) return TRUE; } +static void +toggle_caret_browsing(WebKitWebView *webView) +{ + WebKitSettings *settings = webkit_web_view_get_settings(webView); + + webkit_settings_set_enable_caret_browsing(settings, + !webkit_settings_get_enable_caret_browsing(settings)); + + webkit_web_view_set_settings(webView, settings); +} + /* commonCb_key_press_event: Global callback for keybindings * * Theses shortcuts should be avoided as much as possible: @@ -236,6 +247,7 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client * switch(((GdkEventKey *)event)->keyval) { case GDK_KEY_F5: webkit_web_view_reload(browser->webView); return TRUE; + case GDK_KEY_F7: toggle_caret_browsing(browser->webView); return TRUE; } } else -- cgit v1.3.1-23-gd82d From aa9d7cd7abb1c1bb2afab376194614ef0c5c9b6e Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 6 Jul 2019 14:21:41 +0200 Subject: Bind F12 to opening Web Inspector --- badwolf.1 | 2 ++ badwolf.c | 3 +++ 2 files changed, 5 insertions(+) (limited to 'badwolf.c') diff --git a/badwolf.1 b/badwolf.1 index d2014a2..8f13795 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -38,6 +38,8 @@ Focuses on the location(URL) entry Reloads the current tab (with/without clearing cache) .It browser F7 Toggles caret browsing. +.It browser F12 +Opens the web inspector. .It browser C-[ / C-] Go back/forward in current tab’s history .It any A-Left / A-Right diff --git a/badwolf.c b/badwolf.c index 8b4f289..5ea0e5b 100644 --- a/badwolf.c +++ b/badwolf.c @@ -248,6 +248,9 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client * { case GDK_KEY_F5: webkit_web_view_reload(browser->webView); return TRUE; case GDK_KEY_F7: toggle_caret_browsing(browser->webView); return TRUE; + case GDK_KEY_F12: + webkit_web_inspector_show(webkit_web_view_get_inspector(browser->webView)); + return TRUE; } } else -- cgit v1.3.1-23-gd82d From 2216742794e48bda3898813acbb9e1d68d38b241 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 6 Jul 2019 14:39:30 +0200 Subject: Move non-static definitions to badwolf.h, with proper namespacing --- badwolf.c | 62 +++++++++++--------------------------------------------------- badwolf.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 51 deletions(-) create mode 100644 badwolf.h (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 5ea0e5b..a9c4b67 100644 --- a/badwolf.c +++ b/badwolf.c @@ -2,42 +2,18 @@ // Copyright © 2019 Haelwenn (lanodan) Monnier // SPDX-License-Identifier: BSD-3-Clause +#include "badwolf.h" + #include "config.h" #include /* _() and other internationalization/localization helpers */ #include /* g_fprintf() */ -#include -#include /* LC_* */ -#include /* realpath(), malloc() */ -#include +#include /* LC_* */ +#include /* realpath(), malloc() */ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; const gchar *version = "0.3.0"; -struct Window -{ - GtkWidget *main_window; - GtkWidget *notebook; - GtkWidget *new_tab; -}; - -struct Client -{ - GtkWidget *box; - - GtkWidget *toolbar; - GtkWidget *javascript; - GtkWidget *location; - - WebKitWebView *webView; - struct Window *window; - - GtkWidget *statusbar; - GtkWidget *statuslabel; - GtkWidget *search; -}; - -gchar *ensure_uri_scheme(gchar *text, gboolean try_file); static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); static gboolean commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); @@ -51,12 +27,10 @@ static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, gpointer user_data); static gboolean WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); -GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser); static gboolean WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); static gboolean WebViewCb_notify__is__playing__audio(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); -void webView_tab_label_change(struct Client *browser, const gchar *title); static gboolean WebViewCb_notify__estimated_load_progress(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data); @@ -86,28 +60,13 @@ static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_ 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, WebKitWebView *related_web_view); -int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); static void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data); static void closeCb_clicked(GtkButton *close, gpointer user_data); static void notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data); -gint get_tab_position(GtkContainer *notebook, GtkWidget *child); -/* ensure_uri_scheme: tries to add a scheme on a pseudo-URL missing a scheme - * - gchar text: pseudo-URL missing a scheme - * - gboolean try_file: when TRUE check try first if it can be a file:// path - * - * When `text` isn't exploitable (ie. NULL), returns "about:blank", - * when the URL seems to be valid, return it, - * if try_file is TRUE, check if it can be file:// path, - * some other checks might be added. - * In the end use the fallback (`http://` for now, might get configuration), - * might get some safeguard. - */ gchar * -ensure_uri_scheme(gchar *text, gboolean try_file) +badwolf_ensure_uri_scheme(gchar *text, gboolean try_file) { if(text == NULL) return "about:blank"; @@ -156,7 +115,8 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data) struct Client *browser = (struct Client *)user_data; GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); - gtk_notebook_remove_page(notebook, get_tab_position(GTK_CONTAINER(notebook), browser->box)); + gtk_notebook_remove_page(notebook, + badwolf_get_tab_position(GTK_CONTAINER(notebook), browser->box)); gtk_widget_destroy(browser->box); @@ -420,7 +380,7 @@ webView_tab_label_change(struct Client *browser, const gchar *title) gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(notebook), browser->box, title); // Set the window title if the title change was on the current tab - if(get_tab_position(GTK_CONTAINER(notebook), browser->box) == + if(badwolf_get_tab_position(GTK_CONTAINER(notebook), browser->box) == gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))) gtk_window_set_title(GTK_WINDOW(browser->window->main_window), title); } @@ -600,7 +560,7 @@ locationCb_activate(GtkEntry *location, gpointer user_data) char *target_url; struct Client *browser = (struct Client *)user_data; - target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location), TRUE); + target_url = badwolf_ensure_uri_scheme((char *)gtk_entry_get_text(location), TRUE); if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url); @@ -674,7 +634,7 @@ struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view) { struct Client *browser = malloc(sizeof(struct Client)); - target_url = ensure_uri_scheme(target_url, (related_web_view == NULL)); + target_url = badwolf_ensure_uri_scheme(target_url, (related_web_view == NULL)); char *badwolf_l10n = NULL; if(browser == NULL) return NULL; @@ -877,7 +837,7 @@ notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, } gint -get_tab_position(GtkContainer *notebook, GtkWidget *child) +badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child) { GValue position = G_VALUE_INIT; g_value_init(&position, G_TYPE_INT); diff --git a/badwolf.h b/badwolf.h new file mode 100644 index 0000000..e50f5f5 --- /dev/null +++ b/badwolf.h @@ -0,0 +1,44 @@ +#include +#include + +struct Window +{ + GtkWidget *main_window; + GtkWidget *notebook; + GtkWidget *new_tab; +}; + +struct Client +{ + GtkWidget *box; + + GtkWidget *toolbar; + GtkWidget *javascript; + GtkWidget *location; + + WebKitWebView *webView; + struct Window *window; + + GtkWidget *statusbar; + GtkWidget *statuslabel; + GtkWidget *search; +}; + +/* badwolf_ensure_uri_scheme: tries to add a scheme on a pseudo-URL missing a scheme + * - gchar text: pseudo-URL missing a scheme + * - gboolean try_file: when TRUE check try first if it can be a file:// path + * + * When `text` isn't exploitable (ie. NULL), returns "about:blank", + * when the URL seems to be valid, return it, + * if try_file is TRUE, check if it can be file:// path, + * some other checks might be added. + * In the end use the fallback (`http://` for now, might get configuration), + * might get some safeguard. + */ +gchar *badwolf_ensure_uri_scheme(gchar *text, gboolean try_file); +GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser); +void webView_tab_label_change(struct Client *browser, const gchar *title); +struct Client * +new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view); +int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); +gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child); -- cgit v1.3.1-23-gd82d From 4d30c11f4c7ff59805c770ca972a24088c9f2604 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 6 Jul 2019 15:53:06 +0200 Subject: Move keybindings to a separate file --- Makefile | 15 ++++-- badwolf.c | 156 +--------------------------------------------------------- badwolf.h | 7 +++ config.h | 4 ++ keybindings.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ keybindings.h | 12 +++++ 6 files changed, 187 insertions(+), 159 deletions(-) create mode 100644 keybindings.c create mode 100644 keybindings.h (limited to 'badwolf.c') diff --git a/Makefile b/Makefile index 095024d..89cbf0c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ DATADIR = $(PREFIX)/share/badwolf PACKAGE = Badwolf DEPS = gtk+-3.0 webkit2gtk-4.0 -OBJS = badwolf +OBJS = keybindings.o +EXE = badwolf TRANS = fr.mo CC = cc @@ -15,7 +16,7 @@ CFLAGS = -g -Wall -Wextra -Wconversion -Wsign-conversion CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_DEFAULT_SOURCE LIBS = `pkg-config --libs $(DEPS)` -all: $(OBJS) $(TRANS) +all: $(EXE) $(TRANS) po/messages.pot: badwolf.c xgettext --keyword=_ --language=C -o $@ --add-comments --sort-output -j badwolf.c @@ -27,8 +28,14 @@ ${TRANS}: po/${@:.mo=.po} mkdir -p locale/${@:.mo=}/LC_MESSAGES msgfmt -o locale/${@:.mo=}/LC_MESSAGES/$(PACKAGE).mo po/${@:.mo=.po} +${EXE}: $(OBJS) + $(CC) -std=c11 $(CFLAGS) $(CDEPS) $(LDFLAGS) $(LIBS) -o $@ $(OBJS) $@.c + .c: - $(CC) -std=c11 $(CFLAGS) $(CDEPS) -o $@ $< $(LDFLAGS) $(LIBS) + $(CC) -std=c11 $(CFLAGS) $(CDEPS) $(LDFLAGS) $(LIBS) -o $@ $< + +.c.o: + $(CC) -std=c11 $(CFLAGS) $(CDEPS) $(LDFLAGS) $(LIBS) -c -o $@ $< install: all mkdir -p $(DESTDIR)$(BINDIR) @@ -39,7 +46,7 @@ install: all cp -r locale/ $(DESTDIR)$(DATADIR) clean: - rm -fr locale $(OBJS) + rm -fr locale $(OBJS) $(EXE) format: *.c *.h clang-format -style=file -assume-filename=.clang-format -i *.c *.h diff --git a/badwolf.c b/badwolf.c index a9c4b67..a48d324 100644 --- a/badwolf.c +++ b/badwolf.c @@ -5,6 +5,7 @@ #include "badwolf.h" #include "config.h" +#include "keybindings.h" #include /* _() and other internationalization/localization helpers */ #include /* g_fprintf() */ @@ -15,13 +16,6 @@ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; const gchar *version = "0.3.0"; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); -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 boxCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, gpointer user_data); @@ -91,23 +85,6 @@ badwolf_ensure_uri_scheme(gchar *text, gboolean try_file) return g_strdup_printf("http://%s", text); } -static void -badwolf_about_dialog(GtkWindow *main_window) -{ - // clang-format off - gtk_show_about_dialog( - main_window, - "license", "SPDX-License-Identifier: BSD-3-Clause", - "copyright", "2019 Haelwenn (lanodan) Monnier ", - "website", homepage, - "comments", "Minimalist and privacy-oriented WebKitGTK+ browser", - "version", version, - //FIXME: "logo-icon-name", g_get_application_name(), - NULL - ); - // clang-format on -} - static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data) { @@ -125,137 +102,6 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data) return TRUE; } -static void -toggle_caret_browsing(WebKitWebView *webView) -{ - WebKitSettings *settings = webkit_web_view_get_settings(webView); - - webkit_settings_set_enable_caret_browsing(settings, - !webkit_settings_get_enable_caret_browsing(settings)); - - webkit_web_view_set_settings(webView, settings); -} - -/* commonCb_key_press_event: Global callback for keybindings - * - * Theses shortcuts should be avoided as much as possible: - * - Single key shortcuts (ie. backspace and space) - * - Triple key shortcuts (except for Ctrl+Shift) - * - Unix Terminal shortcuts (specially Ctrl-W) - * - * loosely follows https://developer.gnome.org/hig/stable/keyboard-input.html - */ -static gboolean -commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser) -{ - GtkNotebook *notebook = GTK_NOTEBOOK(window->notebook); - - if(((GdkEventKey *)event)->state & GDK_CONTROL_MASK) - { - 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; - case GDK_KEY_0: - webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(browser->webView), 1); - return TRUE; - } - } - else - { - 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; - } - } - } - - if((((GdkEventKey *)event)->state & GDK_MOD1_MASK)) - { - if((browser != NULL) && (((GdkEventKey *)event)->keyval == GDK_KEY_d)) - { - webkit_web_view_try_close(browser->webView); - return TRUE; - } - - switch(((GdkEventKey *)event)->keyval) - { - case GDK_KEY_Left: gtk_notebook_prev_page(notebook); return TRUE; - case GDK_KEY_Right: gtk_notebook_next_page(notebook); return TRUE; - } - if((((GdkEventKey *)event)->keyval >= GDK_KEY_0) && - (((GdkEventKey *)event)->keyval <= GDK_KEY_9)) - gtk_notebook_set_current_page(notebook, (gint)(((GdkEventKey *)event)->keyval - GDK_KEY_1)); - } - - if(browser != NULL) - { - switch(((GdkEventKey *)event)->keyval) - { - case GDK_KEY_F5: webkit_web_view_reload(browser->webView); return TRUE; - case GDK_KEY_F7: toggle_caret_browsing(browser->webView); return TRUE; - case GDK_KEY_F12: - webkit_web_inspector_show(webkit_web_view_get_inspector(browser->webView)); - return TRUE; - } - } - else - { - switch(((GdkEventKey *)event)->keyval) - { - case GDK_KEY_F1: badwolf_about_dialog(GTK_WINDOW(window->main_window)); return TRUE; - } - } - - return FALSE; -} - -static gboolean -WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data) -{ - (void)webView; - struct Client *browser = (struct Client *)user_data; - - if(commonCb_key_press_event(browser->window, event, browser)) return TRUE; - - 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) -{ - (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, diff --git a/badwolf.h b/badwolf.h index e50f5f5..4c9fa65 100644 --- a/badwolf.h +++ b/badwolf.h @@ -1,6 +1,12 @@ +#ifndef BADWOLF_H_INCLUDED +#define BADWOLF_H_INCLUDED + #include #include +const gchar *homepage; +const gchar *version; + struct Window { GtkWidget *main_window; @@ -42,3 +48,4 @@ struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view); int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser); gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child); +#endif /* BADWOLF_H_INCLUDED */ diff --git a/config.h b/config.h index f1fe00e..df9e004 100644 --- a/config.h +++ b/config.h @@ -1,3 +1,5 @@ +#ifndef CONFIG_H_INCLUDED +#define CONFIG_H_INCLUDED /* BADWOLF_TAB_POSITION: Position of the tab listing, can be one of: * - GTK_POS_TOP * - GTK_POS_BOTTOM @@ -79,3 +81,5 @@ * See https://developer.gnome.org/pango/stable/pango-Layout-Objects.html#PangoEllipsizeMode */ #define BADWOLF_STATUSLABEL_ELLIPSIZE PANGO_ELLIPSIZE_MIDDLE + +#endif /* CONFIG_H_INCLUDED */ diff --git a/keybindings.c b/keybindings.c new file mode 100644 index 0000000..d75a438 --- /dev/null +++ b/keybindings.c @@ -0,0 +1,152 @@ +#include "keybindings.h" + +#include "badwolf.h" + +static void +badwolf_about_dialog(GtkWindow *main_window) +{ + // clang-format off + gtk_show_about_dialog( + main_window, + "license", "SPDX-License-Identifier: BSD-3-Clause", + "copyright", "2019 Haelwenn (lanodan) Monnier ", + "website", homepage, + "comments", "Minimalist and privacy-oriented WebKitGTK+ browser", + "version", version, + //FIXME: "logo-icon-name", g_get_application_name(), + NULL + ); + // clang-format on +} + +static void +toggle_caret_browsing(WebKitWebView *webView) +{ + WebKitSettings *settings = webkit_web_view_get_settings(webView); + + webkit_settings_set_enable_caret_browsing(settings, + !webkit_settings_get_enable_caret_browsing(settings)); + + webkit_web_view_set_settings(webView, settings); +} + +/* commonCb_key_press_event: Global callback for keybindings + * + * Theses shortcuts should be avoided as much as possible: + * - Single key shortcuts (ie. backspace and space) + * - Triple key shortcuts (except for Ctrl+Shift) + * - Unix Terminal shortcuts (specially Ctrl-W) + * + * loosely follows https://developer.gnome.org/hig/stable/keyboard-input.html + */ +gboolean +commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser) +{ + GtkNotebook *notebook = GTK_NOTEBOOK(window->notebook); + + if(((GdkEventKey *)event)->state & GDK_CONTROL_MASK) + { + 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; + case GDK_KEY_0: + webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(browser->webView), 1); + return TRUE; + } + } + else + { + 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; + } + } + } + + if((((GdkEventKey *)event)->state & GDK_MOD1_MASK)) + { + if((browser != NULL) && (((GdkEventKey *)event)->keyval == GDK_KEY_d)) + { + webkit_web_view_try_close(browser->webView); + return TRUE; + } + + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_Left: gtk_notebook_prev_page(notebook); return TRUE; + case GDK_KEY_Right: gtk_notebook_next_page(notebook); return TRUE; + } + if((((GdkEventKey *)event)->keyval >= GDK_KEY_0) && + (((GdkEventKey *)event)->keyval <= GDK_KEY_9)) + gtk_notebook_set_current_page(notebook, (gint)(((GdkEventKey *)event)->keyval - GDK_KEY_1)); + } + + if(browser != NULL) + { + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_F5: webkit_web_view_reload(browser->webView); return TRUE; + case GDK_KEY_F7: toggle_caret_browsing(browser->webView); return TRUE; + case GDK_KEY_F12: + webkit_web_inspector_show(webkit_web_view_get_inspector(browser->webView)); + return TRUE; + } + } + else + { + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_F1: badwolf_about_dialog(GTK_WINDOW(window->main_window)); return TRUE; + } + } + + return FALSE; +} + +gboolean +WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data) +{ + (void)webView; + struct Client *browser = (struct Client *)user_data; + + if(commonCb_key_press_event(browser->window, event, browser)) return TRUE; + + return FALSE; +} + +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; +} + +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; +} diff --git a/keybindings.h b/keybindings.h new file mode 100644 index 0000000..e7d1d6b --- /dev/null +++ b/keybindings.h @@ -0,0 +1,12 @@ +#ifndef KEYBINDINGS_H_INCLUDED +#define KEYBINDINGS_H_INCLUDED +#include "badwolf.h" + +#include +#include + +gboolean boxCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); +gboolean commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); +gboolean main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); +gboolean WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data); +#endif /* KEYBINDINGS_H_INCLUDED */ -- cgit v1.3.1-23-gd82d From f2fd43fd7335ceb6acdfd3f7483be616ae611406 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 18 Jul 2019 10:40:26 +0200 Subject: Sync javascript toggle button with default settings --- badwolf.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 5ea0e5b..2919780 100644 --- a/badwolf.c +++ b/badwolf.c @@ -706,6 +706,9 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web WebKitSettings *settings = webkit_settings_new_with_settings(BADWOLF_WEBKIT_SETTINGS); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(browser->javascript), + webkit_settings_get_enable_javascript(settings)); + browser->webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", web_context, -- cgit v1.3.1-23-gd82d From 768ad801aaac4012b94131f00040e3b9dc629773 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 23 Jul 2019 13:12:49 +0200 Subject: Add the git hash in the version when possible --- Makefile | 2 +- badwolf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'badwolf.c') diff --git a/Makefile b/Makefile index 89cbf0c..bf27740 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ TRANS = fr.mo CC = cc CFLAGS = -g -Wall -Wextra -Wconversion -Wsign-conversion -CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_DEFAULT_SOURCE +CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_DEFAULT_SOURCE -DVERSION="$(shell ./version.sh)" LIBS = `pkg-config --libs $(DEPS)` all: $(EXE) $(TRANS) diff --git a/badwolf.c b/badwolf.c index f338b47..ca1b302 100644 --- a/badwolf.c +++ b/badwolf.c @@ -13,7 +13,7 @@ #include /* realpath(), malloc() */ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; -const gchar *version = "0.3.0"; +const gchar *version = VERSION; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, -- cgit v1.3.1-23-gd82d From 1026413b3f2ca3ebb0f2604ef34b0b6094d14c8d Mon Sep 17 00:00:00 2001 From: Jean-Yves Monnier Date: Tue, 9 Jul 2019 05:17:37 +0200 Subject: open multiple URLs Tested and validated on FreeBSD --- badwolf.1 | 2 +- badwolf.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'badwolf.c') diff --git a/badwolf.1 b/badwolf.1 index 8f13795..27cd6b3 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -9,7 +9,7 @@ .Sh SYNOPSIS .Nm .Op Ar webkit/gtk options -.Op Ar url or path +.Op Ar URLs or paths .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 ca1b302..68a9c23 100644 --- a/badwolf.c +++ b/badwolf.c @@ -701,7 +701,6 @@ main(int argc, char *argv[]) { // getting an abort if this one fails to alloc struct Window *window = g_malloc(sizeof(struct Window)); - gchar *target_url = NULL; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, DATADIR "/locale"); @@ -722,8 +721,6 @@ main(int argc, char *argv[]) gtk_init(&argc, &argv); - if(argv[1]) target_url = argv[1]; - 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-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); @@ -741,7 +738,11 @@ main(int argc, char *argv[]) gtk_container_add(GTK_CONTAINER(window->main_window), window->notebook); - badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url, NULL)); + if(argc == 1) + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL)); + else + for(int i = 1; i < argc; ++i) + badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL)); g_signal_connect( window->main_window, "key-press-event", G_CALLBACK(main_windowCb_key_press_event), window); -- cgit v1.3.1-23-gd82d From c31526e3a15ae326bbd08942c523dfc9baa82e4d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 31 Oct 2019 13:20:35 +0100 Subject: Move JS control to enable-javascript-markup enable-javascript-markup toggles only the document's javascript while enable-javascript also controls WebKit's javascript used in at least the media player --- badwolf.c | 4 ++-- config.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 68a9c23..0c4cfa7 100644 --- a/badwolf.c +++ b/badwolf.c @@ -420,7 +420,7 @@ javascriptCb_toggled(GtkButton *javascript, gpointer user_data) WebKitSettings *settings = webkit_web_view_get_settings(browser->webView); - webkit_settings_set_enable_javascript( + webkit_settings_set_enable_javascript_markup( settings, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(javascript))); webkit_web_view_set_settings(browser->webView, settings); @@ -513,7 +513,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web WebKitSettings *settings = webkit_settings_new_with_settings(BADWOLF_WEBKIT_SETTINGS); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(browser->javascript), - webkit_settings_get_enable_javascript(settings)); + webkit_settings_get_enable_javascript_markup(settings)); browser->webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", diff --git a/config.h b/config.h index df9e004..0044667 100644 --- a/config.h +++ b/config.h @@ -63,7 +63,8 @@ "enable-caret-browsing", FALSE, \ "enable-developer-extras", TRUE, \ "enable-java", FALSE, \ - "enable-javascript", FALSE, \ + "enable-javascript", TRUE, \ + "enable-javascript-markup", FALSE, \ "enable-plugins", FALSE, \ "javascript-can-access-clipboard", FALSE, \ "javascript-can-open-windows-automatically", FALSE, \ -- cgit v1.3.1-23-gd82d From 3cf773a201f43573ad77876792f0a79843dfec27 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 31 Oct 2019 13:25:35 +0100 Subject: badwolf.c: enable sandboxing --- badwolf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 0c4cfa7..10c019b 100644 --- a/badwolf.c +++ b/badwolf.c @@ -496,6 +496,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web browser->search = gtk_search_entry_new(); WebKitWebContext *web_context = webkit_web_context_new_ephemeral(); + webkit_web_context_set_sandbox_enabled(web_context, TRUE); webkit_web_context_set_process_model(web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); -- cgit v1.3.1-23-gd82d From 6c37e90f6b49dbcbdce0cb3b4a522e6b17647d3d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 12 Oct 2019 06:47:05 +0200 Subject: s/web_contentCb_download_started/web_contextCb_download_started/ --- badwolf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 10c019b..b9f9de2 100644 --- a/badwolf.c +++ b/badwolf.c @@ -42,7 +42,7 @@ static gboolean WebViewCb_decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision, WebKitPolicyDecisionType decision_type, gpointer user_data); -static void web_contentCb_download_started(WebKitWebContext *context, +static void web_contextCb_download_started(WebKitWebContext *context, WebKitDownload *download, gpointer user_data); static gboolean downloadCb_decide_destination(WebKitDownload *download, @@ -353,7 +353,7 @@ WebViewCb_decide_policy(WebKitWebView *web_view, } static void -web_contentCb_download_started(WebKitWebContext *context, +web_contextCb_download_started(WebKitWebContext *context, WebKitDownload *download, gpointer user_data) { @@ -606,7 +606,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web /* signals for WebView's WebContext */ g_signal_connect(G_OBJECT(web_context), "download-started", - G_CALLBACK(web_contentCb_download_started), + G_CALLBACK(web_contextCb_download_started), browser); /* signals for search widget */ -- cgit v1.3.1-23-gd82d From 9c11983fadcb5ce3bcf6fbbdb2e3c7dfff09d653 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 12 Oct 2019 06:54:04 +0200 Subject: Set WebKitWebExtension directory --- badwolf.1 | 12 ++++++++++-- badwolf.c | 15 +++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'badwolf.c') diff --git a/badwolf.1 b/badwolf.1 index 27cd6b3..ccec38e 100644 --- a/badwolf.1 +++ b/badwolf.1 @@ -1,7 +1,7 @@ ./" BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser ./" Copyright © 2019 Haelwenn (lanodan) Monnier ./" SPDX-License-Identifier: BSD-3-Clause -.Dd 2019-04-02 +.Dd 2019-10-31 .Dt badwolf 1 .Sh NAME .Nm badwolf @@ -12,7 +12,7 @@ .Op Ar URLs or paths .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. +is a minimalist browser that cares about privacy, it is based on WebKitGTK and thus also accepts WebKitGTK (and dependencies) flags and environment variables, unfortunately there doesn't seems to be manpages for theses. .Pp Runtime configuration specific to .Nm @@ -66,6 +66,14 @@ A colon-separated list in the form lang_COUNTRY where lang is in ISO-639 and COU .Ic BADWOLF_L10N="en_GB:fr_FR:de_DE" . When this variable isn't set, spelling isn't activated. A more generic variable name is also intended to be used in the future. .El +.Sh FILES +.Bl -tag -width Ds -compact +.It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/webkit-web-extensions/ +Directory containing the +.Lk https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html WebKitWebExtensions +to be loaded into +.Nm . Note: They aren't the JavaScript-based Web-Extensions supported by Firefox or Chrome, but native code in shared objects using the WebKitGTK API. +.El .Sh BUGS You can submit contributions or tickets to .Lk https://gitlab.com/lanodan/badwolf diff --git a/badwolf.c b/badwolf.c index b9f9de2..6c6b0c9 100644 --- a/badwolf.c +++ b/badwolf.c @@ -15,6 +15,8 @@ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; const gchar *version = VERSION; +gchar *web_extensions_directory; + static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, @@ -42,7 +44,7 @@ static gboolean WebViewCb_decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision, WebKitPolicyDecisionType decision_type, gpointer user_data); -static void web_contextCb_download_started(WebKitWebContext *context, +static void web_contextCb_download_started(WebKitWebContext *web_context, WebKitDownload *download, gpointer user_data); static gboolean downloadCb_decide_destination(WebKitDownload *download, @@ -353,11 +355,11 @@ WebViewCb_decide_policy(WebKitWebView *web_view, } static void -web_contextCb_download_started(WebKitWebContext *context, +web_contextCb_download_started(WebKitWebContext *web_context, WebKitDownload *download, gpointer user_data) { - (void)context; + (void)web_context; g_signal_connect(G_OBJECT(download), "decide-destination", @@ -500,6 +502,8 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web webkit_web_context_set_process_model(web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); + webkit_web_context_set_web_extensions_directory(web_context, web_extensions_directory); + badwolf_l10n = getenv("BADWOLF_L10N"); if(badwolf_l10n != NULL) @@ -708,6 +712,8 @@ main(int argc, char *argv[]) bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); + gtk_init(&argc, &argv); + g_fprintf(stderr, _("Running Badwolf version: %s\n"), version); g_fprintf(stderr, _("Buildtime WebKit version: %d.%d.%d\n"), @@ -720,7 +726,8 @@ main(int argc, char *argv[]) webkit_get_minor_version(), webkit_get_micro_version()); - gtk_init(&argc, &argv); + web_extensions_directory = g_build_filename(g_get_user_data_dir(), "badwolf", "webkit-web-extension", NULL); + g_fprintf(stderr, _("webkit-web-extension directory set to: %s\n"), web_extensions_directory); window->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window->notebook = gtk_notebook_new(); -- cgit v1.3.1-23-gd82d