Blob Blame History Raw
From 13f9b07039484927532d913dbccc664679235bf6 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Mon, 25 Mar 2019 13:19:41 +1000
Subject: [PATCH xserver] dix: leave last.valuators alone on slave switch

Terms:
dev->last.valuator[] is the last value given to us by the driver
dev->valuator.axisVal[] is the last value sent to the client
dev->last.scroll[] is the abs value of the scroll axis as given by the driver,
        used for button emulation calculation (and the remainder)

This function updates the device's last.valuator state based on the current
master axis state. This way, relative motion continues fluidly when switching
between devices. Before mouse 2 comes into effect, it's valuator state is
updated to wherever the pointer currently is so the relative event applies on
top of that.

This can only work for x/y axes, all other axes aren't guaranteed to have the
same meaning and/or may not be present:
- xtest device: no valuator 2
- mouse: valuator 2 is horizontal scroll axis
- tablet: valuator 2 is pressure

Scaling the current value from the pressure range into the range for
horizontal scrolling makes no sense. And it causes scroll jumps:

- scroll down, last.valuator == axisVal == 20
- xdotool click 1, the XTest device doesn't have that valuator
- scroll up
  - updateSlaveDeviceCoords reset last.valuator to 0 (axisVal == 20)
  - DeviceClassesChangedEvent includes value 20 for the axis
  - event is processed, last.value changes from 0 to -1
  - axisVal is updated to -1, causing a jump of -21

The same applies when we switch from tablet to mouse wheel if the pressure
value is 0 on proximity out (basically guaranteed). So let's drop this code
altogether and only leave the scaling for the relative x/y motion.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
 dix/getevents.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/dix/getevents.c b/dix/getevents.c
index d8955969a..f83dac709 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -331,9 +331,6 @@ rescaleValuatorAxis(double coord, AxisInfoPtr from, AxisInfoPtr to,
 static void
 updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
 {
-    int i;
-    DeviceIntPtr lastSlave;
-
     /* master->last.valuators[0]/[1] is in desktop-wide coords and the actual
      * position of the pointer */
     pDev->last.valuators[0] = master->last.valuators[0];
@@ -358,27 +355,7 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
                                                       screenInfo.height);
     }

-    /* calculate the other axis as well based on info from the old
-     * slave-device. If the old slave had less axes than this one,
-     * last.valuators is reset to 0.
-     */
-    if ((lastSlave = master->last.slave) && lastSlave->valuator) {
-        for (i = 2; i < pDev->valuator->numAxes; i++) {
-            if (i >= lastSlave->valuator->numAxes) {
-                pDev->last.valuators[i] = 0;
-                valuator_mask_set_double(pDev->last.scroll, i, 0);
-            }
-            else {
-                double val = pDev->last.valuators[i];
-
-                val = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
-                                          pDev->valuator->axes + i, 0, 0);
-                pDev->last.valuators[i] = val;
-                valuator_mask_set_double(pDev->last.scroll, i, val);
-            }
-        }
-    }
-
+    /* other axes are left as-is */
 }

 /**
--
2.20.1