1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

PopupMenu: Avoid giving focus back to previous component on dismiss

This change is designed to fix issues with views stealing focus and
being brought to the front when popup menus are dismissed.

To test this behaviour:
- Open two instances "a" and "b" of a plugin editor containing a
  ComboBox
- Click the ComboBox in editor "a", opening its PopupMenu
- Drag the titlebar of editor "b" to move it
- The PopupMenu should be dismissed, but editor "a" should *not* steal
  keyboard focus or be brought to the front
This commit is contained in:
reuk 2021-10-19 20:14:17 +01:00
parent f562517939
commit c2f661171a
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -2013,38 +2013,29 @@ struct PopupMenuCompletionCallback : public ModalComponentManager::Callback
if (PopupMenuSettings::menuWasHiddenBecauseOfAppChange)
return;
auto* focusComponent = getComponentToPassFocusTo();
const auto focusedIsNotMinimised = [focusComponent]
if (auto* focusComponent = Component::getCurrentlyFocusedComponent())
{
if (focusComponent != nullptr)
const auto focusedIsNotMinimised = [focusComponent]
{
if (auto* peer = focusComponent->getPeer())
return ! peer->isMinimised();
return false;
}();
return false;
}();
if (focusedIsNotMinimised)
{
if (auto* topLevel = focusComponent->getTopLevelComponent())
topLevel->toFront (true);
if (focusedIsNotMinimised)
{
if (auto* topLevel = focusComponent->getTopLevelComponent())
topLevel->toFront (true);
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
focusComponent->grabKeyboardFocus();
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
focusComponent->grabKeyboardFocus();
}
}
}
Component* getComponentToPassFocusTo() const
{
if (auto* current = Component::getCurrentlyFocusedComponent())
return current;
return prevFocused.get();
}
ApplicationCommandManager* managerOfChosenCommand = nullptr;
std::unique_ptr<Component> component;
WeakReference<Component> prevFocused { Component::getCurrentlyFocusedComponent() };
JUCE_DECLARE_NON_COPYABLE (PopupMenuCompletionCallback)
};