Add a toggle command for the stylefile.

The patch adds some better formatting for the manpage too.

Thanks to Nick <suckless-dev@njw.me.uk> for the toggle patch!
This commit is contained in:
Christoph Lohmann 2013-02-16 16:18:05 +01:00
parent 3e972f8e2a
commit bd5bbb7fc3
3 changed files with 40 additions and 8 deletions

View File

@ -83,5 +83,6 @@ static Key keys[] = {
{ MODKEY|GDK_SHIFT_MASK,GDK_i, toggle, { .v = "auto-load-images" } }, { 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_s, toggle, { .v = "enable-scripts" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_v, toggle, { .v = "enable-plugins" } }, { MODKEY|GDK_SHIFT_MASK,GDK_v, toggle, { .v = "enable-plugins" } },
{ MODKEY|GDK_SHIFT_MASK,GDK_m, togglestyle,{ 0 } },
}; };

26
surf.1
View File

@ -18,10 +18,13 @@ one can point surf to another URI by setting its XProperties.
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-c cookiefile .B \-c cookiefile
Specify the cookiefile to use. Specify the
.I cookiefile
to use.
.TP .TP
.B \-e xid .B \-e xid
Reparents to window specified by xid. Reparents to window specified by
.I xid.
.TP .TP
.B \-i .B \-i
Disable Images Disable Images
@ -33,16 +36,20 @@ Disable the Web Inspector (Developer Tools).
Disable Plugins Disable Plugins
.TP .TP
.B \-r scriptfile .B \-r scriptfile
Specify the user scriptfile. Specify the user
.I scriptfile.
.TP .TP
.B \-s .B \-s
Disable Javascript Disable Javascript
.TP .TP
.B \-t stylefile .B \-t stylefile
Specify the user stylefile. Specify the user
.I stylefile.
.TP .TP
.B \-u useragent .B \-u useragent
Specify the useragent which surf should use. Specify the
.I useragent
which surf should use.
.TP .TP
.B \-v .B \-v
Prints version information to standard output, then exits. Prints version information to standard output, then exits.
@ -129,6 +136,11 @@ Toggle caret browsing.
.B Ctrl\-Shift\-i .B Ctrl\-Shift\-i
Toggle auto-loading of images. Toggle auto-loading of images.
.TP .TP
.B Ctrl\-Shift\-m
Toggle if the
.I stylefile
file should be loaded.
.TP
.B Ctrl\-Shift\-s .B Ctrl\-Shift\-s
Toggle script execution. Toggle script execution.
.TP .TP
@ -139,7 +151,9 @@ Toggle the enabling of plugins on that surf instance.
Toggle fullscreen mode. Toggle fullscreen mode.
.SH ENVIRONMENT .SH ENVIRONMENT
.B SURF_USERAGENT .B SURF_USERAGENT
If this variable is set upon startup, surf will use it as the useragent string If this variable is set upon startup, surf will use it as the
.I useragent
string
.TP .TP
.B http_proxy .B http_proxy
If this variable is set and not empty upon startup, surf will use it as the http proxy If this variable is set and not empty upon startup, surf will use it as the http proxy

21
surf.c
View File

@ -77,7 +77,7 @@ static GdkNativeWindow embed = 0;
static gboolean showxid = FALSE; static gboolean showxid = FALSE;
static char winid[64]; static char winid[64];
static gboolean usingproxy = 0; static gboolean usingproxy = 0;
static char togglestat[5]; static char togglestat[6];
static char pagestat[3]; static char pagestat[3];
static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, 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, static void titlechange(WebKitWebView *v, WebKitWebFrame *frame,
const char *title, Client *c); const char *title, Client *c);
static void toggle(Client *c, const Arg *arg); static void toggle(Client *c, const Arg *arg);
static void togglestyle(Client *c, const Arg *arg);
static void update(Client *c); static void update(Client *c);
static void updatewinid(Client *c); static void updatewinid(Client *c);
static void usage(void); static void usage(void);
@ -1038,6 +1039,7 @@ toggle(Client *c, const Arg *arg) {
static void static void
gettogglestat(Client *c){ gettogglestat(Client *c){
gboolean value; gboolean value;
char *uri;
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
g_object_get(G_OBJECT(settings), "enable-caret-browsing", 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); g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL);
togglestat[3] = value? 'V': 'v'; 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 static void
@ -1183,3 +1188,15 @@ main(int argc, char *argv[]) {
return EXIT_SUCCESS; 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);
}