Hi, I am posting a patch against tip which lies on the border to caprice and code bloat, but these changes proved very useful to me in the last months. That's why I'd love to see some of them accepted.
- toggle() boolean properties of Webkit (examples in the config) - scroll uses a heuristic in passing integer parameter borrowed from meillo, I guess, and extended to scroll a page up/down or to the begin/end of document. Scrolling vertically and horizontally differs just in the GtkAdjustment used. So I've put them together. Horizontal scroll is very useful on many (broken) sites when you have a small screen. - setting custom style I found useful for the frequent cases that I read long texts of insane color on insane background burning my eyes. The style file being sth like * {background:#333333 !important; text:#eeeeee !important;} - the key bindings in the patch are not ok but I ran out of ideas. Couldn't post my original ones, since they don't conform to the main line, e.g. I have hjkl for scrolling, HL for navigation, gG for begin/end of document, Space/Shift|Space for page down/up, etc. Thanks to everybody contributing to surf. Hope you find something useful. cheers, -- stanio_
diff -r c7c0e3c25efb config.def.h --- a/config.def.h Tue May 18 14:20:24 2010 +0200 +++ b/config.def.h Thu May 20 11:03:36 2010 +0200 @@ -25,10 +25,19 @@ { MODKEY|GDK_SHIFT_MASK,GDK_i, zoom, { .i = 0 } }, { MODKEY, GDK_l, navigate, { .i = +1 } }, { MODKEY, GDK_h, navigate, { .i = -1 } }, - { MODKEY, GDK_j, scroll, { .i = +1 } }, - { MODKEY, GDK_k, scroll, { .i = -1 } }, + { MODKEY, GDK_j, scroll_v, { .i = +1 } }, + { MODKEY, GDK_k, scroll_v, { .i = -1 } }, + { MODKEY, GDK_space, scroll_v, { .i = +10000 } }, + { MODKEY, GDK_b, scroll_v, { .i = +20000 } }, + { MODKEY|GDK_SHIFT_MASK,GDK_h, scroll_h, { .i = -1 } }, + { MODKEY|GDK_SHIFT_MASK,GDK_l, scroll_h, { .i = +1 } }, { 0, GDK_Escape, stop, { 0 } }, + { MODKEY, GDK_v, toggle, { .v = "enable-plugins" } }, + { MODKEY, GDK_I, toggle, { .v = "auto-load-images" } }, + { MODKEY, GDK_c, toggle, { .v = "enable-caret-browsing" } }, { MODKEY, GDK_o, source, { 0 } }, + { MODKEY, GDK_t, setstyle, { .v = "/home/stanio/.surf/text_style.css" } }, + { MODKEY|GDK_SHIFT_MASK,GDK_t, setstyle, { .v = (const char *)NULL} }, { MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, { MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, { MODKEY, GDK_n, find, { .b = TRUE } }, diff -r c7c0e3c25efb surf.c --- a/surf.c Tue May 18 14:20:24 2010 +0200 +++ b/surf.c Thu May 20 11:03:36 2010 +0200 @@ -96,15 +96,19 @@ static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c); static void reload(Client *c, const Arg *arg); static void resize(GtkWidget *w, GtkAllocation *a, Client *c); -static void scroll(Client *c, const Arg *arg); +static void scroll(GtkAdjustment *a, const Arg *arg); +static void scroll_h(Client *c, const Arg *arg); +static void scroll_v(Client *c, const Arg *arg); static void setatom(Client *c, int a, const char *v); static void setcookie(SoupCookie *c); +static void setstyle(Client *c, const Arg *arg); static void setup(void); static void sigchld(int unused); static void source(Client *c, const Arg *arg); static void spawn(Client *c, const Arg *arg); 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 update(Client *c); static void updatewinid(Client *c); static void usage(void); @@ -634,19 +638,37 @@ } void -scroll(Client *c, const Arg *arg) { +scroll(GtkAdjustment *a, const Arg *arg) { gdouble v; - GtkAdjustment *a; - a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll)); v = gtk_adjustment_get_value(a); - v += gtk_adjustment_get_step_increment(a) * arg->i; + switch (arg->i){ + case +10000: + case -10000: + v += gtk_adjustment_get_page_increment(a) * (arg->i / 10000); break; + case +20000: + case -20000: + default: + v += gtk_adjustment_get_step_increment(a) * 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); } void +scroll_h(Client *c, const Arg *arg) { + scroll(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(c->scroll)), arg); +} + +void +scroll_v(Client *c, const Arg *arg) { + scroll(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll)), arg); +} + + + +void setcookie(SoupCookie *c) { int lock; @@ -674,6 +696,17 @@ } void +setstyle(Client *c, const Arg *arg){ + WebKitWebSettings *settings; + char *uri, *customstylefile; + + customstylefile = arg->v==NULL?stylefile:(char *)arg->v; + settings = webkit_web_view_get_settings(c->view); + uri = g_strconcat("file://", customstylefile, NULL); + g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); +} + +void setup(void) { char *proxy; char *new_proxy; @@ -758,6 +791,18 @@ update(c); } + +void +toggle(Client *c, const Arg *arg) { + WebKitWebSettings *settings; + settings = webkit_web_view_get_settings(c->view); + char *name = (char *)arg->v; + gboolean value; + + g_object_get(G_OBJECT(settings), name, &value, NULL); + g_object_set(G_OBJECT(settings), name, !value, NULL); +} + void update(Client *c) { char *t;