From 4846c7cefc0a03ac69576ccebdb8e16055c57461 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sun, 11 Apr 2010 14:19:04 +0200 Subject: Break out scrolling code Move the duplicated scrolling code to a function. Signed-off-by: Henrik Rydberg --- src/multitouch.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/multitouch.c b/src/multitouch.c index 012476d..ebc0033 100644 --- a/src/multitouch.c +++ b/src/multitouch.c @@ -180,6 +180,22 @@ static void tickle_button(LocalDevicePtr local, int id) xf86PostButtonEvent(local->dev, FALSE, id, 0, 0, 0); } +static void button_scroll(LocalDevicePtr local, + int btdec, int btinc, + int *scroll, int step, + int delta) +{ + *scroll += delta; + while (*scroll > step) { + tickle_button(local, btinc); + *scroll -= step; + } + while (*scroll < -step) { + tickle_button(local, btdec); + *scroll += step; + } +} + static void handle_gestures(LocalDevicePtr local, const struct Gestures *gs, const struct Capabilities *caps) @@ -201,27 +217,11 @@ static void handle_gestures(LocalDevicePtr local, TRACE2("motion: %d %d\n", gs->dx, gs->dy); } if (GETBIT(gs->type, GS_VSCROLL)) { - vscroll += gs->dy; - while (vscroll > vstep) { - tickle_button(local, 5); - vscroll -= vstep; - } - while (vscroll < -vstep) { - tickle_button(local, 4); - vscroll += vstep; - } + button_scroll(local, 4, 5, &vscroll, vstep, gs->dy); TRACE1("vscroll: %d\n", gs->dy); } if (GETBIT(gs->type, GS_HSCROLL)) { - hscroll += gs->dx; - while (hscroll > hstep) { - tickle_button(local, 7); - hscroll -= hstep; - } - while (hscroll < -hstep) { - tickle_button(local, 6); - hscroll += hstep; - } + button_scroll(local, 6, 7, &hscroll, hstep, gs->dx); TRACE1("hscroll: %d\n", gs->dx); } } -- cgit v1.2.3