From 2edf3757f2b7adf21b2228c5436cd93c8858c00c Mon Sep 17 00:00:00 2001
From: Alyssa Hung <ahung@isisview.org>
Date: Fri, 13 Apr 2012 01:04:38 -0400
Subject: [PATCH synaptics] Support inverted scroll direction.

This patch allows scroll direction to be inverted by allowing
VertScrollDelta and HorizScrollDelta to be set to negative values. This
enables behaviour that is consistent with modern touchscreen devices,
where the content scrolls in the same direction as the user's finger
movement.

Signed-off-by: Alyssa Hung <ahung@isisview.org>
---
 man/synaptics.man |    3 +++
 src/synaptics.c   |    4 ++--
 tools/synclient.c |    4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/man/synaptics.man b/man/synaptics.man
index 864a95f..2cbe50e 100644
--- a/man/synaptics.man
+++ b/man/synaptics.man
@@ -634,6 +634,9 @@ HorizScrollDelta parameters.
 To disable vertical or horizontal scrolling, set VertScrollDelta or
 HorizScrollDelta to zero.
 .
+To invert the direction of vertical or horizontal scrolling, set
+VertScrollDelta or HorizScrollDelta to a negative value.
+.
 .LP
 Acceleration is mostly handled outside the driver, thus the driver will
 translate MinSpeed into constant deceleration and adapt MaxSpeed at
diff --git a/src/synaptics.c b/src/synaptics.c
index f07fd13..6050ab6 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -2559,14 +2559,14 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 
     if (priv->vert_scroll_edge_on || priv->vert_scroll_twofinger_on) {
 	/* + = down, - = up */
-	if (para->scroll_dist_vert > 0 && hw->y != priv->scroll.last_y) {
+	if (para->scroll_dist_vert != 0 && hw->y != priv->scroll.last_y) {
 	    priv->scroll.delta_y += (hw->y - priv->scroll.last_y);
 	    priv->scroll.last_y = hw->y;
 	}
     }
     if (priv->horiz_scroll_edge_on || priv->horiz_scroll_twofinger_on) {
 	/* + = right, - = left */
-	if (para->scroll_dist_horiz > 0 && hw->x != priv->scroll.last_x) {
+	if (para->scroll_dist_horiz != 0 && hw->x != priv->scroll.last_x) {
 	    priv->scroll.delta_x += (hw->x - priv->scroll.last_x);
 	    priv->scroll.last_x = hw->x;
 	}
diff --git a/tools/synclient.c b/tools/synclient.c
index 942312a..2535700 100644
--- a/tools/synclient.c
+++ b/tools/synclient.c
@@ -90,8 +90,8 @@ static struct Parameter params[] = {
     {"EmulateMidButtonTime",  PT_INT,    0, 1000,  SYNAPTICS_PROP_MIDDLE_TIMEOUT,32,	0},
     {"EmulateTwoFingerMinZ",  PT_INT,    0, 1000,  SYNAPTICS_PROP_TWOFINGER_PRESSURE,	32,	0},
     {"EmulateTwoFingerMinW",  PT_INT,    0, 15,    SYNAPTICS_PROP_TWOFINGER_WIDTH,	32,	0},
-    {"VertScrollDelta",       PT_INT,    0, 1000,  SYNAPTICS_PROP_SCROLL_DISTANCE,	32,	0},
-    {"HorizScrollDelta",      PT_INT,    0, 1000,  SYNAPTICS_PROP_SCROLL_DISTANCE,	32,	1},
+    {"VertScrollDelta",       PT_INT,    -1000, 1000,  SYNAPTICS_PROP_SCROLL_DISTANCE,	32,	0},
+    {"HorizScrollDelta",      PT_INT,    -1000, 1000,  SYNAPTICS_PROP_SCROLL_DISTANCE,	32,	1},
     {"VertEdgeScroll",        PT_BOOL,   0, 1,     SYNAPTICS_PROP_SCROLL_EDGE,	8,	0},
     {"HorizEdgeScroll",       PT_BOOL,   0, 1,     SYNAPTICS_PROP_SCROLL_EDGE,	8,	1},
     {"CornerCoasting",        PT_BOOL,   0, 1,     SYNAPTICS_PROP_SCROLL_EDGE,	8,	2},
-- 
1.7.10

