[PATCH v3 23/23] Scroll: Initial smooth scrolling support
Daniel Stone
daniel at fooishbar.org
Thu Jun 23 15:12:58 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(-)
v3: Take changed variable names and semantics into account.
Drop pre-ABIv7 compatibility.
diff --git a/src/synaptics.c b/src/synaptics.c
index f17a33b..7b9888f 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -807,6 +807,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);
@@ -933,6 +937,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:
@@ -975,11 +985,16 @@ DeviceInit(DeviceIntPtr dev)
unsigned char map[SYN_MAX_BUTTONS + 1];
int i;
int min, max;
+ int num_axes = 2;
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);
DBG(3, "Synaptics DeviceInit called\n");
@@ -994,7 +1009,7 @@ DeviceInit(DeviceIntPtr dev)
btn_labels,
SynapticsCtrl,
GetMotionHistorySize(),
- 2,
+ num_axes,
axes_labels);
/*
@@ -1076,6 +1091,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;
@@ -2468,7 +2495,27 @@ post_scroll_events(const InputInfoPtr pInfo)
{
SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
SynapticsParameters *para = &priv->synpara;
+#ifdef HAVE_SMOOTH_SCROLL
+
+ valuator_mask_zero(priv->scroll_events_mask);
+ if (priv->scroll.delta_y != 0.0)
+ {
+ valuator_mask_set_double(priv->scroll_events_mask,
+ priv->scroll_axis_vert,
+ priv->scroll.delta_y);
+ priv->scroll.delta_y = 0;
+ }
+ if (priv->scroll.delta_x != 0.0)
+ {
+ valuator_mask_set_double(priv->scroll_events_mask,
+ priv->scroll_axis_horiz,
+ priv->scroll.delta_x);
+ priv->scroll.delta_x = 0;
+ }
+ if (valuator_mask_num_valuators(priv->scroll_events_mask))
+ xf86PostMotionEventM(pInfo->dev, FALSE, priv->scroll_events_mask);
+#else
while (priv->scroll.delta_y <= -1.0)
{
post_button_click(pInfo, 4);
@@ -2492,6 +2539,7 @@ post_scroll_events(const InputInfoPtr pInfo)
post_button_click(pInfo, 7);
priv->scroll.delta_x -= 1.0;
}
+#endif
}
static inline int
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index c53de53..1a6e73e 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
@@ -260,6 +265,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.4
More information about the xorg-devel
mailing list