surf

My custom build of surf web browser
Log | Files | Refs | README | LICENSE

commit fe3bd631d4e163e15ab685c22ad70c67f8b94f83
parent 69004b2ff67c5747e3f03fcffad1192741ea9419
Author: Carlos J. Torres <vlaadbrain@gmail.com>
Date:   Thu, 21 Feb 2013 09:59:07 -0500

disable/toggle scrollbars

	* add flag to main
	* add flag to manual
	* add signal handler to block default scrollbar policy
	* add toggle of scrollbars (hacky - but no reload) with a twitch
	* add key map to manual
	* add commandline flag to children surfers
	* update TODO
	* sort stuff alphabetically for the style inquisition

Signed-off-by: Christoph Lohmann <20h@r-36.net>

Diffstat:
MTODO.md | 2+-
Mconfig.def.h | 2++
Msurf.1 | 12+++++++++---
Msurf.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 79 insertions(+), 16 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -2,7 +2,7 @@ * suckless adblocking * integrate the WebKitWebInspector API -* make scrollbars a switch and allow them to be disabled +* replace twitch() with proper gtk calls to make scrollbars reappear * replace webkit with something sane * add video player options * play in plugin diff --git a/config.def.h b/config.def.h @@ -10,6 +10,7 @@ static char *cafile = "/etc/ssl/certs/ca-certificates.crt"; static char *strictssl = FALSE; /* Refuse untrusted SSL connections */ /* Webkit default features */ +static Bool enablescrollbars = TRUE; static Bool enablespatialbrowsing = TRUE; static Bool enableplugins = TRUE; static Bool enablescripts = TRUE; @@ -84,5 +85,6 @@ static Key keys[] = { { 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 } }, + { MODKEY|GDK_SHIFT_MASK,GDK_b, togglescrollbars,{ 0 } }, }; diff --git a/surf.1 b/surf.1 @@ -3,7 +3,7 @@ surf \- simple webkit-based browser .SH SYNOPSIS .B surf -.RB [-ipnsvx] +.RB [-bipnsvx] .RB [-c\ cookiefile] .RB [-e\ xid] .RB [-r\ scriptfile] @@ -17,6 +17,9 @@ which makes it possible to embed it in another application. Furthermore, one can point surf to another URI by setting its XProperties. .SH OPTIONS .TP +.B \-b +Disable Scrollbars +.TP .B \-c cookiefile Specify the .I cookiefile @@ -127,8 +130,8 @@ Copies current URI to primary selection. .B Ctrl\-o Show the sourcecode of the current page. .TP -.B Ctrl\-Shift\-o -Open the Web Inspector (Developer Tools) window for the current page. +.B Ctrl\-Shift\-b +Toggle scrollbars .TP .B Ctrl\-Shift\-c Toggle caret browsing. @@ -141,6 +144,9 @@ Toggle if the .I stylefile file should be loaded. .TP +.B Ctrl\-Shift\-o +Open the Web Inspector (Developer Tools) window for the current page. +.TP .B Ctrl\-Shift\-s Toggle script execution. .TP diff --git a/surf.c b/surf.c @@ -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 togglescrollbars(Client *c, const Arg *arg); static void togglestyle(Client *c, const Arg *arg); static void update(Client *c); static void updatewinid(Client *c); @@ -654,13 +655,9 @@ newclient(void) { c->vbox = gtk_vbox_new(FALSE, 0); gtk_paned_pack1(GTK_PANED(c->pane), c->vbox, TRUE, TRUE); - /* Scrolled Window */ - c->scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), - GTK_POLICY_NEVER, GTK_POLICY_NEVER); - /* Webview */ c->view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c); @@ -698,6 +695,21 @@ newclient(void) { "resource-request-starting", G_CALLBACK(beforerequest), c); + /* Scrolled Window */ + c->scroll = gtk_scrolled_window_new(NULL, NULL); + + frame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(c->view)); + g_signal_connect(G_OBJECT(frame), "scrollbars-policy-changed", + G_CALLBACK(gtk_true), NULL); + + if(!enablescrollbars) { + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), + GTK_POLICY_NEVER, GTK_POLICY_NEVER); + } else { + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + } + /* Arranging */ gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view)); gtk_container_add(GTK_CONTAINER(c->win), c->pane); @@ -718,8 +730,8 @@ newclient(void) { gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); - frame = webkit_web_view_get_main_frame(c->view); runscript(frame); + settings = webkit_web_view_get_settings(c->view); if(!(ua = getenv("SURF_USERAGENT"))) ua = useragent; @@ -778,22 +790,24 @@ newclient(void) { static void newwindow(Client *c, const Arg *arg, gboolean noembed) { guint i = 0; - const char *cmd[10], *uri; + const char *cmd[11], *uri; const Arg a = { .v = (void *)cmd }; char tmp[64]; cmd[i++] = argv0; + if(!enablescrollbars) + cmd[i++] = "-b"; if(embed && !noembed) { cmd[i++] = "-e"; snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed); cmd[i++] = tmp; } - if(!enablescripts) - cmd[i++] = "-s"; - if(!enableplugins) - cmd[i++] = "-p"; if(!loadimages) cmd[i++] = "-i"; + if(!enableplugins) + cmd[i++] = "-p"; + if(!enablescripts) + cmd[i++] = "-s"; if(showxid) cmd[i++] = "-x"; cmd[i++] = "--"; @@ -1048,6 +1062,44 @@ toggle(Client *c, const Arg *arg) { } static void +twitch(Client *c, const Arg *arg) { + GtkAdjustment *a; + gdouble v; + + a = gtk_scrolled_window_get_vadjustment( + GTK_SCROLLED_WINDOW(c->scroll)); + + v = gtk_adjustment_get_value(a); + + v += arg->i; + + v = MAX(v, 0.0); + v = MIN(v, gtk_adjustment_get_upper(a) - + gtk_adjustment_get_page_size(a)); + gtk_adjustment_set_value(a, v); +} + +static void +togglescrollbars(Client *c, const Arg *arg) { + GtkPolicyType vspolicy; + Arg a; + + gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(c->scroll), NULL, &vspolicy); + + if(vspolicy == GTK_POLICY_AUTOMATIC) { + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), + GTK_POLICY_NEVER, GTK_POLICY_NEVER); + } else { + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + a.i = +1; + twitch(c, &a); + a.i = -1; + twitch(c, &a); + } +} + +static void togglestyle(Client *c, const Arg *arg) { WebKitWebSettings *settings; char *uri; @@ -1128,7 +1180,7 @@ updatewinid(Client *c) { static void usage(void) { - die("usage: %s [-inpsvx] [-c cookiefile] [-e xid] [-r scriptfile]" + die("usage: %s [-binpsvx] [-c cookiefile] [-e xid] [-r scriptfile]" " [-t stylefile] [-u useragent] [uri]\n", basename(argv0)); } @@ -1162,6 +1214,9 @@ main(int argc, char *argv[]) { /* command line args */ ARGBEGIN { + case 'b': + enablescrollbars = 0; + break; case 'c': cookiefile = EARGF(usage()); break;