From 10a26b758471cdc68729eeb220bf72bd1edcb76e Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 23 Aug 2021 19:58:03 +0100 Subject: [PATCH] TooltipWindow: Avoid re-showing a tooltip if the mouse has not moved since it was last clicked This behaviour more closely mirrors the behaviour of other applications. --- .../windows/juce_TooltipWindow.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp index cb68fe42eb..cef1bca8f9 100644 --- a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp @@ -191,6 +191,14 @@ void TooltipWindow::timerCallback() if (tipChanged || mouseWasClicked || mouseMovedQuickly) lastCompChangeTime = now; + auto showTip = [this, &mouseSource, &mousePos, &newTip] + { + bool mouseHasMovedSinceClick = mouseSource.getLastMouseDownPosition() != lastMousePos; + + if (mouseHasMovedSinceClick) + displayTip (mousePos.roundToInt(), newTip); + }; + if (isVisible() || now < lastHideTime + 500) { // if a tip is currently visible (or has just disappeared), update to a new one @@ -205,18 +213,17 @@ void TooltipWindow::timerCallback() } else if (tipChanged) { - displayTip (mousePos.roundToInt(), newTip); + showTip(); } } else { - // if there isn't currently a tip, but one is needed, only let it - // appear after a timeout.. + // if there isn't currently a tip, but one is needed, only let it appear after a timeout if (newTip.isNotEmpty() - && newTip != tipShowing - && now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears) + && newTip != tipShowing + && now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears) { - displayTip (mousePos.roundToInt(), newTip); + showTip(); } } }