I am trying to add a “right click” popup menu to a button, and while isPopupMenu works with a mouse (right-click) and with control-click (on mac), it doesn’t work with the “two-finger tap” of my MacBook’s trackpad.
Isn’t the two-finger tap supposed to be right-click? it is for every app on the Mac… How can I intercept the two-finger tap to add it as a modifier?
Hmm, something funky going on here that may well be a bug.
100% sure that testing MouseEvent.mods.isPopupMenu() in mouseDown or mouseUp methods of a Component (or derived class) works as intended, but I never used onClick beyond implementing left click behaviours.
Looking quickly at the JUCE code seems like this should work in onClick for a Button, but I don’t have time to investigate further.
Please be aware that adding a MouseListener for intercepting the right mouse click is only half of the problem: the Button that you right-clicked will still perform its action exactly as if it were left-clicked, and that may not be what you wanted/your user expects when right-clicking to display its context menu.
To prevent the left-click action being triggered when right-clicking, there are a number of workarounds (listed in the topic linked below), but IMHO it would be better for JUCE Buttons to natively have an option to ignore right-clicks (or hey, even provide a onRightClick lambda for them, that would be awesome) so if you agree, please cast your vote in the Feature Request topic linked below, perhaps that will catch the JUCE team attention…