surf

Mahdi's build of surf
git clone git://mahdi.pw/surf.git
Log | Files | Refs | README | LICENSE

commit 95746bd6204c5def1c87bdcba1814145d623c891
parent 976d18789711202fda559d11389afc9f7b41437b
Author: Mahdi Mirzade <[email protected]>
Date:   Tue, 12 Apr 2022 13:58:37 +0430

Tweaks, DarkMode, Get webkit context/settings only once

Diffstat:
MLICENSE | 1+
Mconfig.h | 2++
Msurf.1 | 3+++
Msurf.c | 63+++++++++++++++++++++++++++++++++++++--------------------------
4 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -36,6 +36,7 @@ MIT/X Consortium License © 2018 Eddie Thieda <[email protected]> © 2018 Leonardo Taccari <[email protected]> © 2019 efe <[email protected]> +© 2022 Mahdi Mirzade <[email protected]> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/config.h b/config.h @@ -25,6 +25,7 @@ static Parameter defconfig[ParameterLast] = { [Certificate] = { { .i = 0 }, }, [CaretBrowsing] = { { .i = 0 }, }, [CookiePolicies] = { { .v = "@Aa" }, }, + [DarkMode] = { { .i = 0 }, }, [DefaultCharset] = { { .v = "UTF-8" }, }, [DiskCache] = { { .i = 1 }, }, [DNSPrefetch] = { { .i = 0 }, }, @@ -215,6 +216,7 @@ static Key keys[] = { { MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .i = LoadImages } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, + { MODKEY|GDK_SHIFT_MASK, GDK_KEY_d, toggle, { .i = DarkMode } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, }; diff --git a/surf.1 b/surf.1 @@ -208,6 +208,9 @@ Toggle scrollbars. This will reload the page. .B Ctrl\-Shift\-c Toggle caret browsing. This will reload the page. .TP +.B Ctrl\-Shift\-d +Toggle dark mode. This will reload the page. +.TP .B Ctrl\-Shift\-i Toggle auto-loading of images. This will reload the page. .TP diff --git a/surf.c b/surf.c @@ -56,6 +56,7 @@ typedef enum { CaretBrowsing, Certificate, CookiePolicies, + DarkMode, DiskCache, DefaultCharset, DNSPrefetch, @@ -101,6 +102,8 @@ typedef struct { typedef struct Client { GtkWidget *win; WebKitWebView *view; + WebKitSettings *settings; + WebKitWebContext *context; WebKitWebInspector *inspector; WebKitFindController *finder; WebKitHitTestResult *mousepos; @@ -277,6 +280,7 @@ static ParamName loadcommitted[] = { // AccessMicrophone, // AccessWebcam, CaretBrowsing, + DarkMode, DefaultCharset, FontSize, FrameFlattening, @@ -767,7 +771,6 @@ void setparameter(Client *c, int refresh, ParamName p, const Arg *a) { GdkRGBA bgcolor = { 0 }; - WebKitSettings *s = webkit_web_view_get_settings(c->view); modparams[p] = curconfig[p].prio; @@ -777,7 +780,7 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) case AccessWebcam: return; /* do nothing */ case CaretBrowsing: - webkit_settings_set_enable_caret_browsing(s, a->i); + webkit_settings_set_enable_caret_browsing(c->settings, a->i); refresh = 0; break; case Certificate: @@ -786,32 +789,35 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) return; /* do not update */ case CookiePolicies: webkit_cookie_manager_set_accept_policy( - webkit_web_context_get_cookie_manager( - webkit_web_view_get_context(c->view)), + webkit_web_context_get_cookie_manager(c->context), cookiepolicy_get()); refresh = 0; break; + case DarkMode: + g_object_set(gtk_settings_get_default(), + "gtk-application-prefer-dark-mode", a->i, NULL); + return; + break; case DiskCache: - webkit_web_context_set_cache_model( - webkit_web_view_get_context(c->view), a->i ? + webkit_web_context_set_cache_model(c->context, a->i ? WEBKIT_CACHE_MODEL_WEB_BROWSER : WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER); return; /* do not update */ case DefaultCharset: - webkit_settings_set_default_charset(s, a->v); + webkit_settings_set_default_charset(c->settings, a->v); return; /* do not update */ case DNSPrefetch: - webkit_settings_set_enable_dns_prefetching(s, a->i); + webkit_settings_set_enable_dns_prefetching(c->settings, a->i); return; /* do not update */ case FileURLsCrossAccess: - webkit_settings_set_allow_file_access_from_file_urls(s, a->i); - webkit_settings_set_allow_universal_access_from_file_urls(s, a->i); + webkit_settings_set_allow_file_access_from_file_urls(c->settings, a->i); + webkit_settings_set_allow_universal_access_from_file_urls(c->settings, a->i); return; /* do not update */ case FontSize: - webkit_settings_set_default_font_size(s, a->i); + webkit_settings_set_default_font_size(c->settings, a->i); return; /* do not update */ case FrameFlattening: - webkit_settings_set_enable_frame_flattening(s, a->i); + webkit_settings_set_enable_frame_flattening(c->settings, a->i); break; case Geolocation: refresh = 0; @@ -821,21 +827,21 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) webkit_web_view_set_background_color(c->view, &bgcolor); return; /* do not update */ case Inspector: - webkit_settings_set_enable_developer_extras(s, a->i); + webkit_settings_set_enable_developer_extras(c->settings, a->i); return; /* do not update */ case Java: - webkit_settings_set_enable_java(s, a->i); + webkit_settings_set_enable_java(c->settings, a->i); return; /* do not update */ case JavaScript: - webkit_settings_set_enable_javascript(s, a->i); + webkit_settings_set_enable_javascript(c->settings, a->i); break; case KioskMode: return; /* do nothing */ case LoadImages: - webkit_settings_set_auto_load_images(s, a->i); + webkit_settings_set_auto_load_images(c->settings, a->i); break; case MediaManualPlay: - webkit_settings_set_media_playback_requires_user_gesture(s, a->i); + webkit_settings_set_media_playback_requires_user_gesture(c->settings, a->i); break; case PreferredLanguages: return; /* do nothing */ @@ -852,20 +858,18 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) case ShowIndicators: break; case SmoothScrolling: - webkit_settings_set_enable_smooth_scrolling(s, a->i); + webkit_settings_set_enable_smooth_scrolling(c->settings, a->i); return; /* do not update */ case SiteQuirks: - webkit_settings_set_enable_site_specific_quirks(s, a->i); + webkit_settings_set_enable_site_specific_quirks(c->settings, a->i); break; case SpellChecking: - webkit_web_context_set_spell_checking_enabled( - webkit_web_view_get_context(c->view), a->i); + webkit_web_context_set_spell_checking_enabled(c->context, a->i); return; /* do not update */ case SpellLanguages: return; /* do nothing */ case StrictTLS: - webkit_web_context_set_tls_errors_policy( - webkit_web_view_get_context(c->view), a->i ? + webkit_web_context_set_tls_errors_policy(c->context, a->i ? WEBKIT_TLS_ERRORS_POLICY_FAIL : WEBKIT_TLS_ERRORS_POLICY_IGNORE); break; @@ -877,7 +881,7 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) refresh = 0; break; case WebGL: - webkit_settings_set_enable_webgl(s, a->i); + webkit_settings_set_enable_webgl(c->settings, a->i); break; case ZoomLevel: webkit_web_view_set_zoom_level(c->view, a->f); @@ -923,8 +927,8 @@ setcert(Client *c, const char *uri) if ((uri = strstr(uri, "https://"))) { uri += sizeof("https://") - 1; host = g_strndup(uri, strchr(uri, '/') - uri); - webkit_web_context_allow_tls_certificate_for_host( - webkit_web_view_get_context(c->view), cert, host); + webkit_web_context_allow_tls_certificate_for_host(c->context, + cert, host); g_free(host); } @@ -1124,6 +1128,8 @@ newview(Client *c, WebKitWebView *rv) /* Webview */ if (rv) { v = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(rv)); + context = webkit_web_view_get_context(v); + settings = webkit_web_view_get_settings(v); } else { settings = webkit_settings_new_with_settings( "allow-file-access-from-file-urls", curconfig[FileURLsCrossAccess].val.i, @@ -1237,6 +1243,11 @@ newview(Client *c, WebKitWebView *rv) g_signal_connect(G_OBJECT(v), "web-process-terminated", G_CALLBACK(webprocessterminated), c); + c->context = context; + c->settings = settings; + + setparameter(c, 0, DarkMode, &curconfig[DarkMode].val); + return v; }