RFR: 8372756: Mouse additional buttons and horizontal scrolling are broken on XWayland GNOME >= 47 after JDK-8351907
Nikita Provotorov
duke at openjdk.org
Wed Dec 3 11:33:35 UTC 2025
On Wed, 3 Dec 2025 00:12:47 GMT, Alexander Zvegintsev <azvegint at openjdk.org> wrote:
>> The #25265 change introduced an artificial restriction that is actually unnecessary and harmful:
>>
>> https://github.com/openjdk/jdk/blob/f5e4cd7f0d12fd21399b192b32a5c9abfe8a3564/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java#L1526-L1529
>>
>>> Trying to click any mouse additional button raises an exception like the following:
>>>
>>> WARN - sun.awt.X11.XToolkit - Exception on Toolkit thread
>> java.lang.IllegalArgumentException: Nonexistent button 6
>> at java.desktop/java.awt.event.MouseEvent.<init>(MouseEvent.java:774)
>> at java.desktop/sun.awt.X11.XWindow.handleButtonPressRelease(XWindow.java:765)
>> at java.desktop/sun.awt.X11.XContentWindow.handleButtonPressRelease(XContentWindow.java:45)
>> at java.desktop/sun.awt.X11.XBaseWindow.dispatchEvent(XBaseWindow.java:1206)
>> at java.desktop/sun.awt.X11.XBaseWindow.dispatchToWindow(XBaseWindow.java:1178)
>> at java.desktop/sun.awt.X11.XToolkit.dispatchEvent(XToolkit.java:939)
>> at java.desktop/sun.awt.X11.XToolkit.run(XToolkit.java:1086)
>> at java.desktop/sun.awt.X11.XToolkit.run(XToolkit.java:968)
>> at java.base/java.lang.Thread.run(Thread.java:1583)
>>
>> This changeset simply reverses the check, returning it to its original state.
>>
>> The actual check for the supported mouse buttons for the robot is maintained here.
>>
>> https://github.com/openjdk/jdk/blob/f5e4cd7f0d12fd21399b192b32a5c9abfe8a3564/src/java.desktop/share/classes/java/awt/Robot.java#L367-L371
>>
>> https://github.com/openjdk/jdk/blob/f5e4cd7f0d12fd21399b192b32a5c9abfe8a3564/src/java.desktop/share/classes/java/awt/Robot.java#L208-L214
>
> src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java line 1530:
>
>> 1528: //If we have 3 physical buttons and a wheel, we report 3 buttons.
>> 1529: //If we have 1,2,3 physical buttons, we report it as is i.e. 1,2 or 3 respectively.
>> 1530: if (numberOfButtons >= 5) {
>
> Suggestion:
>
> if (numberOfButtons > 5) {
>
> It actually should be `>5`, without it the `numberOfButtons == 5` in `else if` branch is always false.
>
> I want to put the fix to 26, so I intentionally left it as it was before because it had been tested for years. Once we agree on that, I'll file an issue.
BTW, buttons 6 and 7 nowadays are used for horizontal scrolling on X11: when you either do one of the following:
* a horizontal scrolling gesture on a touchpad
* use a secondary mouse wheel (e.g. like on Logitech MX Master 3S/4)
X11 generates a ButtonPress event with the button set to 6 or 7 (depending on the scrolling direction). AWT then subtracts 2 (to take into account the primary wheel) and generates a MouseEvent with the button set to 4 or 5. In the ideal world it obviously should have been MouseWheelEvent exactly how it's done for the primary wheel. However IDK if it'd be a good change for OpenJDK due to the compatibility/legacy reasons.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28621#discussion_r2584742505
More information about the client-libs-dev
mailing list