fix stylesheet interna.
* 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 Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
		
							parent
							
								
									344efec3fb
								
							
						
					
					
						commit
						90de5cdd15
					
				
							
								
								
									
										31
									
								
								surf.c
								
								
								
								
							
							
						
						
									
										31
									
								
								surf.c
								
								
								
								
							|  | @ -573,6 +573,9 @@ static gchar * | ||||||
| getstyle(const char *uri) { | getstyle(const char *uri) { | ||||||
| 	int i; | 	int i; | ||||||
| 
 | 
 | ||||||
|  | 	if(stylefile != NULL) | ||||||
|  | 		return g_strconcat("file://", stylefile, NULL); | ||||||
|  | 
 | ||||||
| 	for(i = 0; i < LENGTH(styles); i++) { | 	for(i = 0; i < LENGTH(styles); i++) { | ||||||
| 		if(styles[i].regex && !regexec(&(styles[i].re), uri, 0, | 		if(styles[i].regex && !regexec(&(styles[i].re), uri, 0, | ||||||
| 					NULL, 0)) { | 					NULL, 0)) { | ||||||
|  | @ -704,7 +707,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { | ||||||
| 		} | 		} | ||||||
| 		setatom(c, AtomUri, uri); | 		setatom(c, AtomUri, uri); | ||||||
| 
 | 
 | ||||||
| 		if(stylefile == NULL && enablestyles) { | 		if(enablestyles) { | ||||||
| 			g_object_set(G_OBJECT(set), "user-stylesheet-uri", | 			g_object_set(G_OBJECT(set), "user-stylesheet-uri", | ||||||
| 					getstyle(uri), NULL); | 					getstyle(uri), NULL); | ||||||
| 		} | 		} | ||||||
|  | @ -770,7 +773,7 @@ newclient(void) { | ||||||
| 	GdkGeometry hints = { 1, 1 }; | 	GdkGeometry hints = { 1, 1 }; | ||||||
| 	GdkScreen *screen; | 	GdkScreen *screen; | ||||||
| 	gdouble dpi; | 	gdouble dpi; | ||||||
| 	char *uri = NULL, *ua; | 	char *ua; | ||||||
| 
 | 
 | ||||||
| 	if(!(c = calloc(1, sizeof(Client)))) | 	if(!(c = calloc(1, sizeof(Client)))) | ||||||
| 		die("Cannot malloc!\n"); | 		die("Cannot malloc!\n"); | ||||||
|  | @ -900,9 +903,9 @@ newclient(void) { | ||||||
| 	if(!(ua = getenv("SURF_USERAGENT"))) | 	if(!(ua = getenv("SURF_USERAGENT"))) | ||||||
| 		ua = useragent; | 		ua = useragent; | ||||||
| 	g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); | 	g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); | ||||||
| 	if (stylefile != NULL) { | 	if (enablestyles) { | ||||||
| 		uri = g_strconcat("file://", stylefile, NULL); | 		g_object_set(G_OBJECT(settings), "user-stylesheet-uri", | ||||||
| 		g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); | 					 getstyle("about:blank"), NULL); | ||||||
| 	} | 	} | ||||||
| 	g_object_set(G_OBJECT(settings), "auto-load-images", loadimages, | 	g_object_set(G_OBJECT(settings), "auto-load-images", loadimages, | ||||||
| 			NULL); | 			NULL); | ||||||
|  | @ -958,9 +961,6 @@ newclient(void) { | ||||||
| 		fullscreen(c, NULL); | 		fullscreen(c, NULL); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(stylefile != NULL) |  | ||||||
| 		g_free(uri); |  | ||||||
| 
 |  | ||||||
| 	setatom(c, AtomFind, ""); | 	setatom(c, AtomFind, ""); | ||||||
| 	setatom(c, AtomUri, "about:blank"); | 	setatom(c, AtomUri, "about:blank"); | ||||||
| 	if(hidebackground) | 	if(hidebackground) | ||||||
|  | @ -1192,7 +1192,7 @@ setup(void) { | ||||||
| 	scriptfile = buildpath(scriptfile); | 	scriptfile = buildpath(scriptfile); | ||||||
| 	cachefolder = buildpath(cachefolder); | 	cachefolder = buildpath(cachefolder); | ||||||
| 	styledir = buildpath(styledir); | 	styledir = buildpath(styledir); | ||||||
| 	if(stylefile == NULL && enablestyles) { | 	if(stylefile == NULL) { | ||||||
| 		for(i = 0; i < LENGTH(styles); i++) { | 		for(i = 0; i < LENGTH(styles); i++) { | ||||||
| 			if(regcomp(&(styles[i].re), styles[i].regex, | 			if(regcomp(&(styles[i].re), styles[i].regex, | ||||||
| 						REG_EXTENDED)) { | 						REG_EXTENDED)) { | ||||||
|  | @ -1386,13 +1386,8 @@ togglestyle(Client *c, const Arg *arg) { | ||||||
| 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); | 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); | ||||||
| 	char *uri; | 	char *uri; | ||||||
| 
 | 
 | ||||||
| 	g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL); | 	enablestyles = !enablestyles; | ||||||
| 	if(stylefile == NULL && enablestyles) { | 	uri = enablestyles ? getstyle(geturi(c)) : g_strdup(""); | ||||||
| 		uri = (uri && uri[0])? g_strdup("") : getstyle(geturi(c)); |  | ||||||
| 	} else { |  | ||||||
| 		uri = uri[0]? g_strdup("") : g_strconcat("file://", |  | ||||||
| 				stylefile, NULL); |  | ||||||
| 	} |  | ||||||
| 	g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); | 	g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); | ||||||
| 
 | 
 | ||||||
| 	updatetitle(c); | 	updatetitle(c); | ||||||
|  | @ -1401,7 +1396,6 @@ togglestyle(Client *c, const Arg *arg) { | ||||||
| static void | static void | ||||||
| gettogglestat(Client *c){ | gettogglestat(Client *c){ | ||||||
| 	gboolean value; | 	gboolean value; | ||||||
| 	char *uri; |  | ||||||
| 	int p = 0; | 	int p = 0; | ||||||
| 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); | 	WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); | ||||||
| 
 | 
 | ||||||
|  | @ -1424,8 +1418,7 @@ gettogglestat(Client *c){ | ||||||
| 	g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); | 	g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); | ||||||
| 	togglestat[p++] = value? 'V': 'v'; | 	togglestat[p++] = value? 'V': 'v'; | ||||||
| 
 | 
 | ||||||
| 	g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL); | 	togglestat[p++] = enablestyles ? 'M': 'm'; | ||||||
| 	togglestat[p++] = (uri && uri[0]) ? 'M': 'm'; |  | ||||||
| 
 | 
 | ||||||
| 	togglestat[p] = '\0'; | 	togglestat[p] = '\0'; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue