Add support for the metrics gesture

This patch adds support for the metrics gesture (GestureMetrics) in
cmt. The metrics gesture is used to expose vital stats that we
would like to catch with the UMA system in Chrome. We currently catches
the ground noise pattern and send them with the metrics gesture.

BUG=chromium:237683
TEST=Based on https://gerrit.chromium.org/gerrit/55727/
On link:
$ DISPLAY=:0.0 xinput list-props 11 | grep "Metrics"

One should see:
        Metrics Noisy Ground Distance (403):    10.000000
        Metrics Noisy Ground Time (404):        0.100000

To watch for the metrics gesture, use command:
$ DISPLAY=:0.0 xinput test-xi2 11 | grep "9:"

With the default distance threshold (10.0), it should be impossible
to trigger the check. Try to quickly move finger on the touchpad and
make sure no line shows up. Now, change the threshold value to 0.1 with
the following line:

$ DISPLAY=:0.0 xinput set-float-prop 11 403 0.1

Quickly move finger back and forth on the touchpad again, one should
now see various lines coming up with the above watch command:

$ DISPLAY=:0.0 xinput test-xi2 11 | grep "9:"
                      Detail for Valuator 9:
                9: 0.00 (0.00)
                9: 0.00 (0.00)
                9: 0.00 (0.00)
                9: 0.00 (0.00)
                ...

CQ-DEPEND=I5e6c9bd5489f4e5aeb90e0d7d7f48cd3e068d08f

Change-Id: Ib30c43f55439a5bb45e0c983f8a8d5057e056048
Reviewed-on: https://gerrit.chromium.org/gerrit/55729
Reviewed-by: Andrew de los Reyes <[email protected]>
Commit-Queue: Tai-Hsu Lin <[email protected]>
Tested-by: Tai-Hsu Lin <[email protected]>
diff --git a/src/cmt.c b/src/cmt.c
index b9730a2..3f6beb1 100644
--- a/src/cmt.c
+++ b/src/cmt.c
@@ -34,6 +34,10 @@
 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VX   "Abs Dbl Fling X Velocity"
 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VY   "Abs Dbl Fling Y Velocity"
 
+#define AXIS_LABEL_PROP_ABS_METRICS_TYPE      "Abs Metrics Type"
+#define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1 "Abs Dbl Metrics Data 1"
+#define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2 "Abs Dbl Metrics Data 2"
+
 #define AXIS_LABEL_PROP_ABS_DBL_START_TIME "Abs Dbl Start Timestamp"
 #define AXIS_LABEL_PROP_ABS_DBL_END_TIME   "Abs Dbl End Timestamp"
 
@@ -362,6 +366,9 @@
         AXIS_LABEL_PROP_ABS_FLING_STATE,
         AXIS_LABEL_PROP_ABS_DBL_FLING_VX,
         AXIS_LABEL_PROP_ABS_DBL_FLING_VY,
+        AXIS_LABEL_PROP_ABS_METRICS_TYPE,
+        AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1,
+        AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2,
         AXIS_LABEL_PROP_ABS_DBL_START_TIME,
         AXIS_LABEL_PROP_ABS_DBL_END_TIME,
         AXIS_LABEL_PROP_ABS_FINGER_COUNT
diff --git a/src/cmt.h b/src/cmt.h
index 81e1903..1b630b9 100644
--- a/src/cmt.h
+++ b/src/cmt.h
@@ -46,6 +46,9 @@
     CMT_AXIS_FLING_STATE,
     CMT_AXIS_DBL_FLING_VX,
     CMT_AXIS_DBL_FLING_VY,
+    CMT_AXIS_METRICS_TYPE,
+    CMT_AXIS_METRICS_DATA1,
+    CMT_AXIS_METRICS_DATA2,
     CMT_AXIS_DBL_START_TIME,
     CMT_AXIS_DBL_END_TIME,
     CMT_AXIS_FINGER_COUNT
diff --git a/src/gesture.c b/src/gesture.c
index 68e1e3f..91040c3 100644
--- a/src/gesture.c
+++ b/src/gesture.c
@@ -361,6 +361,19 @@
                 pinch->dz, pinch->ordinal_dz);
             break;
         }
+        case kGestureTypeMetrics: {
+            const GestureMetrics* metrics = &gesture->details.metrics;
+            DBG(info, "Gesture Metrics: [%f, %f] type=%d\n",
+                metrics->data[0], metrics->data[1], metrics->type);
+            valuator_mask_set_double(mask, CMT_AXIS_METRICS_DATA1,
+                metrics->data[0]);
+            valuator_mask_set_double(mask, CMT_AXIS_METRICS_DATA2,
+                metrics->data[1]);
+            valuator_mask_set(mask, CMT_AXIS_METRICS_TYPE, metrics->type);
+            SetTimeValues(mask, gesture, dev, TRUE);
+            xf86PostMotionEventM(dev, TRUE, mask);
+            break;
+        }
         default:
             ERR(info, "Unrecognized gesture type (%u)\n", gesture->type);
             break;