| @@ -197,7 +197,7 @@ public: | |||||
| [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0]; | [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0]; | ||||
| [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0]; | [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0]; | ||||
| setCollectionBehaviour (false); | |||||
| [window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary]; | |||||
| [window setRestorable: NO]; | [window setRestorable: NO]; | ||||
| @@ -406,43 +406,16 @@ public: | |||||
| return [window isMiniaturized]; | 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 | void setFullScreen (bool shouldBeFullScreen) override | ||||
| { | { | ||||
| if (isSharedWindow) | if (isSharedWindow) | ||||
| return; | return; | ||||
| setCollectionBehaviour (shouldBeFullScreen); | |||||
| if (isMinimised()) | if (isMinimised()) | ||||
| setMinimised (false); | setMinimised (false); | ||||
| if (hasNativeTitleBar()) | |||||
| { | |||||
| if (shouldBeFullScreen != isFullScreen()) | |||||
| [window toggleFullScreen: nil]; | |||||
| } | |||||
| else | |||||
| { | |||||
| [window zoom: nil]; | |||||
| } | |||||
| if (shouldBeFullScreen != isFullScreen()) | |||||
| [window toggleFullScreen: nil]; | |||||
| } | } | ||||
| bool isFullScreen() const override | bool isFullScreen() const override | ||||
| @@ -1599,7 +1572,6 @@ public: | |||||
| } | } | ||||
| [NSApp setPresentationOptions: NSApplicationPresentationDefault]; | [NSApp setPresentationOptions: NSApplicationPresentationDefault]; | ||||
| setCollectionBehaviour (isFullScreen()); | |||||
| } | } | ||||
| void setHasChangedSinceSaved (bool b) override | void setHasChangedSinceSaved (bool b) override | ||||
| @@ -2335,6 +2307,7 @@ struct JuceNSWindowClass : public NSViewComponentPeerWrapper<ObjCClass<NSWindo | |||||
| addMethod (@selector (windowWillResize:toSize:), windowWillResize); | addMethod (@selector (windowWillResize:toSize:), windowWillResize); | ||||
| addMethod (@selector (windowDidExitFullScreen:), windowDidExitFullScreen); | addMethod (@selector (windowDidExitFullScreen:), windowDidExitFullScreen); | ||||
| addMethod (@selector (windowWillEnterFullScreen:), windowWillEnterFullScreen); | addMethod (@selector (windowWillEnterFullScreen:), windowWillEnterFullScreen); | ||||
| addMethod (@selector (windowWillExitFullScreen:), windowWillExitFullScreen); | |||||
| addMethod (@selector (windowWillStartLiveResize:), windowWillStartLiveResize); | addMethod (@selector (windowWillStartLiveResize:), windowWillStartLiveResize); | ||||
| addMethod (@selector (windowDidEndLiveResize:), windowDidEndLiveResize); | addMethod (@selector (windowDidEndLiveResize:), windowDidEndLiveResize); | ||||
| addMethod (@selector (window:shouldPopUpDocumentPathMenu:), shouldPopUpPathMenu); | addMethod (@selector (window:shouldPopUpDocumentPathMenu:), shouldPopUpPathMenu); | ||||
| @@ -2353,6 +2326,8 @@ struct JuceNSWindowClass : public NSViewComponentPeerWrapper<ObjCClass<NSWindo | |||||
| addMethod (@selector (window:shouldDragDocumentWithEvent:from:withPasteboard:), shouldAllowIconDrag); | addMethod (@selector (window:shouldDragDocumentWithEvent:from:withPasteboard:), shouldAllowIconDrag); | ||||
| addMethod (@selector (toggleFullScreen:), toggleFullScreen); | |||||
| addProtocol (@protocol (NSWindowDelegate)); | addProtocol (@protocol (NSWindowDelegate)); | ||||
| registerClass(); | registerClass(); | ||||
| @@ -2503,12 +2478,39 @@ private: | |||||
| return frameRect.size; | return frameRect.size; | ||||
| } | } | ||||
| static void toggleFullScreen (id self, SEL name, id sender) | |||||
| { | |||||
| if (auto* owner = getOwner (self)) | |||||
| { | |||||
| const auto isFullScreen = owner->isFullScreen(); | |||||
| if (! isFullScreen) | |||||
| owner->lastSizeBeforeZoom = owner->getBounds().toFloat(); | |||||
| sendSuperclassMessage<void> (self, name, sender); | |||||
| if (isFullScreen) | |||||
| { | |||||
| [NSApp setPresentationOptions: NSApplicationPresentationDefault]; | |||||
| owner->setBounds (owner->lastSizeBeforeZoom.toNearestInt(), false); | |||||
| } | |||||
| } | |||||
| } | |||||
| static void windowDidExitFullScreen (id self, SEL, NSNotification*) | static void windowDidExitFullScreen (id self, SEL, NSNotification*) | ||||
| { | { | ||||
| if (auto* owner = getOwner (self)) | if (auto* owner = getOwner (self)) | ||||
| owner->resetWindowPresentation(); | 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*) | static void windowWillEnterFullScreen (id self, SEL, NSNotification*) | ||||
| { | { | ||||
| if (SystemStats::getOperatingSystemType() <= SystemStats::MacOSX_10_9) | if (SystemStats::getOperatingSystemType() <= SystemStats::MacOSX_10_9) | ||||