Clicking a button always shows Popmenu

I have a PopMenu that shows when I click a Button. While the PopMenu is showing I want a click on the Button to hide it and not hide first and re-show.

With a CallOutBox this is fairly simple to achieve as you can just use setDismissalMouseClicksAreAlwaysConsumed

CallOutBox* callout = &CallOutBox::launchAsynchronously (contentWidow, r, this);

Is there anyway to get the same behavior with a PopMenu?

You could set your button in ‘toggle’ mode and only show the menu when the button is down :

button.setClickingTogglesState (true);

button.onClick = [this]()
    if (button.getToggleState())
        menu.showMenuAsync (...);

and set your button back in ‘off’ state in your the menu callback :
button.setToggleState (false, dontSendNotification);