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

MacOS: Disable window controls for windows created by JUCE when a Component is modal

The change does not affect plugin windows, which are created by the
host.
This commit is contained in:
attila 2024-01-04 17:44:00 +01:00
parent cc60286c89
commit fb14118771
3 changed files with 60 additions and 1 deletions

View file

@ -106,7 +106,10 @@ JUCE_IMPLEMENT_SINGLETON (ModalComponentManager)
void ModalComponentManager::startModal (Component* component, bool autoDelete)
{
if (component != nullptr)
{
stack.add (new ModalItem (component, autoDelete));
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
}
}
void ModalComponentManager::attachCallback (Component* component, Callback* callback)
@ -210,6 +213,8 @@ void ModalComponentManager::handleAsyncUpdate()
item->callbacks.getUnchecked (j)->modalStateFinished (item->returnValue);
compToDelete.deleteAndZero();
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
}
}
}

View file

@ -250,6 +250,31 @@ struct ComponentHelpers
if (modalWouldBlockComponent (*c, &modal))
(c->*function) (ms, SH::screenPosToLocalPos (*c, ms.getScreenPosition()), Time::getCurrentTime());
}
class ModalComponentManagerChangeNotifier
{
public:
static auto& getInstance()
{
static ModalComponentManagerChangeNotifier instance;
return instance;
}
ErasedScopeGuard addListener (std::function<void()> l)
{
return listeners.addListener (std::move (l));
}
void modalComponentManagerChanged()
{
listeners.call();
}
private:
ModalComponentManagerChangeNotifier() = default;
detail::CallbackListenerList<> listeners;
};
};
} // namespace juce::detail

View file

@ -1712,7 +1712,7 @@ public:
NSWindow* window = nil;
NSView* view = nil;
WeakReference<Component> safeComponent;
bool isSharedWindow = false;
const bool isSharedWindow = false;
#if USE_COREGRAPHICS_RENDERING
bool usingCoreGraphics = true;
#else
@ -1998,10 +1998,39 @@ private:
#endif
}
void modalComponentManagerChanged()
{
if (isSharedWindow)
return;
auto style = [window styleMask];
if (ModalComponentManager::getInstance()->getNumModalComponents() > 0)
{
style &= ~NSWindowStyleMaskMiniaturizable;
style &= ~NSWindowStyleMaskClosable;
}
else
{
const auto flags = getStyleFlags();
if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
}
[window setStyleMask: style];
}
//==============================================================================
std::vector<ScopedNotificationCenterObserver> scopedObservers;
std::vector<ScopedNotificationCenterObserver> windowObservers;
ErasedScopeGuard modalChangeListenerScope =
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().addListener ([this]
{
modalComponentManagerChanged();
});
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
};