Bug and potential fix: Button toggle disables tooltips

I recently encountered odd behavior with the interaction of tooltips and ToggleButtons (or any Button with click toggling enabled). Specifically, when I click on a ToggleButton that is currently in the “off” state, tooltips cease to appear.

After looking through the implementations of juce::Button and juce::TooltipWindow, it seems to be clear what is causing this.

juce_Button.cpp
See image A

The global modifiers are likely changed here so that any events triggered by setToggleState() will have the relevant modifiers, such as which mouse button was used to click the Button, even though the mouse was already released at this point. The only issue is that the modifers are never reverted back to their present state. Causing the following block of code to incorrectly be skipped:

juce_TooltipWindow.cpp
See image B

Because this issue is caused by the lack of anything changing the modifiers back to their present state, clicking anywhere will cause the tooltips to appear again.

Suggested fix:
After changing the modifiers and setting the toggle state, return the modifiers to their correct state
See image C

I can confirm that, after making this change locally, tooltips now appear as expected.

Image reference, to get around the maximum 1 upload requirement for new users:

Could you describe in a bit more detail the behaviour you’d expect to see, and the behaviour that you actually see?

I tested this out in the “WidgetsDemo” in the demo runner. This demo has some buttons with tooltips which can be hovered and clicked. I tried running on both macOS Catalina and Windows 10.

When I hover one of the radio button checkboxes (which are ToggleButton instances), I see a tooltip appear. When I press and hold the mouse button on a button that is off, the tooltip disappears. When I release the mouse button, the tooltip reappears after a short delay. Does this match what you see? If not, please ensure that you’re running the latest version of JUCE from the develop branch and try testing again.

Hi reuk, it looks the “unfixed” code I had for juce_Button.cpp never existed, and has always been the version that works correctly. Not sure how ModifierKeys::currentModifiers = modifiers got there. I don’t recall making any changes to it, but either way, the issue is solved now. Thanks for your patience and I’ll make sure to check the repository before posting in the future!

To follow up - I’ve made a tiny tweak to the behaviour of the TooltipWindow so that it will only re-display after the mouse is moved. This more closely matches behaviour I see in other apps.