[PATCH synaptics v2 21/21] Initial smooth scrolling support

Daniel Stone daniel at fooishbar.org
Tue Jun 14 10:06:09 PDT 2011


Post smooth-scrolling events through the new X server API when
available, rather than legacy jerky button events.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/synaptics.c    |   54 +++++++++++++++++++++++++++++++++++++++++++++++++--
 src/synapticsstr.h |   11 ++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

v2: Removed xf86InitValuatorAxisDefaults calls for smooth scrolling axes,
    don't leak mask, use correct axis ranges, and split include order
    shuffling out into a separate patch.

diff --git a/src/synaptics.c b/src/synaptics.c
index 01a03d5..a2c3186 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -809,6 +809,10 @@ static void SynapticsUnInit(InputDriverPtr drv,
         free(priv->timer);
     if (priv && priv->proto_data)
         free(priv->proto_data);
+#ifdef HAVE_SMOOTH_SCROLL
+    if (priv && priv->scroll_events_mask)
+        valuator_mask_free(&priv->scroll_events_mask);
+#endif
     free(pInfo->private);
     pInfo->private = NULL;
     xf86DeleteInput(pInfo, 0);
@@ -936,6 +940,12 @@ static void InitAxesLabels(Atom *labels, int nlabels)
     switch(nlabels)
     {
         default:
+#ifdef HAVE_SMOOTH_SCROLL
+        case 4:
+            labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL);
+        case 3:
+            labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL);
+#endif
         case 2:
             labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
         case 1:
@@ -979,12 +989,17 @@ DeviceInit(DeviceIntPtr dev)
     unsigned char map[SYN_MAX_BUTTONS + 1];
     int i;
     int min, max;
+    int num_axes = 2;
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
     Atom btn_labels[SYN_MAX_BUTTONS] = { 0 };
-    Atom axes_labels[2] = { 0 };
+    Atom axes_labels[4] = { 0 };
     DeviceVelocityPtr pVel;
 
-    InitAxesLabels(axes_labels, 2);
+#ifdef HAVE_SMOOTH_SCROLL
+    num_axes += 2;
+#endif
+
+    InitAxesLabels(axes_labels, num_axes);
     InitButtonLabels(btn_labels, SYN_MAX_BUTTONS);
 #endif
 
@@ -1001,7 +1016,8 @@ DeviceInit(DeviceIntPtr dev)
                             btn_labels,
 #endif
 			    SynapticsCtrl,
-			    GetMotionHistorySize(), 2
+			    GetMotionHistorySize(),
+			    num_axes
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
                             , axes_labels
 #endif
@@ -1094,6 +1110,18 @@ DeviceInit(DeviceIntPtr dev)
             );
     xf86InitValuatorDefaults(dev, 1);
 
+#ifdef HAVE_SMOOTH_SCROLL
+    xf86InitValuatorAxisStruct(dev, 2, axes_labels[2], 0, -1, 0, 0, 0,
+                               Relative);
+    priv->scroll_axis_horiz = 2;
+    xf86InitValuatorAxisStruct(dev, 3, axes_labels[3], 0, -1, 0, 0, 0,
+                               Relative);
+    priv->scroll_axis_vert = 3;
+    priv->scroll_events_mask = valuator_mask_new(MAX_VALUATORS);
+    if (!priv->scroll_events_mask)
+        return !Success;
+#endif
+
     if (!alloc_shm_data(pInfo))
 	return !Success;
 
@@ -2477,7 +2505,26 @@ post_scroll_events(const InputInfoPtr pInfo, struct ScrollData scroll)
 {
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
     SynapticsParameters *para = &priv->synpara;
+#ifdef HAVE_SMOOTH_SCROLL
+    double val;
+
+    valuator_mask_zero(priv->scroll_events_mask);
 
+    if (para->scroll_dist_vert > 0 && scroll.y)
+    {
+        val = (float) scroll.y / (float) para->scroll_dist_vert;
+        valuator_mask_set_double(priv->scroll_events_mask,
+                                 priv->scroll_axis_vert, val);
+    }
+    if (para->scroll_dist_horiz > 0 && scroll.x)
+    {
+        val = (float) scroll.x / (float) para->scroll_dist_horiz;
+        valuator_mask_set_double(priv->scroll_events_mask,
+                                 priv->scroll_axis_horiz, val);
+    }
+    if (valuator_mask_num_valuators(priv->scroll_events_mask))
+        xf86PostMotionEventM(pInfo->dev, FALSE, priv->scroll_events_mask);
+#else
     while (para->scroll_dist_vert > 0 && scroll.y <= -para->scroll_dist_vert)
     {
         post_button_click(pInfo, 4);
@@ -2501,6 +2548,7 @@ post_scroll_events(const InputInfoPtr pInfo, struct ScrollData scroll)
         post_button_click(pInfo, 7);
         scroll.x -= para->scroll_dist_horiz;
     }
+#endif
 }
 
 static inline int
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index 7383f97..1c0672a 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -23,6 +23,7 @@
 #define _SYNAPTICSSTR_H_
 
 #include "synproto.h"
+#include <xserver-properties.h>
 
 #ifdef DBG
 #  undef DBG
@@ -39,6 +40,10 @@
 #define xf86IDrvMsg(pInfo, type, ...) xf86Msg(type, __VA_ARGS__)
 #endif
 
+#ifdef AXIS_LABEL_PROP_REL_VSCROLL
+#define HAVE_SMOOTH_SCROLL
+#endif
+
 /******************************************************************************
  *		Definitions
  *					structs, typedefs, #defines, enums
@@ -256,6 +261,12 @@ typedef struct _SynapticsPrivateRec
     enum TouchpadModel model;		/* The detected model */
     unsigned short id_vendor;		/* vendor id */
     unsigned short id_product;		/* product id */
+
+#ifdef HAVE_SMOOTH_SCROLL
+    int scroll_axis_horiz;              /* Horizontal smooth-scrolling axis */
+    int scroll_axis_vert;               /* Vertical smooth-scrolling axis */
+    ValuatorMask *scroll_events_mask;   /* ValuatorMask for smooth-scrolling */
+#endif
 } SynapticsPrivate;
 
 #endif /* _SYNAPTICSSTR_H_ */
-- 
1.7.5.3



More information about the xorg-devel mailing list