Button right click confusion


#1

I think I must be missing something concerning right clicks and the Button class. The default behavior calls buttonClicked() on either right or left mouse buttons. To the best of my knowledge this is not the default behavior of a button on Windows or macOS, and the code is already dealing with touch events internally. I have seen this post https://forum.juce.com/t/fr-buttons-add-option-to-ignore-clicks-with-right-mouse-button/20723 but there were no responses. I changed this behavior in my local repo but would like to understand why this is the default implementation.


#2

Probably because some people want different behavior based on left/right mouse clicks? I think something along these lines this should work:

void MyComponent::buttonClicked (Button* b) 
{
    if (b == &some_button)
    {
        auto& modifiers = ModifierKeys::getCurrentModifiers();
        if (modifiers.isRightButtonDown() 
            // do something
        else
            // do something else
    }
}

#3

Thanks for the reply. I understand I can check for modifiers but I was specifically referring to the “default” behavior. i.e. I would expect buttonClicked to be called when the OS “primary” mouse button is clicked and not have to check modifiers. I suppose if buttonClicked were not called some other method would also have to be called with the modifiers.