[PATCH xf86-input-synaptics 5/8] Don't report motion inside soft-button areas

Hans de Goede hdegoede at redhat.com
Fri Feb 21 01:31:41 PST 2014


Unless the motion has started outside the soft-button area.

Note that we must start reporting motions regardless of whether we think we're
in the button area or not as soon as we've switched to using cumulative
coordinates, since then the coordinates are no longer absolute.

This fixes the reporting of unintended motion just before a click in a soft
button area which sometimes causes mis-clicks.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/synaptics.c    | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/synapticsstr.h |  1 +
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/src/synaptics.c b/src/synaptics.c
index d6064b0..84e704b 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -1043,6 +1043,7 @@ SynapticsReset(SynapticsPrivate * priv)
     priv->count_packet_finger = 0;
     priv->finger_state = FS_UNTOUCHED;
     priv->last_motion_millis = 0;
+    priv->inside_button_area = FALSE;
     priv->tap_state = TS_START;
     priv->tap_button = 0;
     priv->tap_button_state = TBS_BUTTON_UP;
@@ -1545,6 +1546,56 @@ is_inside_topmiddlebutton_area(SynapticsParameters * para, int x, int y)
     return is_inside_button_area(para, TOP_MIDDLE_BUTTON_AREA, x, y);
 }
 
+static Bool
+is_inside_top_or_bottom_button_area(SynapticsParameters * para, int offset,
+                                    int x, int y)
+{
+    Bool inside_area = TRUE;
+    Bool right_valid, middle_valid;
+    int top, bottom;
+
+    /* We don't have a left button area, so we only check the y axis */
+    right_valid = para->softbutton_areas[offset][TOP] ||
+                  para->softbutton_areas[offset][BOTTOM];
+    middle_valid = para->softbutton_areas[offset + 1][TOP] ||
+                   para->softbutton_areas[offset + 1][BOTTOM];
+
+    if (!right_valid && !middle_valid)
+        return FALSE;
+
+    /* Check both buttons are horizontally aligned */
+    if (right_valid && middle_valid && (
+            para->softbutton_areas[offset][TOP] !=
+                para->softbutton_areas[offset + 1][TOP] ||
+            para->softbutton_areas[offset][BOTTOM] !=
+                para->softbutton_areas[offset + 1][BOTTOM]))
+        return FALSE;
+
+    if (right_valid) {
+        top    = para->softbutton_areas[offset][TOP];
+        bottom = para->softbutton_areas[offset][BOTTOM];
+    }
+    else {
+        top    = para->softbutton_areas[offset + 1][TOP];
+        bottom = para->softbutton_areas[offset + 1][BOTTOM];
+    }
+
+    if (top && y < top)
+        inside_area = FALSE;
+    else if (bottom && y > bottom)
+        inside_area = FALSE;
+
+    return inside_area;
+}
+
+static Bool
+is_inside_anybutton_area(SynapticsParameters * para, int x, int y)
+{
+    return
+        is_inside_top_or_bottom_button_area(para, BOTTOM_BUTTON_AREA, x, y) ||
+        is_inside_top_or_bottom_button_area(para, TOP_BUTTON_AREA, x, y);
+}
+
 static CARD32
 timerFunc(OsTimerPtr timer, CARD32 now, pointer arg)
 {
@@ -3045,6 +3096,8 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
     int delay = 1000000000;
     int timeleft;
     Bool inside_active_area;
+    Bool using_cumulative_coords = FALSE;
+    Bool ignore_motion;
 
     /* If touchpad is switched off, we skip the whole thing and return delay */
     if (para->touchpad_off == TOUCHPAD_OFF) {
@@ -3070,6 +3123,7 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
     if (para->clickpad && (hw->left || hw->right || hw->middle)) {
         hw->x = hw->cumulative_dx;
         hw->y = hw->cumulative_dy;
+        using_cumulative_coords = TRUE;
     }
 
     /* apply hysteresis before doing anything serious. This cancels
@@ -3079,6 +3133,16 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
 
     inside_active_area = is_inside_active_area(priv, hw->x, hw->y);
 
+    /* Ignore motion *starting* inside softbuttonareas */
+    if (priv->finger_state < FS_TOUCHED)
+        priv->inside_button_area = is_inside_anybutton_area(para, hw->x, hw->y);
+    /* If we already have a finger down, clear inside_button_area if it goes
+       outside of the softbuttonareas */
+    else if (priv->inside_button_area && !is_inside_anybutton_area(para, hw->x, hw->y))
+        priv->inside_button_area = FALSE;
+
+    ignore_motion = !using_cumulative_coords && priv->inside_button_area;
+
     /* these two just update hw->left, right, etc. */
     update_hw_button_state(pInfo, hw, now, &delay);
     if (priv->has_scrollbuttons)
@@ -3150,8 +3214,8 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
     }
 
     /* Post events */
-    if (finger >= FS_TOUCHED && (dx || dy) &&
-        (para->touchpad_off != TOUCHPAD_CLICK_ONLY))
+    if (finger >= FS_TOUCHED && (dx || dy) && !ignore_motion &&
+            (para->touchpad_off != TOUCHPAD_CLICK_ONLY))
         xf86PostMotionEvent(pInfo->dev, 0, 0, 2, dx, dy);
 
     if (priv->mid_emu_state == MBE_LEFT_CLICK) {
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index c03aa25..6d8b0c0 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -249,6 +249,7 @@ struct _SynapticsPrivateRec {
     Bool prev_up;               /* Previous up button value, for double click emulation */
     enum FingerState finger_state;      /* previous finger state */
     CARD32 last_motion_millis;  /* time of the last motion */
+    Bool inside_button_area;    /* Inside button area (ignore motion) */
 
     enum TapState tap_state;    /* State of tap processing */
     int tap_max_fingers;        /* Max number of fingers seen since entering start state */
-- 
1.9.0



More information about the xorg-devel mailing list