[PATCH smooth scrolling] dix: Don't reset the scrolling valuators when emulating events

Peter Hutterer peter.hutterer at who-t.net
Sun Aug 14 22:24:12 PDT 2011


Relative valuators accumulate. Don't reset last.valuators when emulating
legacy scroll button events but rather take the difference before and after,
then emulate based on that.

For subpixel scroll events the previous valuator values sent to the clients
were:
    0.2 - 0.4 -0.6 - 0.8 - 0.0 - 0.2 - 0.4...
This sequence is now
    0.2 - 0.4 -0.6 - 0.8 - 1.0 - 1.2 - 1.4...

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
This one goes on top of the patches in my -next branch, it won't apply to
master.

 dix/getevents.c |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/dix/getevents.c b/dix/getevents.c
index 2890b6f..c8af013 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1201,6 +1201,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     int h_scroll_axis = pDev->valuator->h_scroll_axis;
     int v_scroll_axis = pDev->valuator->v_scroll_axis;
     ValuatorMask mask;
+    double last_scroll_v = 0,
+           last_scroll_h = 0;
 
     /* refuse events from disabled devices */
     if (!pDev->enabled)
@@ -1252,6 +1254,13 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
         }
     }
 
+    /* Relative axes accumulate. Remember the last integer value we had for
+     * the scroll emulation */
+    if (v_scroll_axis != -1)
+        last_scroll_v = (int)pDev->last.valuators[v_scroll_axis];
+    if (h_scroll_axis != -1)
+        last_scroll_h = (int)pDev->last.valuators[h_scroll_axis];
+
     /* First fill out the original event set, with smooth-scrolling axes. */
     nev_tmp = fill_pointer_events(events, pDev, type, buttons, ms, flags,
                                   &mask);
@@ -1259,11 +1268,14 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     num_events += nev_tmp;
 
     /* Now turn the smooth-scrolling axes back into emulated button presses
-     * for legacy clients. */
-    while ((v_scroll_axis != -1 &&
-            fabs(pDev->last.valuators[v_scroll_axis]) >= 1.0) ||
-           (h_scroll_axis != -1 &&
-            fabs(pDev->last.valuators[h_scroll_axis]) >= 1.0))
+     * for legacy clients, based on the integer delta between before and now */
+    if (v_scroll_axis != -1)
+        last_scroll_v = pDev->last.valuators[v_scroll_axis] - last_scroll_v;
+    if (h_scroll_axis != -1)
+        last_scroll_h = pDev->last.valuators[h_scroll_axis] - last_scroll_h;
+
+    while ((v_scroll_axis != -1 && fabs(last_scroll_v) >= 1.0) ||
+           (h_scroll_axis != -1 && fabs(last_scroll_h) >= 1.0))
     {
         int b = 0;
 
@@ -1272,27 +1284,24 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
         if (num_events + 4 >= GetMaximumEventsNum())
             break;
 
-        if (v_scroll_axis != -1 && pDev->last.valuators[v_scroll_axis] <= -1.0)
+        if (v_scroll_axis != -1 && last_scroll_v <= -1.0)
         {
-            pDev->last.valuators[v_scroll_axis] += 1.0;
+            last_scroll_v += 1.0;
             b = 4;
         }
-        else if (v_scroll_axis != -1 &&
-                 pDev->last.valuators[v_scroll_axis] >= 1.0)
+        else if (v_scroll_axis != -1 && last_scroll_v >= 1.0)
         {
-            pDev->last.valuators[v_scroll_axis] -= 1.0;
+            last_scroll_v -= 1.0;
             b = 5;
         }
-        else if (h_scroll_axis != -1 &&
-                 pDev->last.valuators[h_scroll_axis] <= -1.0)
+        else if (h_scroll_axis != -1 && last_scroll_h <= -1.0)
         {
-            pDev->last.valuators[h_scroll_axis] += 1.0;
+            last_scroll_h += 1.0;
             b = 6;
         }
-        else if (h_scroll_axis != -1 &&
-                 pDev->last.valuators[h_scroll_axis] >= 1.0)
+        else if (h_scroll_axis != -1 && last_scroll_h >= 1.0)
         {
-            pDev->last.valuators[h_scroll_axis] -= 1.0;
+            last_scroll_h -= 1.0;
             b = 7;
         }
 
-- 
1.7.6



More information about the xorg-devel mailing list