diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 4cf50e87f..71a59e87f 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -1316,16 +1316,6 @@ public class PSurfaceAWT extends PSurfaceNone { peButton = PConstants.RIGHT; } - // If running on Mac OS, allow ctrl-click as right mouse. Prior to 0215, - // this used isPopupTrigger() on the native event, but that doesn't work - // for mouseClicked and mouseReleased (or others). - if (PApplet.platform == PConstants.MACOSX) { - //if (nativeEvent.isPopupTrigger()) { - if ((modifiers & InputEvent.CTRL_MASK) != 0) { - peButton = PConstants.RIGHT; - } - } - sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(), peAction, peModifiers, nativeEvent.getX() / windowScaleFactor, diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 457b50ea4..85f0fb81a 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -561,6 +561,14 @@ public class PApplet implements PConstants { */ public boolean mousePressed; + // MACOSX: CTRL + Left Mouse is converted to Right Mouse. This boolean keeps + // track of whether the conversion happened on PRESS, because we should report + // the same button during DRAG and on RELEASE, even though CTRL might have + // been released already. Otherwise the events are inconsistent, e.g. + // Left Pressed - Left Drag - CTRL Pressed - Right Drag - Right Released. + // See: https://github.com/processing/processing/issues/5672 + private boolean macosxLeftButtonWithCtrlPressed; + /** @deprecated Use a mouse event handler that passes an event instead. */ @Deprecated @@ -2650,8 +2658,27 @@ public class PApplet implements PConstants { mouseY = event.getY(); } + int button = event.getButton(); + + // If running on Mac OS, allow ctrl-click as right mouse. + if (PApplet.platform == PConstants.MACOSX && event.getButton() == PConstants.LEFT) { + if (action == MouseEvent.PRESS && event.isControlDown()) { + macosxLeftButtonWithCtrlPressed = true; + } + if (macosxLeftButtonWithCtrlPressed) { + button = PConstants.RIGHT; + event = new MouseEvent(event.getNative(), event.getMillis(), + event.getAction(), event.getModifiers(), + event.getX(), event.getY(), + button, event.getCount()); + } + if (button == MouseEvent.RELEASE) { + macosxLeftButtonWithCtrlPressed = false; + } + } + // Get the (already processed) button code - mouseButton = event.getButton(); + mouseButton = button; /* // Compatibility for older code (these have AWT object params, not P5) diff --git a/core/src/processing/javafx/PSurfaceFX.java b/core/src/processing/javafx/PSurfaceFX.java index e9f8243d7..4061f36fc 100644 --- a/core/src/processing/javafx/PSurfaceFX.java +++ b/core/src/processing/javafx/PSurfaceFX.java @@ -860,14 +860,6 @@ public class PSurfaceFX implements PSurface { break; } - // If running on Mac OS, allow ctrl-click as right mouse. - // Verified to be necessary with Java 8u45. - if (PApplet.platform == PConstants.MACOSX && - fxEvent.isControlDown() && - button == PConstants.LEFT) { - button = PConstants.RIGHT; - } - //long when = nativeEvent.getWhen(); // from AWT long when = System.currentTimeMillis(); int x = (int) fxEvent.getX(); // getSceneX()? diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 17d2d916e..a9de3f0b8 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -1033,13 +1033,6 @@ public class PSurfaceJOGL implements PSurface { break; } - if (PApplet.platform == PConstants.MACOSX) { - //if (nativeEvent.isPopupTrigger()) { - if ((modifiers & InputEvent.CTRL_MASK) != 0) { - peButton = PConstants.RIGHT; - } - } - int peCount = 0; if (peAction == MouseEvent.WHEEL) { // Invert wheel rotation count so it matches JAVA2D's