[dev] [surf] [PATCH] fix stylesheet interna.

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Tue, 20 Jan 2015 16:13:31 +0100

* no more segfault when running `surf -m`
* allow to enable custom styles after `surf -m` with mod+shift+m
* use enablestyles instead of the webkit-setting, which clears things up a bit
---
 surf.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/surf.c b/surf.c
index ce8fce8..007e1ea 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -564,6 +564,9 @@ static gchar *
 getstyle(const char *uri) {
 	int i;
 
+	if(stylefile != NULL)
+		return g_strconcat("file://", stylefile, NULL);
+
 	for(i = 0; i < LENGTH(styles); i++) {
 		if(styles[i].regex && !regexec(&(styles[i].re), uri, 0,
 					NULL, 0)) {
_AT_@ -695,7 +698,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
 		}
 		setatom(c, AtomUri, uri);
 
-		if(stylefile == NULL && enablestyles) {
+		if(enablestyles) {
 			g_object_set(G_OBJECT(set), "user-stylesheet-uri",
 					getstyle(uri), NULL);
 		}
_AT_@ -761,7 +764,7 @@ newclient(void) {
 	GdkGeometry hints = { 1, 1 };
 	GdkScreen *screen;
 	gdouble dpi;
-	char *uri = NULL, *ua;
+	char *ua;
 
 	if(!(c = calloc(1, sizeof(Client))))
 		die("Cannot malloc!\n");
_AT_@ -891,9 +894,9 @@ newclient(void) {
 	if(!(ua = getenv("SURF_USERAGENT")))
 		ua = useragent;
 	g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
-	if (stylefile != NULL) {
-		uri = g_strconcat("file://", stylefile, NULL);
-		g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
+	if (enablestyles) {
+		g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
+					 getstyle("about:blank"), NULL);
 	}
 	g_object_set(G_OBJECT(settings), "auto-load-images", loadimages,
 			NULL);
_AT_@ -949,9 +952,6 @@ newclient(void) {
 		fullscreen(c, NULL);
 	}
 
-	if(stylefile != NULL)
-		g_free(uri);
-
 	setatom(c, AtomFind, "");
 	setatom(c, AtomUri, "about:blank");
 	if(hidebackground)
_AT_@ -1183,7 +1183,7 @@ setup(void) {
 	scriptfile = buildpath(scriptfile);
 	cachefolder = buildpath(cachefolder);
 	styledir = buildpath(styledir);
-	if(stylefile == NULL && enablestyles) {
+	if(stylefile == NULL) {
 		for(i = 0; i < LENGTH(styles); i++) {
 			if(regcomp(&(styles[i].re), styles[i].regex,
 						REG_EXTENDED)) {
_AT_@ -1377,13 +1377,8 @@ togglestyle(Client *c, const Arg *arg) {
 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
 	char *uri;
 
-	g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
-	if(stylefile == NULL && enablestyles) {
-		uri = (uri && uri[0])? g_strdup("") : getstyle(geturi(c));
-	} else {
-		uri = uri[0]? g_strdup("") : g_strconcat("file://",
-				stylefile, NULL);
-	}
+	enablestyles = !enablestyles;
+	uri = enablestyles ? getstyle(geturi(c)) : g_strdup("");
 	g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
 
 	updatetitle(c);
_AT_@ -1392,7 +1387,6 @@ togglestyle(Client *c, const Arg *arg) {
 static void
 gettogglestat(Client *c){
 	gboolean value;
-	char *uri;
 	int p = 0;
 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
 
_AT_@ -1415,8 +1409,7 @@ gettogglestat(Client *c){
 	g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL);
 	togglestat[p++] = value? 'V': 'v';
 
-	g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
-	togglestat[p++] = (uri && uri[0]) ? 'M': 'm';
+	togglestat[p++] = enablestyles ? 'M': 'm';
 
 	togglestat[p] = '\0';
 }
-- 
2.0.5
Received on Tue Jan 20 2015 - 16:13:31 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 20 2015 - 16:24:13 CET