RFR: 8345538: Robot.mouseMove doesn't clamp bounds on macOS when trying to move mouse off screen [v6]
Alexey Ivanov
aivanov at openjdk.org
Tue Jan 28 18:45:50 UTC 2025
On Tue, 28 Jan 2025 18:39:44 GMT, Alisen Chung <achung at openjdk.org> wrote:
>> src/java.desktop/share/classes/java/awt/Robot.java line 175:
>>
>>> 173: for (int i = 0; i < gs.length; i++) {
>>> 174: allScreenBounds[i] = gs[i].getDefaultConfiguration().getBounds();
>>> 175: }
>>
>> This doesn't look right to me… `init` is an instance method, yet it initialises `allScreenBounds` which is shared among all instances.
>>
>> In a way it makes sense to share the graphics environment / configuration. On the other hand how much would it affect the operation of robot if the bounds are fetched from `GraphicsEnvironment` only when needed?
>>
>> What happens if the graphics configuration changes? Does the user need to create a new instance of the `Robot` class?
>
> I did consider this and thought it would be too expensive to fetch the bounds on every mouseMove action, so i thought it would be better to reinitialize robot when the graphics configuration changes. Do you have a better idea for where/when to cache the bounds?
The first question to answer: _Is it expensive to get screen data from GraphicsEnvironment?_ It shouldn't be, the data is already there, you just fetch the data.
> it would be better to reinitialize robot when the graphics configuration changes
But I see no code which re-initialises the cached graphics configuration if anything changes.
Do I miss anything?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22781#discussion_r1932687868
More information about the client-libs-dev
mailing list