[PATCH xf86-input-synaptics v3 04/10] Add cumulative_d{x, y} to SynapticsHwState

Chase Douglas chase.douglas at canonical.com
Thu Feb 23 13:02:19 PST 2012


These values will be used for clickpad press and drag with two fingers.

While the clickpad button is not pressed, cumulative_d{x,y} will match x
and y values. Once the clickpad button is pressed, cumulative_d{x,y}
will be updated with the relative motion of each active touch on the
touchpad. This allows for dragging with one finger while another finger
stays stationary holding the clickpad button down.

This is an easier and less latent approach than trying to guess which
touch was the "dragging" touch.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/eventcomm.c     |   35 +++++++++++++++++++++++++++++++++--
 src/synproto.c      |    2 ++
 src/synproto.h      |    2 ++
 test/fake-symbols.c |    5 +++++
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/src/eventcomm.c b/src/eventcomm.c
index 60be6fe..a1f334b 100644
--- a/src/eventcomm.c
+++ b/src/eventcomm.c
@@ -526,6 +526,18 @@ SynapticsReadEvent(InputInfoPtr pInfo, struct input_event *ev)
     return rc;
 }
 
+static Bool
+EventTouchSlotPreviouslyOpen(SynapticsPrivate *priv, int slot)
+{
+    int i;
+
+    for (i = 0; i < priv->num_active_touches; i++)
+        if (priv->open_slots[i] == slot)
+            return TRUE;
+
+    return FALSE;
+}
+
 static void
 EventProcessTouchEvent(InputInfoPtr pInfo, struct SynapticsHwState *hw,
                        struct input_event *ev)
@@ -566,8 +578,20 @@ EventProcessTouchEvent(InputInfoPtr pInfo, struct SynapticsHwState *hw,
             int map = proto_data->axis_map[ev->code - ABS_MT_TOUCH_MAJOR];
             valuator_mask_set(hw->mt_mask[slot_index], map, ev->value);
             if (slot_index >= 0)
-                valuator_mask_set(proto_data->last_mt_vals[slot_index], map,
-                                  ev->value);
+            {
+                ValuatorMask *mask = proto_data->last_mt_vals[slot_index];
+                int last_val = valuator_mask_get(mask, map);
+
+                if (EventTouchSlotPreviouslyOpen(priv, slot_index))
+                {
+                    if (ev->code == ABS_MT_POSITION_X)
+                        hw->cumulative_dx += ev->value - last_val;
+                    else if (ev->code == ABS_MT_POSITION_Y)
+                        hw->cumulative_dy += ev->value - last_val;
+                }
+
+                valuator_mask_set(mask, map, ev->value);
+            }
         }
     }
 #endif
@@ -609,6 +633,13 @@ EventReadHwState(InputInfoPtr pInfo,
 
     SynapticsResetTouchHwState(hw);
 
+    /* Reset cumulative values if buttons were not previously pressed */
+    if (!hw->left && !hw->right && !hw->middle)
+    {
+        hw->cumulative_dx = hw->x;
+        hw->cumulative_dy = hw->y;
+    }
+
     while (SynapticsReadEvent(pInfo, &ev)) {
 	switch (ev.type) {
 	case EV_SYN:
diff --git a/src/synproto.c b/src/synproto.c
index 0426e8f..e945f1e 100644
--- a/src/synproto.c
+++ b/src/synproto.c
@@ -120,6 +120,8 @@ SynapticsCopyHwState(struct SynapticsHwState *dst,
     dst->x = src->x;
     dst->y = src->y;
     dst->z = src->z;
+    dst->cumulative_dx = src->cumulative_dx;
+    dst->cumulative_dy = src->cumulative_dy;
     dst->numFingers = src->numFingers;
     dst->fingerWidth = src->fingerWidth;
     dst->left = src->left;
diff --git a/src/synproto.h b/src/synproto.h
index 89392ac..29e8f3b 100644
--- a/src/synproto.h
+++ b/src/synproto.h
@@ -53,6 +53,8 @@ struct SynapticsHwState {
     int x;			/* X position of finger */
     int y;			/* Y position of finger */
     int z;			/* Finger pressure */
+    int cumulative_dx;		/* Cumulative delta X for clickpad dragging */
+    int cumulative_dy;		/* Cumulative delta Y for clickpad dragging */
     int numFingers;
     int fingerWidth;
 
diff --git a/test/fake-symbols.c b/test/fake-symbols.c
index 7f3f0ac..65fad46 100644
--- a/test/fake-symbols.c
+++ b/test/fake-symbols.c
@@ -461,6 +461,11 @@ _X_EXPORT void valuator_mask_free(ValuatorMask **mask)
 {
 }
 
+_X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valuator)
+{
+    return 0;
+}
+
 _X_EXPORT void valuator_mask_set(ValuatorMask *mask, int valuator, int data)
 {
 }
-- 
1.7.9



More information about the xorg-devel mailing list