On Tue, 27 May 2025 17:35:17 GMT, Alisen Chung <ach...@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:
> 
>  - add logging to test
>  - test require macos, spacing in crobot

Latest changes LGTM on macOS (single and dual-monitor setup). Please ensure to 
sync mainline and run CI for sanity check.

src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java line 85:

> 83:             int currXDiff = Math.abs(x - cP.x);
> 84:             int currYDiff = Math.abs(y - cP.y);
> 85:             int currDiff = (int) Math.round(Math.hypot(currXDiff, 
> currYDiff));

Since `Math.hypot(currXDiff, currYDiff)`  translates to `sqrt(currXDiff^2, 
currYDiff^2)`,  ideally Math.abs in redundant on previous lines. But no harm in 
keeping it.

Suggestion:

            int currXDiff = x - cP.x;
            int currYDiff = y - cP.y;
            int currDiff = (int) Math.round(Math.hypot(currXDiff, currYDiff));

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

Marked as reviewed by honkar (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/22781#pullrequestreview-2872218256
PR Review Comment: https://git.openjdk.org/jdk/pull/22781#discussion_r2109944370

Reply via email to