Skip to content

Commit

Permalink
JBR-5762 Sometimes naturally generated MOUSE_DRAGGED events don't con…
Browse files Browse the repository at this point in the history
…tain the pressed button's modifier.

Enforce keeping the pressed button in the modifiers for MOUSE_DRAGGED events. This is under a (default enabled) system property "awt.mac.enforceMouseModifiersForMouseDragged".
  • Loading branch information
NikitkoCent committed Jun 22, 2023
1 parent 7814b10 commit fb12990
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
}

int jmodifiers = NSEvent.nsToJavaModifiers(modifierFlags);
if ((jeventType == MouseEvent.MOUSE_PRESSED) && (jbuttonNumber > MouseEvent.NOBUTTON)) {
jmodifiers |= MouseEvent.getMaskForButton(jbuttonNumber);
if (jbuttonNumber > MouseEvent.NOBUTTON) {
if ( (jeventType == MouseEvent.MOUSE_PRESSED) || (Jbr5762Fix.isEnabled && (jeventType == MouseEvent.MOUSE_DRAGGED)) ) {
jmodifiers |= MouseEvent.getMaskForButton(jbuttonNumber);
}
}

boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);
Expand Down Expand Up @@ -330,4 +332,19 @@ else if (scrollPhase == NSEvent.SCROLL_PHASE_MOMENTUM_BEGAN) {
return roundDelta;
}
}

static class Jbr5762Fix {
static final boolean isEnabled;

static {
boolean isEnabledLocal = false;

try {
isEnabledLocal = Boolean.parseBoolean(System.getProperty("awt.mac.enforceMouseModifiersForMouseDragged", "true"));
} catch (Exception ignored) {
}

isEnabled = isEnabledLocal;
}
}
}

0 comments on commit fb12990

Please sign in to comment.