mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Merge pull request #5674 from JakubValtar/fix-ctrl-click
Make sure Ctrl+Left Mouse on MacOS is consistent
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user