From 8938f51292ca970c38195e260dd885c7519651eb Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 15 Oct 2015 01:48:31 -0700 Subject: [PATCH] Fix weird stair-stepping upward mouse movement on devices with a low scaling factor caused by rounding error (Nexus 9) --- .../limelight/binding/input/TouchContext.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/limelight/binding/input/TouchContext.java b/app/src/main/java/com/limelight/binding/input/TouchContext.java index 113771c6..129ed5b3 100644 --- a/app/src/main/java/com/limelight/binding/input/TouchContext.java +++ b/app/src/main/java/com/limelight/binding/input/TouchContext.java @@ -97,14 +97,33 @@ public class TouchContext { int deltaY = eventY - lastTouchY; // Scale the deltas based on the factors passed to our constructor - deltaX = (int)Math.round((double)deltaX * xFactor); - deltaY = (int)Math.round((double)deltaY * yFactor); + deltaX = (int)Math.round((double)Math.abs(deltaX) * xFactor); + deltaY = (int)Math.round((double)Math.abs(deltaY) * yFactor); + + // Fix up the signs + if (eventX < lastTouchX) { + deltaX = -deltaX; + } + if (eventY < lastTouchY) { + deltaY = -deltaY; + } + + // If the scaling factor ended up rounding deltas to zero, wait until they are + // non-zero to update lastTouch that way devices that report small touch events often + // will work correctly + if (deltaX != 0) { + lastTouchX = eventX; + } + if (deltaY != 0) { + lastTouchY = eventY; + } conn.sendMouseMove((short)deltaX, (short)deltaY); } - - lastTouchX = eventX; - lastTouchY = eventY; + else { + lastTouchX = eventX; + lastTouchY = eventY; + } } return true;