[PATCH 15/15] Initial smooth scrolling support

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 13 22:44:44 PDT 2011


On Thu, Jun 09, 2011 at 08:57:36PM +0100, Daniel Stone wrote:
> 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    |   58 +++++++++++++++++++++++++++++++++++++++++++++------
>  src/synapticsstr.h |   11 +++++++++
>  2 files changed, 62 insertions(+), 7 deletions(-)
> 
> diff --git a/src/synaptics.c b/src/synaptics.c
> index 36f78ae..a9c4618 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -71,16 +71,16 @@
>  #include <xf86Xinput.h>
>  #include <exevents.h>
>  
> -#include "synaptics.h"
> -#include "synapticsstr.h"
> -#include "synaptics-properties.h"
> -
>  #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
>  #include <X11/Xatom.h>
>  #include <xserver-properties.h>
>  #include <ptrveloc.h>
>  #endif
>  
> +#include "synaptics.h"
> +#include "synapticsstr.h"
> +#include "synaptics-properties.h"
> +

why did this get moved?

>  typedef enum {
>      NO_EDGE = 0,
>      BOTTOM_EDGE = 1,
> @@ -923,6 +923,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:
> @@ -966,12 +972,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
>  
> @@ -988,7 +999,8 @@ DeviceInit(DeviceIntPtr dev)
>                              btn_labels,
>  #endif
>  			    SynapticsCtrl,
> -			    GetMotionHistorySize(), 2
> +			    GetMotionHistorySize(),
> +			    num_axes
>  #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
>                              , axes_labels
>  #endif
> @@ -1081,6 +1093,18 @@ DeviceInit(DeviceIntPtr dev)
>              );
>      xf86InitValuatorDefaults(dev, 1);
>  
> +#ifdef HAVE_SMOOTH_SCROLL
> +    xf86InitValuatorAxisStruct(dev, 2, axes_labels[2], 0, 0, 0, 0, 0, Relative);
> +    xf86InitValuatorDefaults(dev, 2);

don't do this, no-one else does it. for relative axes, initialize it to min 0,
max -1 and skip the defaults call.

> +    priv->scroll_axis_horiz = 2;
> +    xf86InitValuatorAxisStruct(dev, 3, axes_labels[3], 0, 0, 0, 0, 0, Relative);
> +    xf86InitValuatorDefaults(dev, 3);
> +    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;

this seems to leave the mask hanging now, doesn't it?
SynapticsUnInit probably needs the matching free call.

Cheers,
  Peter
>  
> @@ -2447,7 +2471,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);
> @@ -2471,6 +2514,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 7c20756..e1ec78b 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