summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <me@armaanb.net>2021-06-10 17:41:15 -0400
committerArmaan Bhojwani <me@armaanb.net>2021-06-10 17:41:59 -0400
commit9965aeb5f64ea23c6c4bf78ef956e165b7c3d762 (patch)
treeefffb4371bb1191749deffb47ff6fd74b6005663
parente46f96f17208fd8905a1a2c2f2d448eaf9acc84f (diff)
downloadchorizo-9965aeb5f64ea23c6c4bf78ef956e165b7c3d762.tar.gz
Update config file parsing and options
-rw-r--r--man/chorizo-config.5.scd57
-rw-r--r--src/browser.c164
2 files changed, 149 insertions, 72 deletions
diff --git a/man/chorizo-config.5.scd b/man/chorizo-config.5.scd
index 0b33364..e472a78 100644
--- a/man/chorizo-config.5.scd
+++ b/man/chorizo-config.5.scd
@@ -12,11 +12,6 @@ $XDG_CONFIG_DIR. Settings must go under the relevant subsection.
# OPTIONS
## BROWSER
-*accepted_language*++
- Type: string++
- Default: NULL++
- Set the accepted language header.
-
*console_to_stdout*++
Type: boolean++
Default: false++
@@ -38,9 +33,20 @@ $XDG_CONFIG_DIR. Settings must go under the relevant subsection.
Default: "about:blank"++
Set the default URI for new tabs.
-*javascript_disabled*++
+*images_enabled*++
+ Type: boolean++
+ Default: true++
+ Determines whether or not images are enabled by default.
+
+*javascript_can_access_clipboard*++
Type: boolean++
Default: false++
+ Determines whether or not JavaScript can access the clipboard. Necessary for
+ websites like gDrive, and "click to copy" buttons
+
+*javascript_enabled*++
+ Type: boolean++
+ Default: true++
Determines whether or not JavaScript is enabled by default.
*search_engine*++
@@ -48,9 +54,9 @@ $XDG_CONFIG_DIR. Settings must go under the relevant subsection.
Default: "https://duckduckgo.com?q="++
What search engine to use when searching with "w/".
-*spellcheck_disabled*++
+*spellcheck_enabled*++
Type: boolean++
- Default: false++
+ Default: true++
Disable spell checking.
*spellcheck_language*++
@@ -63,12 +69,47 @@ $XDG_CONFIG_DIR. Settings must go under the relevant subsection.
Default: the WebKit default++
Choose a custom user agent.
+*webgl_enabled*++
+ Type: boolean++
+ Default: true++
+ Determines whether or not WebGL is enabled.
+
## UI
*default_uri*++
Type: string++
Default: "https://"++
The URI to fill the location bar with when entering the it from the homepage.
+*font_family_default*++
+ Type: string++
+ Default: "sans-serif"++
+ Default font family.
+
+*font_family_default_monospace*++
+ Type: string++
+ Default: "monospace"++
+ Default monospace font family
+
+*font_family_default_sans_serif*++
+ Type: string++
+ Default: "sans-serif"++
+ Default sans-serif font family
+
+*font_family_default_serif*++
+ Type: string++
+ Default: "serif"++
+ Default serif font family
+
+*font_size_default*++
+ Type: integer++
+ Default: 16++
+ Default font size.
+
+*font_size_default_monospace*++
+ Type: integer++
+ Default: 13++
+ Default monospace font size.
+
*scroll_lines*++
Type: integer++
Default: 3++
diff --git a/src/browser.c b/src/browser.c
index 4885119..5054241 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -53,24 +53,18 @@ struct Client {
};
struct Configuration {
+ gdouble zoom_level;
WebKitCookieAcceptPolicy cookie_policy;
- const gchar *accepted_language[2];
gboolean cooperative_alone;
gboolean cooperative_instances;
- gboolean enable_console_to_stdout;
- gboolean images_disabled;
- gboolean javascript_disabled;
+ gboolean images_enabled;
+ gboolean javascript_enabled;
gboolean private;
- gboolean spellcheck_disabled;
+ gboolean spellcheck_enabled;
gchar *default_uri;
- gchar *download_dir;
- gchar *fifo_suffix;
- gchar *history_file;
gchar *home_uri;
gchar *search_engine;
gchar *spellcheck_language;
- gchar *user_agent;
- gdouble global_zoom;
gint scroll_lines;
gint tab_width_chars;
} cfg;
@@ -207,12 +201,68 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
c->web_view = webkit_web_view_new_with_related_view(related_wv);
}
+ // Get settings
c->settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
- webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
- cfg.global_zoom);
- webkit_settings_set_enable_javascript(c->settings,
- !cfg.javascript_disabled);
- webkit_settings_set_auto_load_images(c->settings, !cfg.images_disabled);
+ webkit_settings_set_enable_javascript(c->settings, cfg.javascript_enabled);
+ webkit_settings_set_auto_load_images(c->settings, cfg.images_enabled);
+
+ GKeyFile *config = get_ini();
+ char *val;
+ val = g_key_file_get_string(config, "ui", "font_family_default", NULL);
+ if (val != NULL)
+ webkit_settings_set_default_font_family(c->settings, val);
+
+ val = g_key_file_get_string(config, "ui", "font_family_default_monospace",
+ NULL);
+ if (val != NULL)
+ webkit_settings_set_monospace_font_family(c->settings, val);
+
+ val = g_key_file_get_string(config, "ui", "font_family_default_sans_serif",
+ NULL);
+ if (val != NULL)
+ webkit_settings_set_sans_serif_font_family(c->settings, val);
+
+ val =
+ g_key_file_get_string(config, "ui", "font_family_default_serif", NULL);
+ if (val != NULL)
+ webkit_settings_set_serif_font_family(c->settings, val);
+
+ val = g_key_file_get_string(config, "browser", "user_agent", NULL);
+ if (val != NULL)
+ g_object_set(c->settings, "user-agent", val, NULL);
+
+ int val2;
+ val2 = g_key_file_get_integer(config, "ui", "font_size_default", NULL);
+ if (val2)
+ webkit_settings_set_default_font_size(c->settings, val2);
+
+ val2 = g_key_file_get_integer(config, "ui", "font_size_default_monospace",
+ NULL);
+ if (val2)
+ webkit_settings_set_default_monospace_font_size(c->settings, val2);
+
+ gboolean val3;
+ val3 = g_key_file_get_boolean(config, "browser", "console_to_stdout", NULL);
+ if (val3)
+ webkit_settings_set_enable_write_console_messages_to_stdout(c->settings,
+ val3);
+
+ val3 = g_key_file_get_boolean(config, "browser", "webgl_enable", NULL);
+ if (!val3)
+ webkit_settings_set_enable_webgl(c->settings, val3);
+
+ val3 = g_key_file_get_boolean(config, "browser",
+ "javascript_can_access_clipboard", NULL);
+ if (val3)
+ webkit_settings_set_javascript_can_access_clipboard(c->settings, val3);
+
+ double val4;
+ val4 = g_key_file_get_double(config, "ui", "zoom_level", NULL);
+ if (val4)
+ webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), val4);
+
+ webkit_settings_set_enable_developer_extras(c->settings, TRUE);
+
g_signal_connect(G_OBJECT(c->web_view), "notify::favicon",
G_CALLBACK(changed_favicon), c);
g_signal_connect(G_OBJECT(c->web_view), "notify::title",
@@ -238,28 +288,18 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
G_CALLBACK(crashed_web_view), c);
- if (cfg.user_agent != NULL) {
- g_object_set(c->settings, "user-agent", cfg.user_agent, NULL);
- }
-
- if (cfg.enable_console_to_stdout)
- webkit_settings_set_enable_write_console_messages_to_stdout(c->settings,
- TRUE);
-
- webkit_settings_set_enable_developer_extras(c->settings, TRUE);
-
GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
c->jsbutton = gtk_toggle_button_new_with_label("JS");
gtk_widget_set_tooltip_text(c->jsbutton, "Toggle JavaScript execution");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton),
- !cfg.javascript_disabled);
+ cfg.javascript_enabled);
g_signal_connect(G_OBJECT(c->jsbutton), "toggled", G_CALLBACK(togglejs), c);
c->imgbutton = gtk_toggle_button_new_with_label("IMG");
gtk_widget_set_tooltip_text(c->imgbutton, "Toggle image loading");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
- !cfg.images_disabled);
+ cfg.images_enabled);
g_signal_connect(G_OBJECT(c->imgbutton), "toggled", G_CALLBACK(toggleimg),
c);
@@ -363,8 +403,8 @@ cooperation_setup(void) {
gchar *fifofilename, *fifopath;
gchar *priv = (cfg.private) ? "-private" : "";
- fifofilename =
- g_strdup_printf("%s%s%s-%s", __NAME__, priv, ".fifo", cfg.fifo_suffix);
+ fifofilename = g_strdup_printf("%s%s%s-%s", __NAME__, priv, ".fifo",
+ g_getenv(__NAME_UPPERCASE__ "_FIFO_SUFFIX"));
fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
g_free(fifofilename);
@@ -499,8 +539,11 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data) {
if (t != NULL && strlen(t) > 0) {
set_uri(t, c);
- if (cfg.history_file != NULL && !cfg.private) {
- fp = fopen(cfg.history_file, "a");
+ gchar *history_file =
+ g_key_file_get_string(config, "browser", "history_file", NULL);
+
+ if (history_file != NULL && !cfg.private) {
+ fp = fopen(history_file, "a");
if (fp != NULL) {
fprintf(fp, "%s\n", t);
fclose(fp);
@@ -567,34 +610,23 @@ ensure_uri_scheme(const gchar *t) {
void
get_config(void) {
- cfg.accepted_language[0] = NULL;
- cfg.accepted_language[1] = NULL;
cfg.cooperative_alone = TRUE;
cfg.cooperative_instances = TRUE;
- cfg.fifo_suffix = "main";
-
- const char *e = g_getenv(__NAME_UPPERCASE__ "_FIFO_SUFFIX");
- if (e != NULL)
- cfg.fifo_suffix = g_strdup(e);
-
- char *xdg_down = getenv("XDG_DOWNLOAD_DIR");
- cfg.download_dir = (xdg_down) ? xdg_down : "/var/tmp";
config = get_ini();
- cfg.accepted_language[0] =
- g_key_file_get_string(config, "browser", "accepted_language", NULL);
- cfg.history_file =
- g_key_file_get_string(config, "browser", "history_file", NULL);
+
cfg.home_uri = g_key_file_get_string(config, "browser", "homepage", NULL);
cfg.home_uri = (cfg.home_uri) ? cfg.home_uri : "about:blank";
- cfg.enable_console_to_stdout =
- g_key_file_get_boolean(config, "browser", "console_to_stdout", NULL);
- cfg.user_agent =
- g_key_file_get_string(config, "browser", "user_agent", NULL);
- cfg.javascript_disabled =
- g_key_file_get_boolean(config, "browser", "javascript_disabled", NULL);
- cfg.images_disabled =
- g_key_file_get_boolean(config, "browser", "images_disabled", NULL);
+
+ cfg.javascript_enabled =
+ g_key_file_get_boolean(config, "browser", "javascript_enabled", NULL);
+ cfg.javascript_enabled =
+ (cfg.javascript_enabled) ? cfg.javascript_enabled : TRUE;
+
+ cfg.images_enabled =
+ g_key_file_get_boolean(config, "browser", "images_enabled", NULL);
+ cfg.images_enabled = (cfg.images_enabled) ? cfg.images_enabled : TRUE;
+
char *input_cookie_policy =
g_key_file_get_string(config, "browser", "cookie_policy", NULL);
cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
@@ -608,21 +640,26 @@ get_config(void) {
cfg.default_uri = g_key_file_get_string(config, "ui", "default_uri", NULL);
cfg.default_uri = (cfg.default_uri) ? cfg.default_uri : "https://";
+
cfg.tab_width_chars =
g_key_file_get_integer(config, "ui", "tab_width", NULL);
cfg.tab_width_chars = (cfg.tab_width_chars) ? cfg.tab_width_chars : 20;
- cfg.global_zoom = g_key_file_get_double(config, "ui", "zoom_level", NULL);
- cfg.global_zoom = (cfg.global_zoom) ? cfg.global_zoom : 1.0;
+
cfg.search_engine =
g_key_file_get_string(config, "ui", "search_engine", NULL);
cfg.search_engine =
(cfg.search_engine) ? cfg.search_engine : "https://duckduckgo.com?q=";
- cfg.spellcheck_disabled =
- g_key_file_get_boolean(config, "ui", "spellcheck_disabled", NULL);
+
+ cfg.spellcheck_enabled =
+ g_key_file_get_boolean(config, "ui", "spellcheck_enabled", NULL);
+ cfg.spellcheck_enabled =
+ (cfg.spellcheck_enabled) ? cfg.spellcheck_enabled : FALSE;
+
cfg.spellcheck_language =
g_key_file_get_string(config, "ui", "spellcheck_language", NULL);
cfg.spellcheck_language =
(cfg.spellcheck_language) ? cfg.spellcheck_language : "en_US";
+
cfg.scroll_lines =
g_key_file_get_integer(config, "ui", "scroll_lines", NULL);
cfg.scroll_lines = (cfg.scroll_lines) ? cfg.scroll_lines : 3;
@@ -762,11 +799,10 @@ init_default_web_context(void) {
webkit_web_context_set_web_extensions_directory(wc, p);
g_free(p);
- if (cfg.accepted_language[0] != NULL)
- webkit_web_context_set_preferred_languages(wc, cfg.accepted_language);
-
+ char *xdg_down = getenv("XDG_DOWNLOAD_DIR");
g_signal_connect(G_OBJECT(wc), "download-started",
- G_CALLBACK(download_start), cfg.download_dir);
+ G_CALLBACK(download_start),
+ (xdg_down) ? xdg_down : "/var/tmp");
trust_user_certs(wc);
@@ -787,7 +823,7 @@ init_default_web_context(void) {
const gchar *const languages[2] = {(const gchar *)cfg.spellcheck_language,
NULL};
webkit_web_context_set_spell_checking_languages(wc, languages);
- webkit_web_context_set_spell_checking_enabled(wc, !cfg.spellcheck_disabled);
+ webkit_web_context_set_spell_checking_enabled(wc, cfg.spellcheck_enabled);
}
void
@@ -995,7 +1031,7 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) {
return TRUE;
} else if (def_key("zoom_reset", GDK_KEY_0) == key) {
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
- cfg.global_zoom);
+ cfg.zoom_level);
return TRUE;
}
}
@@ -1105,7 +1141,7 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data) {
gdk_event_get_scroll_deltas(event, &dx, &dy);
z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
z += -dy * 0.1;
- z = dx != 0 ? cfg.global_zoom : z;
+ z = dx != 0 ? cfg.zoom_level : z;
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
return TRUE;
}