RFR: 8294426: Two fingers tap generates wrong mouse modifiers on M2 MacBooks
Nikita Provotorov
duke at openjdk.org
Wed Jun 21 19:30:21 UTC 2023
On Mon, 17 Oct 2022 23:36:47 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> Hi there!
>> JetBrains has faced with a bug on Apple M2 MacBooks when tapping (_not_ pressing) with two fingers on a trackpad generates wrong mouse modifiers (which are returned by [MouseEvent.getModifiersEx](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/event/InputEvent.html#getModifiersEx())).
>>
>> <s>As far as I see, OpenJDK bug tracker still doesn't contain such a bug and I don't have rights to create a new one, so the PR doesn't refer any id</s> UPD: fixed. Here is the bug link from the JetBrains own tracker: [JBR-4765](https://youtrack.jetbrains.com/issue/JBR-4765/Cannot-invoke-context-menu-by-two-fingers-tapping-on-MacBook-with-M2-chip).
>>
>> The bug is 100% reproducible on M2 MacBooks (at least under macOS 12.5). It's also reproducible on M1 MacBooks, but much more rarely (about 10-15% of reproducibility).
>>
>> ## Steps to reproduce
>> 1. Enable `System Preferences` -> `Trackpad` -> `Tap to click`
>> 2. Tap with two fingers in the following app:
>>
>> import javax.swing.*;
>> import java.awt.event.MouseAdapter;
>> import java.awt.event.MouseEvent;
>>
>> class MouseWindow {
>> final JFrame frame;
>>
>> MouseWindow() {
>> frame = new JFrame();
>> frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
>>
>> frame.setTitle("Mouse window");
>>
>> frame.addMouseListener(new MouseAdapter() {
>> @Override
>> public void mousePressed(MouseEvent e) {
>> System.out.println(e);
>> }
>> });
>>
>> frame.pack();
>>
>> frame.setSize(300, 300);
>>
>> frame.setVisible(true);
>> }
>>
>> public static void main(String[] args) {
>> SwingUtilities.invokeLater(MouseWindow::new);
>> }
>> }
>>
>>
>> ### Expected
>> Printed mouse event has `modifiersEx` is `4096` (which is `InputEvent.BUTTON3_DOWN_MASK`)
>>
>> ### Actual
>> Printed mouse event has `modifiersEx` is `4352` (which is `InputEvent.BUTTON3_DOWN_MASK | InputEvent.META_DOWN_MASK`)
>>
>> ## Evaluation
>> The following happens when a native mouse event reaches Java:
>> 1. `NSEvent.nsToJavaModifiers(0)` called inside [CPlatformResponder.handleMouseEvent():81](https://github.com/openjdk/jdk/blob/5ae6bc23e857535532b59aae674e2b917bbf7284/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java#L81) returns `0`. Earlier it always returned `4096` (`InputEvent.BUTTON3_DOWN_MASK`) but not in the cases of M2 tapping. For a trackpad press (not a tap) it still return...
>
> Can we report this behaviour change to Apple for investigation?
@mrserb,
> Can we report this behaviour change to Apple for investigation?
I think this is our problem here - we ask for the _currently pressed modifiers_ only after the event has happened (and dispatched to us), so there is no guarantee that a user doesn't manage to release the mouse button before the press event is dispatched to us.
Do you agree?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/10429#issuecomment-1601552204
More information about the client-libs-dev
mailing list