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

MacOS: Fix invisible PopupMenu in Logic

We avoid modifying window controls in modal situations if possible.
Doing as much as [window setStyleMask: [window styleMask]]; for a
PopupMenu window will make it invisible on MacOS when the plugin is
hosted in an external subprocess.

This fixes a regression caused by
fb14118771.
This commit is contained in:
attila 2024-01-30 11:19:56 +01:00
parent a028f277c1
commit 6056c686b8

View file

@ -1998,33 +1998,83 @@ private:
#endif
}
/* Used to store and restore the values of the NSWindowStyleMaskClosable and
NSWindowStyleMaskMiniaturizable flags.
*/
struct StoredStyleFlags
{
StoredStyleFlags (NSWindowStyleMask m)
: stored { m }
{}
static auto getStoredFlags()
{
return std::array<NSWindowStyleMask, 2> { NSWindowStyleMaskClosable,
NSWindowStyleMaskMiniaturizable };
}
auto withFlagsRestored (NSWindowStyleMask m) const
{
for (const auto& f : getStoredFlags())
m = withFlagFromStored (m, f);
return m;
}
private:
NSWindowStyleMask withFlagFromStored (NSWindowStyleMask m, NSWindowStyleMask flag) const
{
return (m & ~flag) | (stored & flag);
}
NSWindowStyleMask stored;
};
void modalComponentManagerChanged()
{
if (isSharedWindow)
// We are only changing the style flags if we absolutely have to. Plugin windows generally
// don't like to be modified. Windows created under plugin hosts running in an external
// subprocess are particularly touchy, and may make the window invisible even if we call
// [window setStyleMask [window setStyleMask]].
if (isSharedWindow || ! hasNativeTitleBar())
return;
auto style = [window styleMask];
const auto newStyleMask = [&]() -> std::optional<NSWindowStyleMask>
{
const auto currentStyleMask = [window styleMask];
if (ModalComponentManager::getInstance()->getNumModalComponents() > 0)
{
style &= ~NSWindowStyleMaskMiniaturizable;
style &= ~NSWindowStyleMaskClosable;
if (! storedFlags)
storedFlags.emplace (currentStyleMask);
auto updatedMask = (storedFlags->withFlagsRestored (currentStyleMask)) & ~NSWindowStyleMaskMiniaturizable;
if (component.isCurrentlyBlockedByAnotherModalComponent())
updatedMask &= ~NSWindowStyleMaskClosable;
return updatedMask;
}
else
if (storedFlags)
{
const auto flags = getStyleFlags();
if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
const auto flagsToApply = storedFlags->withFlagsRestored (currentStyleMask);
storedFlags.reset();
return flagsToApply;
}
[window setStyleMask: style];
return {};
}();
if (newStyleMask && *newStyleMask != [window styleMask])
[window setStyleMask: *newStyleMask];
}
//==============================================================================
std::vector<ScopedNotificationCenterObserver> scopedObservers;
std::vector<ScopedNotificationCenterObserver> windowObservers;
std::optional<StoredStyleFlags> storedFlags;
ErasedScopeGuard modalChangeListenerScope =
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().addListener ([this]
{