Attached is a patch that enables toggling the user style on/off. It also adds an appropriate letter to the status thing in the title. It uses the key / letter 'm', only because 's' and 'c' (for style / css) are already taken. The patch is against tip.
I use this to switch between a dark style and whatever the website deems fashionable. I think it should probably be applied to the main repo, as it's useful and small and good. If there's no interest in that I could add it to the website instead. Nick
diff --git a/config.def.h b/config.def.h
index da5a08f..bbfb1ed 100644
--- a/config.def.h
+++ b/config.def.h
@@ -83,5 +83,6 @@ static Key keys[] = {
{ MODKEY|GDK_SHIFT_MASK,GDK_i, toggle, { .v = "auto-load-images" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_s, toggle, { .v = "enable-scripts" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_v, toggle, { .v = "enable-plugins" } },
+ { MODKEY|GDK_SHIFT_MASK,GDK_m, togglestyle,{ 0 } },
};
diff --git a/surf.c b/surf.c
index 17f7750..fc61381 100644
--- a/surf.c
+++ b/surf.c
@@ -77,7 +77,7 @@ static GdkNativeWindow embed = 0;
static gboolean showxid = FALSE;
static char winid[64];
static gboolean usingproxy = 0;
-static char togglestat[5];
+static char togglestat[6];
static char pagestat[3];
static void beforerequest(WebKitWebView *w, WebKitWebFrame *f,
@@ -153,6 +153,7 @@ static void stop(Client *c, const Arg *arg);
static void titlechange(WebKitWebView *v, WebKitWebFrame *frame,
const char *title, Client *c);
static void toggle(Client *c, const Arg *arg);
+static void togglestyle(Client *c, const Arg *arg);
static void update(Client *c);
static void updatewinid(Client *c);
static void usage(void);
@@ -1038,6 +1039,7 @@ toggle(Client *c, const Arg *arg) {
static void
gettogglestat(Client *c){
gboolean value;
+ char *uri;
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
g_object_get(G_OBJECT(settings), "enable-caret-browsing",
@@ -1053,7 +1055,10 @@ gettogglestat(Client *c){
g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL);
togglestat[3] = value? 'V': 'v';
- togglestat[4] = '\0';
+ g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
+ togglestat[4] = uri[0] ? 'M': 'm';
+
+ togglestat[5] = '\0';
}
static void
@@ -1183,3 +1188,15 @@ main(int argc, char *argv[]) {
return EXIT_SUCCESS;
}
+static void
+togglestyle(Client *c, const Arg *arg) {
+ WebKitWebSettings *settings;
+ char *uri;
+
+ settings = webkit_web_view_get_settings(c->view);
+ g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL);
+ uri = uri[0] ? g_strdup("") : g_strconcat("file://", stylefile, NULL);
+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
+
+ update(c);
+}
signature.asc
Description: Digital signature
