[hackers] [PATCH 2/2] Add setstyle()

From: Quentin Rameau <quinq+hackers_AT_fifth.space>
Date: Sat, 31 Oct 2015 12:34:57 +0100

Regroup style uri setting application calls under one function.
---
 surf.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/surf.c b/surf.c
index 55ffd84..3f33e54 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -155,6 +155,7 @@ static void gettogglestat(Client *c);
 static void getpagestat(Client *c);
 static char *geturi(Client *c);
 static const gchar *getstyle(const char *uri);
+static void setstyle(Client *c, const char *style);
 
 static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
 
_AT_@ -663,6 +664,14 @@ getstyle(const char *uri)
 }
 
 void
+setstyle(Client *c, const char *style)
+{
+	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
+
+	g_object_set(G_OBJECT(settings), "user-stylesheet-uri", style, NULL);
+}
+
+void
 handleplumb(Client *c, WebKitWebView *w, const gchar *uri)
 {
 	Arg arg;
_AT_@ -776,7 +785,6 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
 	WebKitWebFrame *frame;
 	WebKitWebDataSource *src;
 	WebKitNetworkRequest *request;
-	WebKitWebSettings *set = webkit_web_view_get_settings(c->view);
 	SoupMessage *msg;
 	char *uri;
 
_AT_@ -793,10 +801,8 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
 		}
 		setatom(c, AtomUri, uri);
 
-		if (enablestyles) {
-			g_object_set(G_OBJECT(set), "user-stylesheet-uri",
-			             getstyle(uri), NULL);
-		}
+		if (enablestyles)
+			setstyle(c, getstyle(uri));
 		break;
 	case WEBKIT_LOAD_FINISHED:
 		c->progress = 100;
_AT_@ -997,11 +1003,6 @@ newclient(void)
 	if (!(ua = getenv("SURF_USERAGENT")))
 		ua = useragent;
 	g_object_set(G_OBJECT(settings), "user-agent", ua, 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);
 	g_object_set(G_OBJECT(settings),
_AT_@ -1018,6 +1019,8 @@ newclient(void)
 	             "default-font-size", defaultfontsize, NULL);
 	g_object_set(G_OBJECT(settings),
 	             "resizable-text-areas", 1, NULL);
+	if (enablestyles)
+		setstyle(c, getstyle("about:blank"));
 
 	/*
 	 * While stupid, CSS specifies that a pixel represents 1/96 of an inch.
_AT_@ -1531,11 +1534,8 @@ togglescrollbars(Client *c, const Arg *arg)
 void
 togglestyle(Client *c, const Arg *arg)
 {
-	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
-
 	enablestyles = !enablestyles;
-	g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
-	             enablestyles ? getstyle(geturi(c)) : "", NULL);
+	setstyle(c, enablestyles ? getstyle(geturi(c)) : "");
 
 	updatetitle(c);
 }
-- 
2.6.2
Received on Sat Oct 31 2015 - 12:34:57 CET

This archive was generated by hypermail 2.3.0 : Sat Oct 31 2015 - 12:36:12 CET