From dbcfb5dec2de71fe9f647edafbc0e3b11e85b97f Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Sun, 16 Jun 2019 22:45:30 +0200 Subject: [PATCH] Fix negative values in scrollh()/scrollv() Pass a `-' or `+' character as a sign for `h' and `v' messages to also honor possible negative values. --- libsurf-webext.c | 8 ++++---- surf.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsurf-webext.c b/libsurf-webext.c index ec9a235..a1a9280 100644 --- a/libsurf-webext.c +++ b/libsurf-webext.c @@ -87,18 +87,18 @@ readpipe(GIOChannel *s, GIOCondition c, gpointer unused) switch (msg[2]) { case 'h': - if (msgsz != 4) + if (msgsz != 5) return TRUE; ww = webkit_dom_dom_window_get_inner_width(view); webkit_dom_dom_window_scroll_by(view, - (ww / 100) * msg[3], 0); + (ww / 100) * (msg[3] == '-' ? -1 : +1) * msg[4], 0); break; case 'v': - if (msgsz != 4) + if (msgsz != 5) return TRUE; wh = webkit_dom_dom_window_get_inner_height(view); webkit_dom_dom_window_scroll_by(view, - 0, (wh / 100) * msg[3]); + 0, (wh / 100) * (msg[3] == '-' ? -1 : +1) * msg[4]); break; } diff --git a/surf.c b/surf.c index 2b54e3c..e55dc26 100644 --- a/surf.c +++ b/surf.c @@ -1848,8 +1848,8 @@ msgext(Client *c, char type, const Arg *a) static char msg[MSGBUFSZ]; int ret; - if ((ret = snprintf(msg, sizeof(msg), "%c%c%c%c", - 4, c->pageid, type, a->i)) + if ((ret = snprintf(msg, sizeof(msg), "%c%c%c%c%c", + 5, c->pageid, type, a->i >= 0 ? '+' : '-', abs(a->i))) >= sizeof(msg)) { fprintf(stderr, "surf: message too long: %d\n", ret); return; -- 2.21.0