From 500243ac60ffeb5372e2edbce2f4443a07877d2e Mon Sep 17 00:00:00 2001 From: Chase Douglas Date: Thu, 9 Feb 2012 10:43:08 -0800 Subject: [PATCH] Add cumulative_d{x,y} to SynapticsHwState 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. [fixed build error for mt off] Signed-off-by: Chase Douglas Reviewed-by: Peter Hutterer --- src/eventcomm.c | 37 +++++++++++++++++++++++++++++++++++-- src/synproto.c | 2 ++ src/synproto.h | 2 ++ test/fake-symbols.c | 5 +++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/eventcomm.c b/src/eventcomm.c index d031eb4..d52cb6c 100644 --- a/src/eventcomm.c +++ b/src/eventcomm.c @@ -525,6 +525,20 @@ SynapticsReadEvent(InputInfoPtr pInfo, struct input_event *ev) return rc; } +#ifdef HAVE_MULTITOUCH +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; +} +#endif + static void EventProcessTouchEvent(InputInfoPtr pInfo, struct SynapticsHwState *hw, struct input_event *ev) @@ -565,8 +579,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 @@ -614,6 +640,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 21e88c4..bdf2d21 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 & BTN_EMULATED_FLAG ? 0 : src->left; diff --git a/src/synproto.h b/src/synproto.h index 5e8a804..41284b3 100644 --- a/src/synproto.h +++ b/src/synproto.h @@ -56,6 +56,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) { }