commit: 9859ac3e8543a78682be88c55f0ccf2f8c610da9
parent f18b476c29d9e63d0bdd4d81b74a1826faf4e532
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 20 Jan 2024 12:23:26 +0100
Add options: -i (disable images) and -S (enable JavaScript)
Diffstat:
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/badwolf.1 b/badwolf.1
@@ -1,5 +1,5 @@
.\" BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
-.\" Copyright © 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf>
+.\" Copyright © 2019-2024 Badwolf Authors <https://hacktivis.me/projects/badwolf>
.\" SPDX-License-Identifier: BSD-3-Clause
.Dd 2022-07-13
.Dt BADWOLF 1
@@ -10,14 +10,19 @@
.Sh SYNOPSIS
.Nm
.Op Ar webkit/gtk options
+.Op Fl iS
.Op Ar URLs or paths
.Sh DESCRIPTION
.Nm
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
-will probably get added at a later release.
+.Sh OPTIONS
+.Bl -tag -width Ds
+.It Fl i
+Disable Images.
+.It Fl S
+Enable JavaScript.
+.El
.Sh KEYBINDINGS
The following section lists the keybinding by their action, each item is described by the widget the focus is on or
.Aq any
diff --git a/badwolf.c b/badwolf.c
@@ -1,5 +1,5 @@
// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
-// SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf>
+// SPDX-FileCopyrightText: 2019-2024 Badwolf Authors <https://hacktivis.me/projects/badwolf>
// SPDX-License-Identifier: BSD-3-Clause
#include "badwolf.h"
@@ -18,7 +18,7 @@
#include <locale.h> /* LC_* */
#include <stdio.h> /* perror(), fprintf(), snprintf() */
#include <stdlib.h> /* malloc() */
-#include <unistd.h> /* access() */
+#include <unistd.h> /* access(), getopt() */
const gchar *homepage = "https://hacktivis.me/projects/badwolf";
const gchar *version = VERSION;
@@ -27,6 +27,8 @@ static gchar *web_extensions_directory;
static uint64_t context_id_counter = 0;
GtkTreeModel *bookmarks_completion_model;
+bool opt_S = false, opt_i = false;
+
static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data);
static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView,
WebKitWebProcessTerminationReason reason,
@@ -662,6 +664,8 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
if(browser == NULL) return NULL;
+ assert(window != NULL);
+
browser->window = window;
browser->context_id = old_browser == NULL ? context_id_counter++ : old_browser->context_id;
browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -732,6 +736,8 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
}
WebKitSettings *settings = webkit_settings_new_with_settings(BADWOLF_WEBKIT_SETTINGS);
+ if(opt_S) webkit_settings_set_enable_javascript_markup(settings, true);
+ if(opt_i) webkit_settings_set_auto_load_images(settings, false);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(browser->javascript),
webkit_settings_get_enable_javascript_markup(settings));
@@ -1066,6 +1072,26 @@ main(int argc, char *argv[])
gtk_init(&argc, &argv);
+ int c = EOF;
+ while((c = getopt(argc, argv, "iS")) != EOF)
+ {
+ switch(c)
+ {
+ case 'i':
+ opt_i = true;
+ break;
+ case 'S':
+ opt_S = true;
+ break;
+ case '?':
+ fprintf(stderr, _("badwolf: Unrecognized option: '-%c'\n"), optopt);
+ return 1;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
fprintf(stderr, _("Running Badwolf version: %s\n"), version);
fprintf(stderr,
_("Buildtime WebKit version: %d.%d.%d\n"),
@@ -1162,10 +1188,10 @@ main(int argc, char *argv[])
gtk_widget_show(window->new_tab);
gtk_widget_show_all(window->main_window);
- if(argc == 1)
+ if(argc == 0)
badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, NULL, NULL), FALSE);
else
- for(int i = 1; i < argc; ++i)
+ for(int i = 0; i < argc; ++i)
badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, argv[i], NULL), FALSE);
gtk_notebook_set_current_page(GTK_NOTEBOOK(window->notebook), 1);