commit: dc7780f98f0441e99b160d863506bc2c556d4cb6
parent: 5c6685693568ef3530d13285d883a20e103a50ad
author: Chris Noxz <chris@noxz.tech>
date: Tue, 11 Apr 2023 21:09:59 +0200
rewrite config and settings handling
* Add webkit settings name to config.h
* Load configuration into webkit settings based on settings name
* Change how JavaScript indicators are determined
* Add configuration names
* Add default-charset as an environment variable
* Make it possible to interpret settings in an invertible manner (this is used
for configuration objects prefixed with DISABLE_)
4 files changed, 74 insertions(+), 61 deletions(-)
diff --git a/adji.1 b/adji.1
@@ -55,6 +55,11 @@ header based on the provided list of languages, which can be comma-separated
as the default.
.TP
.B
+ADJI_CHARSET
+The character encoding that is automatically assumed when interpreting content
+that does not specify a particular charset. Defaults to \(lqUTF-8\(rq.
+.TP
+.B
ADJI_COOKIE_FILE
By providing a path to a cookie file,
.B adji
diff --git a/browser.c b/browser.c
@@ -72,23 +72,15 @@ client_create(const gchar *uri,
CB(c->wv, "web-process-crashed", cb_wv_crashed, c);
/* load config into webkit settings */
- c->settings = webkit_settings_new_with_settings(
- "auto-load-images", !CFG_B(DisableAutoLoadImages),
- "default-font-family", CFG_S(DefaultFont),
- "default-font-size", CFG_I(DefaultFontSize),
- "enable-developer-extras", CFG_B(DeveloperExtras),
- "enable-dns-prefetching", FALSE,
- "enable-hyperlink-auditing", FALSE,
- "enable-smooth-scrolling", CFG_B(SmoothScrolling),
- "enable-webrtc", FALSE,
- "enable-write-console-messages-to-stdout", CFG_B(ConsoleToStdout),
- "javascript-can-access-clipboard", FALSE,
- "javascript-can-open-windows-automatically", FALSE,
- "monospace-font-family", CFG_S(MonospaceFont),
- "sans-serif-font-family", CFG_S(SansSerifFont),
- "serif-font-family", CFG_S(SerifFont),
- "user-agent", CFG_S(UserAgent),
- NULL);
+ c->settings = webkit_settings_new();
+ for (int i = 0; i < LastConfig; i++)
+ if (cfg[i].s != NULL)
+ g_object_set(
+ G_OBJECT(c->settings),
+ cfg[i].s,
+ cfg[i].i ? (Arg)!(cfg[i].v.b) : (cfg[i].v),
+ NULL
+ );
webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->wv), c->settings);
if (CFG_L(AcceptedLanguages) != NULL)
@@ -120,9 +112,10 @@ client_create(const gchar *uri,
c->entry = gtk_entry_new();
CB(c->entry, "key-press-event", cb_entry_hid, c);
CB(c->entry, "icon-release", cb_entry_icon_hid, c);
-
- /* entry must exist before first call */
- set_javascript_policy(c, !(CFG_B(DisableJavaScript)));
+ gtk_entry_set_icon_from_icon_name(
+ GTK_ENTRY(c->entry), GTK_ENTRY_ICON_SECONDARY, CFG_B(DisableJavaScript)
+ ? ICON_JS_OFF : ICON_JS_ON
+ );
/* create vertical box to store the web view and the entry */
c->vbx = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -1152,15 +1145,14 @@ set_javascript_policy(struct Client *c,
? !webkit_settings_get_enable_javascript_markup(c->settings)
: policy
);
+ gtk_entry_set_icon_from_icon_name(
+ GTK_ENTRY(c->entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ webkit_settings_get_enable_javascript_markup(c->settings)
+ ? ICON_JS_ON
+ : ICON_JS_OFF
+ );
webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(c->wv));
- if ((webkit_settings_get_enable_javascript_markup(c->settings)))
- gtk_entry_set_icon_from_icon_name(
- GTK_ENTRY(c->entry), GTK_ENTRY_ICON_SECONDARY, ICON_JS_ON
- );
- else
- gtk_entry_set_icon_from_icon_name(
- GTK_ENTRY(c->entry), GTK_ENTRY_ICON_SECONDARY, ICON_JS_OFF
- );
save_state();
}
diff --git a/browser.h b/browser.h
@@ -117,16 +117,22 @@ enum config_name {
BadTlsTabFormat,
ConsoleToStdout,
CookieFile,
+ DnsPrefetching,
+ DefaultCharset,
DefaultFont,
DefaultFontSize,
DeveloperExtras,
DisableAutoLoadImages,
DisableJavaScript,
DownloadDirectory,
+ EncryptedMedia,
ExternalHandlerFile,
FifoName,
HistoryFile,
HomeUri,
+ HyperlinkAuditing,
+ JsAccessClipboard,
+ JsOpenWindows,
MonospaceFont,
NormalTabFormat,
ProxyIgnore,
@@ -136,11 +142,12 @@ enum config_name {
SerifFont,
SmoothScrolling,
StateFile,
- UriSchemes,
- UserAgent,
UcDir, /* user (cascading) style sheets directory */
+ UriSchemes,
UsDir, /* user scripts directory */
+ UserAgent,
WeDir, /* web extension directory */
+ WebRtc,
XdgSchemes,
ZoomLevel,
/* must be last to represent number of config items */
@@ -174,7 +181,9 @@ struct Client
typedef struct {
const char *e;
+ const char *s;
enum config_type t;
+ gboolean i;
Arg v;
} Config;
diff --git a/config.h b/config.h
@@ -20,37 +20,44 @@
#define CONFIG_H
static Config cfg[LastConfig] = {
- /* config name enviornment variable name config type default value */
- [AcceptedLanguages] = { __NAME_UPPERCASE__"_ACCEPTED_LANGUAGES", CFG_LIST, {.l = NULL }},
- [BadTlsTabFormat] = { NULL, CFG_STRING, {.s = "<span foreground=\"yellow\" style=\"italic\">%s</span>" }},
- [ConsoleToStdout] = { __NAME_UPPERCASE__"_ENABLE_CONSOLE_TO_STDOUT", CFG_BOOL, {.b = FALSE }},
- [CookieFile] = { __NAME_UPPERCASE__"_COOKIE_FILE", CFG_STRING, {.s = NULL }},
- [DefaultFont] = { __NAME_UPPERCASE__"_DEFAULT_FONT", CFG_STRING, {.s = "monospace" }},
- [DefaultFontSize] = { __NAME_UPPERCASE__"_DEFAULT_FONT_SIZE", CFG_INT, {.i = 12 }},
- [DownloadDirectory] = { __NAME_UPPERCASE__"_DOWNLOAD_DIR", CFG_STRING, {.s = "/var/tmp" }},
- [DeveloperExtras] = { NULL, CFG_BOOL, {.b = TRUE }},
- [ExternalHandlerFile] = { NULL, CFG_STRING, {.s = "exthandler" }},
- [FifoName] = { __NAME_UPPERCASE__"_FIFO_NAME", CFG_STRING, {.s = "default" }},
- [HistoryFile] = { __NAME_UPPERCASE__"_HISTORY_FILE", CFG_STRING, {.s = NULL }},
- [HomeUri] = { __NAME_UPPERCASE__"_HOME_URI", CFG_STRING, {.s = "about:blank" }},
- [DisableAutoLoadImages] = { __NAME_UPPERCASE__"_DISABLE_AUTO_LOAD_IMAGES", CFG_BOOL, {.b = FALSE }},
- [DisableJavaScript] = { __NAME_UPPERCASE__"_DISABLE_JAVASCRIPT", CFG_BOOL, {.b = FALSE }},
- [MonospaceFont] = { __NAME_UPPERCASE__"_MONOSPACE_FONT", CFG_STRING, {.s = "monospace" }},
- [NormalTabFormat] = { NULL, CFG_STRING, {.s = "<span>%s</span>" }},
- [ProxyIgnore] = { __NAME_UPPERCASE__"_PROXY_IGNORE", CFG_LIST, {.l = NULL }},
- [ProxyUri] = { __NAME_UPPERCASE__"_PROXY_URI", CFG_STRING, {.s = NULL }},
- [SansSerifFont] = { __NAME_UPPERCASE__"_SANS_SERIF_FONT", CFG_STRING, {.s = "sans-serif" }},
- [SearchEngineUriFormat] = { __NAME_UPPERCASE__"_SE_URI_FORMAT", CFG_STRING, {.s = "https://ddg.gg?q=%s" }},
- [SerifFont] = { __NAME_UPPERCASE__"_SERIF_FONT", CFG_STRING, {.s = "serif" }},
- [SmoothScrolling] = { __NAME_UPPERCASE__"_ENABLE_SMOOTH_SCROLLING", CFG_BOOL, {.b = FALSE }},
- [StateFile] = { __NAME_UPPERCASE__"_STATE_FILE", CFG_STRING, {.s = NULL }},
- [UriSchemes] = { NULL, CFG_LIST, {.l = (gchar*[]){ "http", "https", "file", "about", "data", "webkit", NULL } }},
- [UserAgent] = { __NAME_UPPERCASE__"_USER_AGENT", CFG_STRING, {.s = NULL }},
- [UsDir] = { NULL, CFG_STRING, {.s = "scripts" }},
- [UcDir] = { NULL, CFG_STRING, {.s = "styles" }},
- [WeDir] = { NULL, CFG_STRING, {.s = "web_extensions" }},
- [XdgSchemes] = { __NAME_UPPERCASE__"_XDG_SCHEMES", CFG_LIST, {.l = NULL }},
- [ZoomLevel] = { __NAME_UPPERCASE__"_ZOOM_LEVEL", CFG_FLOAT, {.f = 1.0 }},
+ /* config name enviornment variable name webkit web view setting name config type invert default value */
+ [AcceptedLanguages] = { __NAME_UPPERCASE__"_ACCEPTED_LANGUAGES", NULL, CFG_LIST, FALSE, {.l = NULL }},
+ [BadTlsTabFormat] = { NULL, NULL, CFG_STRING, FALSE, {.s = "<span foreground=\"yellow\" style=\"italic\">%s</span>" }},
+ [ConsoleToStdout] = { __NAME_UPPERCASE__"_ENABLE_CONSOLE_TO_STDOUT", "enable-write-console-messages-to-stdout", CFG_BOOL, FALSE, {.b = FALSE }},
+ [CookieFile] = { __NAME_UPPERCASE__"_COOKIE_FILE", NULL, CFG_STRING, FALSE, {.s = NULL }},
+ [DnsPrefetching] = { NULL, "enable-dns-prefetching", CFG_BOOL, FALSE, {.b = FALSE }},
+ [DefaultCharset] = { __NAME_UPPERCASE__"_CHARSET", "default-charset", CFG_STRING, FALSE, {.s = "UTF-8" }},
+ [DefaultFontSize] = { __NAME_UPPERCASE__"_DEFAULT_FONT_SIZE", "default-font-size", CFG_INT, FALSE, {.i = 12 }},
+ [DefaultFont] = { __NAME_UPPERCASE__"_DEFAULT_FONT", "default-font-family", CFG_STRING, FALSE, {.s = "monospace" }},
+ [DeveloperExtras] = { NULL, "enable-developer-extras", CFG_BOOL, FALSE, {.b = TRUE }},
+ [DisableAutoLoadImages] = { __NAME_UPPERCASE__"_DISABLE_AUTO_LOAD_IMAGES", "auto-load-images", CFG_BOOL, TRUE, {.b = FALSE }},
+ [DisableJavaScript] = { __NAME_UPPERCASE__"_DISABLE_JAVASCRIPT", "enable-javascript-markup", CFG_BOOL, TRUE, {.b = FALSE }},
+ [DownloadDirectory] = { __NAME_UPPERCASE__"_DOWNLOAD_DIR", NULL, CFG_STRING, FALSE, {.s = "/var/tmp" }},
+ [EncryptedMedia] = { NULL, "enable-encrypted-media", CFG_BOOL, FALSE, {.b = FALSE }},
+ [ExternalHandlerFile] = { NULL, NULL, CFG_STRING, FALSE, {.s = "exthandler" }},
+ [FifoName] = { __NAME_UPPERCASE__"_FIFO_NAME", NULL, CFG_STRING, FALSE, {.s = "default" }},
+ [HistoryFile] = { __NAME_UPPERCASE__"_HISTORY_FILE", NULL, CFG_STRING, FALSE, {.s = NULL }},
+ [HomeUri] = { __NAME_UPPERCASE__"_HOME_URI", NULL, CFG_STRING, FALSE, {.s = "about:blank" }},
+ [HyperlinkAuditing] = { NULL, "enable-hyperlink-auditing", CFG_BOOL, FALSE, {.b = FALSE }},
+ [JsAccessClipboard] = { NULL, "javascript-can-access-clipboard", CFG_BOOL, FALSE, {.b = FALSE }},
+ [JsOpenWindows] = { NULL, "javascript-can-access-clipboard", CFG_BOOL, FALSE, {.b = FALSE }},
+ [MonospaceFont] = { __NAME_UPPERCASE__"_MONOSPACE_FONT", "monospace-font-family", CFG_STRING, FALSE, {.s = "monospace" }},
+ [NormalTabFormat] = { NULL, NULL, CFG_STRING, FALSE, {.s = "<span>%s</span>" }},
+ [ProxyIgnore] = { __NAME_UPPERCASE__"_PROXY_IGNORE", NULL, CFG_LIST, FALSE, {.l = NULL }},
+ [ProxyUri] = { __NAME_UPPERCASE__"_PROXY_URI", NULL, CFG_STRING, FALSE, {.s = NULL }},
+ [SansSerifFont] = { __NAME_UPPERCASE__"_SANS_SERIF_FONT", "sans-serif-font-family", CFG_STRING, FALSE, {.s = "sans-serif" }},
+ [SearchEngineUriFormat] = { __NAME_UPPERCASE__"_SE_URI_FORMAT", NULL, CFG_STRING, FALSE, {.s = "https://ddg.gg?q=%s" }},
+ [SerifFont] = { __NAME_UPPERCASE__"_SERIF_FONT", "serif-font-family", CFG_STRING, FALSE, {.s = "serif" }},
+ [SmoothScrolling] = { __NAME_UPPERCASE__"_ENABLE_SMOOTH_SCROLLING", "enable-smooth-scrolling", CFG_BOOL, FALSE, {.b = FALSE }},
+ [StateFile] = { __NAME_UPPERCASE__"_STATE_FILE", NULL, CFG_STRING, FALSE, {.s = NULL }},
+ [UcDir] = { NULL, NULL, CFG_STRING, FALSE, {.s = "styles" }},
+ [UriSchemes] = { NULL, NULL, CFG_LIST, FALSE, {.l = (gchar*[]){ "http", "https", "file", "about", "data", "webkit", NULL } }},
+ [UsDir] = { NULL, NULL, CFG_STRING, FALSE, {.s = "scripts" }},
+ [UserAgent] = { __NAME_UPPERCASE__"_USER_AGENT", "user-agent", CFG_STRING, FALSE, {.s = NULL }},
+ [WeDir] = { NULL, NULL, CFG_STRING, FALSE, {.s = "web_extensions" }},
+ [WebRtc] = { NULL, "enable-webrtc", CFG_BOOL, FALSE, {.b = FALSE }},
+ [XdgSchemes] = { __NAME_UPPERCASE__"_XDG_SCHEMES", NULL, CFG_LIST, FALSE, {.l = NULL }},
+ [ZoomLevel] = { __NAME_UPPERCASE__"_ZOOM_LEVEL", NULL, CFG_FLOAT, FALSE, {.f = 1.0 }},
};
#endif /* !CONFIG_H */