And because I'm really married to the idea of this going into the
main branch of surf, here's a diff that does the same thing, but
doesn't make Arg a struct, if it should happen to please Tox.
> From: Alex Puterbaugh <[email protected]>
> To: suckless dev <[email protected]>
> Date: Sat, 21 Aug 2010 14:32:17 -0400
> Subject: [dev] [surf] Shortcuts for horizontal scrolling
>
> Hey all,
>
> I've made a small patch that allows you to bind keys for
> horizontal scrolling.
>
> This approach (which imho is the least of many evils) requires
> the Arg union to be a struct, to allow the scroll() function
> to use both .b and .i as arguments.
>
> I think that horizontal scrolling via the keyboard is far from an
> "edge" use case for a web browser that already depends so heavily on
> the keyboard, so I propose that this patch be included in the
> next version of surf.
diff -r dbb565b8d61c config.def.h
--- a/config.def.h Fri Jun 25 09:42:58 2010 +0200
+++ b/config.def.h Sun Aug 22 12:13:48 2010 -0400
@@ -27,14 +27,16 @@
{ 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_h, hscroll, { .i = -1 } },
+ { MODKEY, GDK_l, hscroll, { .i = +1 } },
+ { MODKEY, GDK_j, vscroll, { .i = +1 } },
+ { MODKEY, GDK_k, vscroll, { .i = -1 } },
{ 0, GDK_Escape, stop, { 0 } },
{ MODKEY, GDK_o, source, { 0 } },
{ MODKEY, GDK_g, spawn, SETPROP("_SURF_URI",
"_SURF_GO") },
- { MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND",
"_SURF_FIND") },
+ { MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND",
"_SURF_FIND") },
{ MODKEY, GDK_n, find, { .b = TRUE } },
{ MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } },
};
diff -r dbb565b8d61c surf.c
--- a/surf.c Fri Jun 25 09:42:58 2010 +0200
+++ b/surf.c Sun Aug 22 12:13:48 2010 -0400
@@ -81,6 +81,7 @@
static const char *getcookies(SoupURI *uri);
static char *geturi(Client *c);
void gotheaders(SoupMessage *msg, gpointer user_data);
+void hscroll(Client *c, const Arg *arg);
static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
static void linkhover(WebKitWebView *v, const char* t, const char* l, Client
*c);
@@ -96,7 +97,7 @@
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, gint i);
static void setatom(Client *c, int a, const char *v);
static void setcookie(SoupCookie *c);
static void setup(void);
@@ -108,6 +109,7 @@
static void update(Client *c);
static void updatewinid(Client *c);
static void usage(void);
+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);
@@ -326,6 +328,13 @@
soup_cookies_free(l);
}
+void
+hscroll(Client *c, const Arg *arg) {
+ GtkAdjustment *a;
+ a = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(c->scroll));
+ scroll(a, arg->i);
+}
+
gboolean
initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
Arg arg;
@@ -627,13 +636,11 @@
}
void
-scroll(Client *c, const Arg *arg) {
+scroll(GtkAdjustment *a, gint i) {
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 += gtk_adjustment_get_step_increment(a) * 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);
@@ -778,6 +785,13 @@
}
void
+vscroll(Client *c, const Arg *arg) {
+ GtkAdjustment *a;
+ a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll));
+ scroll(a, arg->i);
+}
+
+void
windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js,
JSObjectRef win, Client *c) {
runscript(frame, js);
}