From 858aab823ae103008414f1af8d29559266e1220b Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 30 Mar 2022 14:31:33 +0100 Subject: [PATCH] ComponentBoundsConstrainer: Properly constrain secondary windows in plugins --- .../layout/juce_ComponentBoundsConstrainer.cpp | 4 +++- modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp b/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp index cc04a06144..ac3aec1d98 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp @@ -104,7 +104,9 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* component, if (auto* parent = component->getParentComponent()) return { parent->getWidth(), parent->getHeight() }; - if (auto* display = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre())) + const auto globalBounds = component->localAreaToGlobal (targetBounds - component->getPosition()); + + if (auto* display = Desktop::getInstance().getDisplays().getDisplayForPoint (globalBounds.getCentre())) return component->getLocalArea (nullptr, display->userArea) + component->getPosition(); const auto max = std::numeric_limits::max(); diff --git a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp index bd92b35a13..ac84cacbf0 100644 --- a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp @@ -294,7 +294,7 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const const auto scale = getDesktopScaleFactor() / Desktop::getInstance().getGlobalScaleFactor(); auto targetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre()) / scale; - auto parentArea = c->getParentMonitorArea(); + auto parentArea = getLocalArea (nullptr, c->getParentMonitorArea()); if (auto* parent = getParentComponent()) {