~strahinja/surf

ff63f32b56b4c9c4ca3fff25f9919a6e39342519 — Страхиња Радић 2 years ago da91870 + 263e05c
Merge branch 'surf-webkit2'
4 files changed, 58 insertions(+), 39 deletions(-)

M config.def.h
M config.h
M surf.1
M surf.c
M config.def.h => config.def.h +7 -7
@@ 27,6 27,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 },     },


@@ 80,13 81,11 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
/* SETPROP(readprop, setprop, prompt)*/
#define SETPROP(r, s, p) { \
        .v = (const char *[]){ "/bin/sh", "-c", \
             "prop=\"$(printf '%b' \"$(xprop -id $1 "r" " \
             "| sed -e 's/^"r"(UTF8_STRING) = \"\\(.*\\)\"/\\1/' " \
             "      -e 's/\\\\\\(.\\)/\\1/g' " \
	     "   && cat ~/.surf/bookmarks)\" " \
             "| dmenu -p '"p"' -w $1)\" " \
             "&& xprop -id $1 -f "s" 8u -set "s" \"$prop\"", \
             "surf-setprop", winid, NULL \
             "prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \
             "| sed \"s/^$2(UTF8_STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.surf/bookmarks)\" " \
             "| dmenu -l 10 -p \"$4\" -w $1)\" && " \
             "xprop -id $1 -f $3 8u -set $3 \"$prop\"", \
             "surf-setprop", winid, r, s, p, NULL \
        } \
}



@@ 208,6 207,7 @@ static Key keys[] = {
	{ 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_m,      toggle,     { .i = Style } },
	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_d,      toggle,     { .i = DarkMode } },
};

/* button definitions */

M config.h => config.h +7 -7
@@ 27,6 27,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 },     },


@@ 80,13 81,11 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
/* SETPROP(readprop, setprop, prompt)*/
#define SETPROP(r, s, p) { \
        .v = (const char *[]){ "/bin/sh", "-c", \
             "prop=\"$(printf '%b' \"$(xprop -id $1 "r" " \
             "| sed -e 's/^"r"(UTF8_STRING) = \"\\(.*\\)\"/\\1/' " \
             "      -e 's/\\\\\\(.\\)/\\1/g' " \
	     "   && cat ~/.surf/bookmarks)\" " \
             "| dmenu -p '"p"' -w $1)\" " \
             "&& xprop -id $1 -f "s" 8u -set "s" \"$prop\"", \
             "surf-setprop", winid, NULL \
             "prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \
             "| sed \"s/^$2(UTF8_STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.surf/bookmarks)\" " \
             "| dmenu -l 10 -p \"$4\" -w $1)\" && " \
             "xprop -id $1 -f $3 8u -set $3 \"$prop\"", \
             "surf-setprop", winid, r, s, p, NULL \
        } \
}



@@ 208,6 207,7 @@ static Key keys[] = {
	{ 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_m,      toggle,     { .i = Style } },
	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_d,      toggle,     { .i = DarkMode } },
};

/* button definitions */

M surf.1 => surf.1 +3 -0
@@ 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

M surf.c => surf.c +41 -25
@@ 57,6 57,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;


@@ 285,6 288,7 @@ static ParamName loadcommitted[] = {
//	AccessMicrophone,
//	AccessWebcam,
	CaretBrowsing,
	DarkMode,
	DefaultCharset,
	FontSize,
	FrameFlattening,


@@ 759,7 763,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;



@@ 769,7 772,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:


@@ 778,32 781,37 @@ 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-theme", 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;


@@ 813,21 821,22 @@ 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 */


@@ 844,20 853,20 @@ 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);
		    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;


@@ 869,7 878,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);


@@ 915,8 924,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);
	}



@@ 1115,6 1124,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,


@@ 1228,6 1239,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;
}