Browse Source

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.
v7.0.12
attila 2 years ago
parent
commit
fb14118771
3 changed files with 60 additions and 1 deletions
  1. +5
    -0
      modules/juce_gui_basics/components/juce_ModalComponentManager.cpp
  2. +25
    -0
      modules/juce_gui_basics/detail/juce_ComponentHelpers.h
  3. +30
    -1
      modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm

+ 5
- 0
modules/juce_gui_basics/components/juce_ModalComponentManager.cpp View File

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


+ 25
- 0
modules/juce_gui_basics/detail/juce_ComponentHelpers.h View File

@@ -250,6 +250,31 @@ struct ComponentHelpers
if (modalWouldBlockComponent (*c, &modal)) if (modalWouldBlockComponent (*c, &modal))
(c->*function) (ms, SH::screenPosToLocalPos (*c, ms.getScreenPosition()), Time::getCurrentTime()); (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 } // namespace juce::detail

+ 30
- 1
modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm View File

@@ -1712,7 +1712,7 @@ public:
NSWindow* window = nil; NSWindow* window = nil;
NSView* view = nil; NSView* view = nil;
WeakReference<Component> safeComponent; WeakReference<Component> safeComponent;
bool isSharedWindow = false;
const bool isSharedWindow = false;
#if USE_COREGRAPHICS_RENDERING #if USE_COREGRAPHICS_RENDERING
bool usingCoreGraphics = true; bool usingCoreGraphics = true;
#else #else
@@ -1998,10 +1998,39 @@ private:
#endif #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> scopedObservers;
std::vector<ScopedNotificationCenterObserver> windowObservers; std::vector<ScopedNotificationCenterObserver> windowObservers;
ErasedScopeGuard modalChangeListenerScope =
detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().addListener ([this]
{
modalComponentManagerChanged();
});
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
}; };


Loading…
Cancel
Save