From eabcfbad26c658f628796e4433a76365df3cdeb2 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 1 Feb 2022 18:25:50 +0000 Subject: [PATCH] NSViewComponentPeer: Add support for true-full-screen with non-native titlebars --- .../native/juce_mac_NSViewComponentPeer.mm | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index d8b8b0fb02..58205af1cd 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -197,7 +197,7 @@ public: [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0]; [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0]; - setCollectionBehaviour (false); + [window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary]; [window setRestorable: NO]; @@ -406,43 +406,16 @@ public: return [window isMiniaturized]; } - NSWindowCollectionBehavior getCollectionBehavior (bool forceFullScreen) const - { - if (forceFullScreen) - return NSWindowCollectionBehaviorFullScreenPrimary; - - // Some SDK versions don't define NSWindowCollectionBehaviorFullScreenNone - constexpr auto fullScreenNone = (NSUInteger) (1 << 9); - - return (getStyleFlags() & (windowHasMaximiseButton | windowIsResizable)) == (windowHasMaximiseButton | windowIsResizable) - ? NSWindowCollectionBehaviorFullScreenPrimary - : fullScreenNone; - } - - void setCollectionBehaviour (bool forceFullScreen) const - { - [window setCollectionBehavior: getCollectionBehavior (forceFullScreen)]; - } - void setFullScreen (bool shouldBeFullScreen) override { if (isSharedWindow) return; - setCollectionBehaviour (shouldBeFullScreen); - if (isMinimised()) setMinimised (false); - if (hasNativeTitleBar()) - { - if (shouldBeFullScreen != isFullScreen()) - [window toggleFullScreen: nil]; - } - else - { - [window zoom: nil]; - } + if (shouldBeFullScreen != isFullScreen()) + [window toggleFullScreen: nil]; } bool isFullScreen() const override @@ -1599,7 +1572,6 @@ public: } [NSApp setPresentationOptions: NSApplicationPresentationDefault]; - setCollectionBehaviour (isFullScreen()); } void setHasChangedSinceSaved (bool b) override @@ -2335,6 +2307,7 @@ struct JuceNSWindowClass : public NSViewComponentPeerWrapperisFullScreen(); + + if (! isFullScreen) + owner->lastSizeBeforeZoom = owner->getBounds().toFloat(); + + sendSuperclassMessage (self, name, sender); + + if (isFullScreen) + { + [NSApp setPresentationOptions: NSApplicationPresentationDefault]; + owner->setBounds (owner->lastSizeBeforeZoom.toNearestInt(), false); + } + } + } + static void windowDidExitFullScreen (id self, SEL, NSNotification*) { if (auto* owner = getOwner (self)) owner->resetWindowPresentation(); } + static void windowWillExitFullScreen (id self, SEL, NSNotification*) + { + // The exit-fullscreen animation looks bad on Monterey if the window isn't resizable... + if (auto* owner = getOwner (self)) + if (auto* window = owner->window) + [window setStyleMask: [window styleMask] | NSWindowStyleMaskResizable]; + } + static void windowWillEnterFullScreen (id self, SEL, NSNotification*) { if (SystemStats::getOperatingSystemType() <= SystemStats::MacOSX_10_9)