RFR: 8345538: Robot.mouseMove doesn't clamp bounds on macOS when trying to move mouse off screen [v11]

Sergey Bylokhov serb at openjdk.org
Thu Feb 6 10:59:14 UTC 2025


On Tue, 28 Jan 2025 23:21:26 GMT, Alisen Chung <achung at openjdk.org> wrote:

>> Currently on macOS when mouseMove is given an offscreen coordinate to move the mouse to, mouseMove will physically clamp to the edge of the screen, but if you try to grab the mouse location immediately after by using MouseInfo.getPointerInfo().getLocation() you will get the value of the offscreen point.
>> 
>> Windows and linux do this clamping and coordinate handling for us, but new distributions may not necessarily handle clamping the same way, so Robot should be checking for clamping rather than delegating it to native.
>> 
>> This fix updates shared code to cache the screen bounds and adds a check to not exceed the bounds in mouseMove. The caching is done in the Robot constructor, so if the screen bounds changes the constructor must be called again to update to the new bounds.
>
> Alisen Chung has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - helper function
>  - grab screen data on mouseMove

The Robot API is just a wrapper around the native API with a basic functionality that works across all platforms. If a native macOS application can move the mouse in a certain way, why should Java be restricted?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22781#issuecomment-2639487470


More information about the client-libs-dev mailing list