[PATCH synaptics 3/4] Factor out delta calculation into a static func.

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 16 17:19:23 PST 2011


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/synaptics.c |  117 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/src/synaptics.c b/src/synaptics.c
index 541dd1c..2201e9f 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -1727,19 +1727,73 @@ get_delta_for_trackstick(SynapticsPrivate *priv, const struct SynapticsHwState *
     *dy = *dy * dtime * para->trackstick_speed;
 }
 
+static void
+get_delta(SynapticsPrivate *priv, const struct SynapticsHwState *hw,
+          edge_type edge, double *dx, double *dy)
+{
+    SynapticsParameters *para = &priv->synpara;
+    double dtime = (hw->millis - HIST(0).millis) / 1000.0;
+    double integral;
+    double tmpf;
+    int x_edge_speed = 0;
+    int y_edge_speed = 0;
+
+    *dx = estimate_delta(hw->x, HIST(0).x, HIST(1).x, HIST(2).x);
+    *dy = estimate_delta(hw->y, HIST(0).y, HIST(1).y, HIST(2).y);
+
+    if ((priv->tap_state == TS_DRAG) || para->edge_motion_use_always) {
+        int minZ = para->edge_motion_min_z;
+        int maxZ = para->edge_motion_max_z;
+        int minSpd = para->edge_motion_min_speed;
+        int maxSpd = para->edge_motion_max_speed;
+        int edge_speed;
+
+        if (hw->z <= minZ) {
+            edge_speed = minSpd;
+        } else if (hw->z >= maxZ) {
+            edge_speed = maxSpd;
+        } else {
+            edge_speed = minSpd + (hw->z - minZ) * (maxSpd - minSpd) / (maxZ - minZ);
+        }
+        if (!priv->synpara.circular_pad) {
+            /* on rectangular pad */
+            if (edge & RIGHT_EDGE) {
+                x_edge_speed = edge_speed;
+            } else if (edge & LEFT_EDGE) {
+                x_edge_speed = -edge_speed;
+            }
+            if (edge & TOP_EDGE) {
+                y_edge_speed = -edge_speed;
+            } else if (edge & BOTTOM_EDGE) {
+                y_edge_speed = edge_speed;
+            }
+        } else if (edge) {
+            /* at edge of circular pad */
+            double relX, relY;
+
+            relative_coords(priv, hw->x, hw->y, &relX, &relY);
+            x_edge_speed = (int)(edge_speed * relX);
+            y_edge_speed = (int)(edge_speed * relY);
+        }
+    }
+
+    /* report edge speed as synthetic motion. Of course, it would be
+     * cooler to report floats than to buffer, but anyway. */
+    tmpf = *dx + x_edge_speed * dtime + priv->frac_x;
+    priv->frac_x = modf(tmpf, &integral);
+    *dx = integral;
+    tmpf = *dy + y_edge_speed * dtime + priv->frac_y;
+    priv->frac_y = modf(tmpf, &integral);
+    *dy = integral;
+}
+
 static int
 ComputeDeltas(SynapticsPrivate *priv, const struct SynapticsHwState *hw,
 	      edge_type edge, int *dxP, int *dyP, Bool inside_area)
 {
-    SynapticsParameters *para = &priv->synpara;
     enum MovingState moving_state;
     double dx, dy;
-    double integral;
     int delay = 1000000000;
-    double tmpf;
-    int x_edge_speed = 0;
-    int y_edge_speed = 0;
-    double dtime = (hw->millis - HIST(0).millis) / 1000.0;
 
     dx = dy = 0;
 
@@ -1779,55 +1833,8 @@ ComputeDeltas(SynapticsPrivate *priv, const struct SynapticsHwState *hw,
 
     if (priv->moving_state == MS_TRACKSTICK)
         get_delta_for_trackstick(priv, hw, &dx, &dy);
-    else if (moving_state == MS_TOUCHPAD_RELATIVE) {
-        dx = estimate_delta(hw->x, HIST(0).x, HIST(1).x, HIST(2).x);
-        dy = estimate_delta(hw->y, HIST(0).y, HIST(1).y, HIST(2).y);
-
-        if ((priv->tap_state == TS_DRAG) || para->edge_motion_use_always) {
-            int minZ = para->edge_motion_min_z;
-            int maxZ = para->edge_motion_max_z;
-            int minSpd = para->edge_motion_min_speed;
-            int maxSpd = para->edge_motion_max_speed;
-            int edge_speed;
-
-            if (hw->z <= minZ) {
-                edge_speed = minSpd;
-            } else if (hw->z >= maxZ) {
-                edge_speed = maxSpd;
-            } else {
-                edge_speed = minSpd + (hw->z - minZ) * (maxSpd - minSpd) / (maxZ - minZ);
-            }
-            if (!priv->synpara.circular_pad) {
-                /* on rectangular pad */
-                if (edge & RIGHT_EDGE) {
-                    x_edge_speed = edge_speed;
-                } else if (edge & LEFT_EDGE) {
-                    x_edge_speed = -edge_speed;
-                }
-                if (edge & TOP_EDGE) {
-                    y_edge_speed = -edge_speed;
-                } else if (edge & BOTTOM_EDGE) {
-                    y_edge_speed = edge_speed;
-                }
-            } else if (edge) {
-                /* at edge of circular pad */
-                double relX, relY;
-
-                relative_coords(priv, hw->x, hw->y, &relX, &relY);
-                x_edge_speed = (int)(edge_speed * relX);
-                y_edge_speed = (int)(edge_speed * relY);
-            }
-        }
-    }
-
-    /* report edge speed as synthetic motion. Of course, it would be
-     * cooler to report floats than to buffer, but anyway. */
-    tmpf = dx + x_edge_speed * dtime + priv->frac_x;
-    priv->frac_x = modf(tmpf, &integral);
-    dx = integral;
-    tmpf = dy + y_edge_speed * dtime + priv->frac_y;
-    priv->frac_y = modf(tmpf, &integral);
-    dy = integral;
+    else if (moving_state == MS_TOUCHPAD_RELATIVE)
+        get_delta(priv, hw, edge, &dx, &dy);
 
 skip:
     priv->count_packet_finger++;
-- 
1.7.3.5



More information about the xorg-devel mailing list