Howdy, folks,

I'm a new subscriber, and thought I'd start with a patch.
The attached patch adds horizontal scrolling to surf, mainly
so that it can be bound to a key aside from the arrow keys.

The function `scroll()' has been renamed to `vscroll()', and
a new function called `hscroll()' has been added.

As a warning, to keep the scrolling keybinds consistent
(left on l, right on h), navigate() keybinds have been moved
to MODKEY+b for backwards navigation & MODKEY+f for forwards
navigation.

Thanks a lot, and I hope this is useful.

Ivy Foster

diff -r 4fe78ffcd81e config.def.h
--- a/config.def.h	Tue May 25 10:38:23 2010 +0200
+++ b/config.def.h	Tue May 25 16:35:38 2010 -0500
@@ -23,10 +23,12 @@
     { MODKEY|GDK_SHIFT_MASK,GDK_j,      zoom,       { .i = -1 } },
     { MODKEY|GDK_SHIFT_MASK,GDK_k,      zoom,       { .i = +1 } },
     { 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_f,      navigate,   { .i = +1 } },
+    { MODKEY,               GDK_b,      navigate,   { .i = -1 } },
+    { MODKEY,               GDK_j,      vscroll,    { .i = +1 } },
+    { MODKEY,               GDK_k,      vscroll,    { .i = -1 } },
+    { MODKEY,               GDK_l,      hscroll,    { .i = +1 } },
+    { MODKEY,               GDK_h,      hscroll,    { .i = -1 } },
     { 0,                    GDK_Escape, stop,       { 0 } },
     { MODKEY,               GDK_o,      source,     { 0 } },
     { MODKEY,               GDK_g,      spawn,      SETPROP("_SURF_URI", "_SURF_GO") },
diff -r 4fe78ffcd81e surf.1
--- a/surf.1	Tue May 25 10:38:23 2010 +0200
+++ b/surf.1	Tue May 25 16:35:38 2010 -0500
@@ -39,10 +39,10 @@
 .B Escape
 Stops loading current page or stops download.
 .TP
-.B Ctrl\-h
+.B Ctrl\-b
 Walks back the history.
 .TP
-.B Ctrl\-l
+.B Ctrl\-f
 Walks forward the history.
 .TP
 .B Ctrl\-k
@@ -51,6 +51,12 @@
 .B Ctrl\-j
 Scrolls page downwards.
 .TP
+.B Ctrl\-h
+Scrolls page left.
+.TP
+.B Ctrl\-l
+Scrolls page right.
+.TP
 .B Ctrl\-Shift\-k
 Zooms page in.
 .TP
diff -r 4fe78ffcd81e surf.c
--- a/surf.c	Tue May 25 10:38:23 2010 +0200
+++ b/surf.c	Tue May 25 16:35:38 2010 -0500
@@ -82,6 +82,7 @@
 static char *geturi(Client *c);
 void gotheaders(SoupMessage *msg, gpointer user_data);
 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
+static void hscroll(Client *c, const Arg *arg);
 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
 static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
 static void loaduri(Client *c, const Arg *arg);
@@ -95,7 +96,6 @@
 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 setatom(Client *c, int a, const char *v);
 static void setcookie(SoupCookie *c);
 static void setup(void);
@@ -107,6 +107,7 @@
 static void update(Client *c);
 static void updatewinid(Client *c);
 static void usage(void);
+static void vscroll(Client *c, const Arg *arg);
 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c);
 static void zoom(Client *c, const Arg *arg);
 
@@ -328,6 +329,19 @@
 	soup_cookies_free(l);
 }
 
+void
+hscroll(Client *c, const Arg *arg) {
+	gdouble h;
+	GtkAdjustment *a;
+
+	a = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(c->scroll));
+	h = gtk_adjustment_get_value(a);
+	h += gtk_adjustment_get_step_increment(a) * arg->i;
+	h = MAX(h, 0.0);
+	h = MIN(h, gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a));
+	gtk_adjustment_set_value(a, h);
+}
+
 gboolean
 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
 	guint i;
@@ -616,19 +630,6 @@
 }
 
 void
-scroll(Client *c, 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;
-	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
 setcookie(SoupCookie *c) {
 	int lock;
 
@@ -768,6 +769,19 @@
 }
 
 void
+vscroll(Client *c, 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;
+	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
 windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
 	runscript(frame, js);
 }

Reply via email to