From 51b0319342c23f559bc19fd9edd296e303469b44 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 3 Mar 2025 13:42:06 +0000 Subject: [PATCH] PopupMenu: Always attach a global mouse listener This makes behaviour more consistent between the parented and non-parented display modes. Before this change, parented popup menus wouldn't respond to mouse clicks until the mouse was released once, which meant that clicking and dragging the mouse over a menu wouldn't trigger a menu item on mouse-up. --- modules/juce_gui_basics/menus/juce_PopupMenu.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 74d161749b..1d00ffd7f9 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -375,10 +375,13 @@ struct MenuWindow final : public Component addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses | lf.getMenuWindowFlags()); - - Desktop::getInstance().addGlobalMouseListener (this); } + // Using a global mouse listener means that we get notifications about all mouse events. + // Without this, drags that are started on a button that displays a menu won't reach the + // menu, because they *only* target the component that initiated the drag interaction. + Desktop::getInstance().addGlobalMouseListener (this); + if (options.getParentComponent() == nullptr && parentWindow == nullptr && lf.shouldPopupMenuScaleWithTargetComponent (options)) if (auto* targetComponent = options.getTargetComponent()) scaleFactor = Component::getApproximateScaleFactorForComponent (targetComponent);