Bug in unbounded mouse movement + global display scale factor


#1

The calculation of unbounded mouse movement is mixing up scaled and unscaled coordinates, causing jumps. For instance suppose the physical screen is 2000px wide and the scaled screen is 1500 px. When the mouse cursor moves past 1500 px in physical coordinates, it will jump to the edge of the screen.

I think this patch fixes this issue. Can you have a look if it makes sense?

--
Roeland

--- juce_MouseInputSource.cpp
+++ juce_MouseInputSource.cpp
@@ -399,7 +399,8 @@
             {
                 // when released, return the mouse to within the component's bounds
                 if (Component* current = getComponentUnderMouse())
-                    setScreenPosition (current->getScreenBounds().toFloat().getConstrainedPoint (lastScreenPos));
+                    setScreenPosition (current->getScreenBounds().toFloat().getConstrainedPoint (
+                        ScalingHelpers::unscaledScreenPosToScaled(lastScreenPos)));
             }
 
             isUnboundedMouseModeOn = enable;
@@ -411,12 +412,13 @@
 
     void handleUnboundedDrag (Component* current)
     {
-        const Rectangle<float> screenArea (current->getParentMonitorArea().expanded (-2, -2).toFloat());
+        const Rectangle<float> screenArea = ScalingHelpers::scaledScreenPosToUnscaled(
+                current->getParentMonitorArea().expanded (-2, -2).toFloat());
 
         if (! screenArea.contains (lastScreenPos))
         {
             const Point<float> componentCentre (current->getScreenBounds().toFloat().getCentre());
-            unboundedMouseOffset += (lastScreenPos - componentCentre);
+            unboundedMouseOffset += (lastScreenPos - ScalingHelpers::scaledScreenPosToUnscaled(componentCentre));
             setScreenPosition (componentCentre);
         }
         else if (isCursorVisibleUntilOffscreen
@@ -423,7 +425,7 @@
                   && (! unboundedMouseOffset.isOrigin())
                   && screenArea.contains (lastScreenPos + unboundedMouseOffset))
         {
-            setScreenPosition (lastScreenPos + unboundedMouseOffset);
+            MouseInputSource::setRawMousePosition (lastScreenPos + unboundedMouseOffset);
             unboundedMouseOffset = Point<float>();
         }
     }


#2

Interesting, thanks for the heads-up! I'll investigate...


#3

It's working now, thanks.

--
Roeland