From 01148684fb65a434c7c5d36251d6bc414dfb1711 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 12 Oct 2018 21:46:50 +0200 Subject: [PATCH] Scroll using js As peer https://stackoverflow.com/a/21861770, all other methods are deprecated. --- config.def.h | 12 ++++++------ surf.c | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config.def.h b/config.def.h index 34265f6..20977db 100644 --- a/config.def.h +++ b/config.def.h @@ -144,12 +144,12 @@ static Key keys[] = { { MODKEY, GDK_KEY_h, navigate, { .i = -1 } }, /* vertical and horizontal scrolling, in viewport percentage */ - { MODKEY, GDK_KEY_j, scrollv, { .i = +10 } }, - { MODKEY, GDK_KEY_k, scrollv, { .i = -10 } }, - { MODKEY, GDK_KEY_space, scrollv, { .i = +50 } }, - { MODKEY, GDK_KEY_b, scrollv, { .i = -50 } }, - { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, - { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, + { MODKEY, GDK_KEY_j, eval, { .v = "window.scrollBy(0, +10);" } }, + { MODKEY, GDK_KEY_k, eval, { .v = "window.scrollBy(0, -10);" } }, + { MODKEY, GDK_KEY_space, eval, { .v = "window.scrollBy(0, +window.innerHeight);" } }, + { MODKEY, GDK_KEY_b, eval, { .v = "window.scrollBy(0, -window.innerHeight);" } }, + { MODKEY, GDK_KEY_i, eval, { .v = "window.scrollBy(+10, 0);" } }, + { MODKEY, GDK_KEY_u, eval, { .v = "window.scrollBy(-10, 0);" } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, diff --git a/surf.c b/surf.c index 2b54e3c..0923688 100644 --- a/surf.c +++ b/surf.c @@ -167,6 +167,7 @@ static void setcert(Client *c, const char *file); static const char *getstyle(const char *uri); static void setstyle(Client *c, const char *file); static void runscript(Client *c); +static void eval(Client *c, const Arg *arg); static void evalscript(Client *c, const char *jsstr, ...); static void updatewinid(Client *c); static void handleplumb(Client *c, const char *uri); @@ -950,6 +951,12 @@ runscript(Client *c) g_free(script); } +void +eval(Client *c, const Arg *arg) +{ + evalscript(c, arg->v, ""); +} + void evalscript(Client *c, const char *jsstr, ...) { -- 2.20.1