# Disable maximise button on macOS?

**URL:** <https://forum.juce.com/t/disable-maximise-button-on-macos/27265>\
**Category:** MacOSX and iOS\
**Created:** [April 16, 2018, 8:31pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265 "2018-04-16T20:31:12Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgporter2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter2/32/3567_2.png) [@bgporter2](https://forum.juce.com/u/bgporter2)\
**Post date:** [April 16, 2018, 8:31pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/1 "2018-04-16T20:31:12Z")

</div>

How does one disable the maximise/fullscreen behavior on macOS?

My main window ctor looks like:

```
MainWindow::MainWindow (String name)
: DocumentWindow (name, Colours::grey, 0)
{
}

```

…but my title bar still has the maximis(z)e button active:

![buttons](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/6/6a254a4d12b73c08572e9129b742d677c11303d3.png)

On Windows, things behave as I’d expect, but under macOS, I can’t find a way to disable this behavior – there are resize limits specified for the app that are being ignored here (I’m assuming because `setBounds()` is being called directly, which I know isn’t affected by resize limits).

---

<div class="post-metadata">

**Author:** ![jonathonracz](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jonathonracz](https://forum.juce.com/u/jonathonracz)\
**Post date:** [April 16, 2018, 8:37pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/2 "2018-04-16T20:37:14Z")

</div>

FWIW, I’ve been having the same problem and would also like to know.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [April 17, 2018, 4:05am UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/3 "2018-04-17T04:05:54Z")

</div>

I might be mistaken, but I think you gotta set the flag directly on the Component Peer instance.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 17, 2018, 7:50am UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/4 "2018-04-17T07:50:23Z")

</div>

Correct, the [ComponentPeer::StyleFlags](https://docs.juce.com/develop/classComponentPeer.html#a94a21f91c61f8211774d6f43243a6ddc) are defined for the ComponentPeer.

But you can set them, when you put your window to the desktop, when you called [Component::addToDesktop (int windowStyleFlags, void\* nativeWindowToAttachTo = nullptr)](https://docs.juce.com/develop/classComponent.html#ad717da76012d971197fd8cf943f3e721)

Adding: if you use the [DocumentWindow](https://docs.juce.com/develop/classDocumentWindow.html#a0b97fb8d09a99701368b33445bc0cf94), there is another enum flag in the constructor specifically for which buttons to use:

> requiredButtons   
> specifies which of the buttons (close, minimise, maximise) should be shown on the title bar. This value is a bitwise combination of values from the TitleBarButtons enum.  
> Note that it can be “allButtons” to get them all. You can change this later with the setTitleBarButtonsRequired() method, which can also specify where they are positioned.

---

<div class="post-metadata">

**Author:** ![bgporter2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter2/32/3567_2.png) [@bgporter2](https://forum.juce.com/u/bgporter2)\
**Post date:** [April 17, 2018, 1:19pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/5 "2018-04-17T13:19:01Z")

</div>

Right, that’s my puzzlement – I’m setting the style flags here to zero, which on Windows successfully disables all three buttons. On macOS, I’ve stepped down into the guts of the ComponentPeer code for macOS, and it looks like the maximise flag is completely ignored?

```
static unsigned int getNSWindowStyleMask (const int flags) noexcept
{
    unsigned int style = (flags & windowHasTitleBar) != 0 ? NSWindowStyleMaskTitled
                                                          : NSWindowStyleMaskBorderless;

    if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
    if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
    if ((flags & windowIsResizable) != 0) style |= NSWindowStyleMaskResizable;
    return style;
}

```

…so we go more deeply into the component peer code to the point where we’re creating and initializing the `NSWindow` that our component uses, and looking up the valid values of [`NSWindowStyleMask`](https://developer.apple.com/documentation/appkit/nswindowstylemask?language=objc) on the Apple developer website, we note that there’s no style flag present to affect this fullscreen/maximize behavior, so not a JUCE problem, a macOS design that makes me harrumph.

Since my app is designed to have a maximum size, I guess that the approach to take here is:

1. When we’re on the mac
2. In my main component’s `paint()` method, look to see if the local bounds are larger than the current max size as set by the last call to `setResizeLimits()`
3. If so, fill the bounds in a bg color, and then make sure that my component is actually drawn into a new rect at the maximum size, centered within the window bounds.

Better ideas (not including ‘redesign the UI to work at arbitrary sizes’), anyone?

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [April 17, 2018, 8:31pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/6 "2018-04-17T20:31:55Z")

</div>

The buttons on the Window’s title bar are actually accessible through some Objective-c code. I have a routine which show/hides those buttons.  
The void\* view pointer is retrieved by calling getPeer()-\>getNativeHandle().

```
void OSXUIUtils::showHideWindowButtons(void* view, bool show, bool animate, float duration)
{
	NSView* nsView = (NSView*)view;
	NSWindow* nsWindow = [nsView window];
	
//[nsWindow setWindowController:(__kindof NSWindowController * _Nullable)

	CGFloat alpha = show ? 1.0 : 0.0;
	if (animate)
	{
		[NSAnimationContext beginGrouping];
		[[NSAnimationContext currentContext] setDuration:duration];
		[[[nsWindow standardWindowButton:NSWindowMiniaturizeButton] animator] setAlphaValue:alpha];
		[[[nsWindow standardWindowButton:NSWindowZoomButton] animator] setAlphaValue:alpha];
		[[[nsWindow standardWindowButton:NSWindowCloseButton] animator] setAlphaValue:alpha];
		[NSAnimationContext endGrouping];
	} else {
		[[nsWindow standardWindowButton:NSWindowMiniaturizeButton] setAlphaValue:alpha];
		[[nsWindow standardWindowButton:NSWindowZoomButton] setAlphaValue:alpha];
		[[nsWindow standardWindowButton:NSWindowCloseButton] setAlphaValue:alpha];
	}
}
```

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [April 17, 2018, 8:36pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/7 "2018-04-17T20:36:21Z")

</div>

Or something like this:

```
void OSXUIUtils::hideFullscreenButton(void* view)
{
	NSView* nsView = (NSView*)view;
	NSWindow* nsWindow = [nsView window];
	NSButton *button = [nsWindow standardWindowButton:NSWindowFullScreenButton];
	[button setHidden:YES];
	button.alphaValue = 0.0;
	[button setEnabled:NO];
	button.image = nil;
	button.alternateImage = nil;
}
```

---

<div class="post-metadata">

**Author:** ![bgporter2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter2/32/3567_2.png) [@bgporter2](https://forum.juce.com/u/bgporter2)\
**Post date:** [April 17, 2018, 9:45pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/8 "2018-04-17T21:45:59Z")

</div>

Wow, thanks. I’ll dig into this.

---

<div class="post-metadata">

**Author:** ![jonathonracz](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jonathonracz](https://forum.juce.com/u/jonathonracz)\
**Post date:** [April 18, 2018, 1:28am UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/9 "2018-04-18T01:28:22Z")

</div>

I mean, shouldn’t this “just work” in JUCE without a native workaround? It sounds like a big bug or oversight for some of the desktop option flags to simply _not work_…

---

<div class="post-metadata">

**Author:** ![rusty](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@rusty](https://forum.juce.com/u/rusty)\
**Post date:** [April 18, 2018, 2:54am UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/10 "2018-04-18T02:54:09Z")

</div>

I’m doing something like this. Think it works.

```
 MainWindow::MainWindow() : DocumentWindow(name, Colours::grey, DocumentWindow::TitleBarButtons::closeButton | DocumentWindow::TitleBarButtons::minimiseButton)
```

---

<div class="post-metadata">

**Author:** ![alexeismith](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@alexeismith](https://forum.juce.com/u/alexeismith)\
**Post date:** [May 9, 2021, 9:43pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/11 "2021-05-09T21:43:29Z")

</div>

Hi, this bug still seems to be present. I’m trying to disable the maximise button in my MacOS app, but the following leaves all three showing:  
`MainWindow::MainWindow() : DocumentWindow(..., ..., DocumentWindow::TitleBarButtons::minimiseButton | DocumentWindow::TitleBarButtons::closeButton)`

Including just `DocumentWindow::TitleBarButtons::closeButton` hides the minimise button only, and vice versa, so it seems the maximise flag is the only problem.

The same happens if I use `setTitleBarButtonsRequired()` in the constructor.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [July 1, 2021, 6:59pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/12 "2021-07-01T18:59:38Z")

</div>

Yup still having the same problem here in macOS, and for a DocumentWindow that I definitely don’t want to allow to be maximized.

Calling this in the DocumentWindow constructor still results in a window with the maximize button in the title-bar:

`setTitleBarButtonsRequired (0, true);`

Additionally, the `maximiseButtonPressed` callback is being ignored ([as reported here](https://forum.juce.com/t/bug-maximisebuttonpressed-event-never-fired-macos-catalina/39226) as well) - so I’m not able to disable the maximize action.

ref: [setTitleBarButtonsRequired](https://docs.juce.com/master/classDocumentWindow.html#af9549ecc64c2b7e91161a49c44b6ae17), [maximiseButtonPressed](https://docs.juce.com/master/classDocumentWindow.html#a1d2ce7145c2e6da062e22589543ea037)

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [December 29, 2021, 12:39am UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/13 "2021-12-29T00:39:04Z")

</div>

Any of the JUCE devs gotten to take a look at this?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [January 11, 2022, 12:51pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/14 "2022-01-11T12:51:07Z")

</div>

I’ve updated the behaviour a bit here:

> <https://github.com/juce-framework/JUCE/commit/8a2bde9fec5e8de53331d4378e241ad78ed51053>
>
> Effects of this change for windows with native titlebars:
> \- Resizable windows wi…thout maximise buttons will now only allow the
> 'zoom' behaviour from the rightmost titlebar button (i.e. this button
> will not allow entering full-screen mode)
> \- Non-resizable windows will grey-out the rightmost titlebar button,
> whether or not the maximise button is enabled

The ‘zoom’ button will now be disabled for non-resizable windows. The ‘maximize’ flag for the document window now controls whether the window is able to enter true full-screen mode.

In testing, this seemed a lot more intuitive than the current behaviour. Hopefully you’ll agree!

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [January 11, 2022, 7:03pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/15 "2022-01-11T19:03:26Z")

</div>

Thank you @reuk, that is huge improvement in window behavior. Just tested those changes out here. Blocking full-screen mode is a sufficient fix for my purposes.

I’ll mention two things that might still be patched up a bit, though neither one is pressing for me:

1. The docs for [DocumentWindow::setTitleBarButtonsRequired](https://docs.juce.com/master/classDocumentWindow.html#af9549ecc64c2b7e91161a49c44b6ae17) say the `requiredButtons` flags will determine which buttons will be _shown_ on the title bar. Since this is not the actual behavior (on macOS anyways) maybe that could be amended.

2. The `maximiseButtonPressed` callback is still not getting called, regardless of the setting of the `maximize` flag.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [January 17, 2022, 2:46pm UTC](https://forum.juce.com/t/disable-maximise-button-on-macos/27265/16 "2022-01-17T14:46:57Z")

</div>

> [@refusesoftware](#):
>
> The `maximiseButtonPressed` callback is still not getting called, regardless of the setting of the `maximize` flag.

It’s not clear to me that it should be called in this case. It doesn’t seem to be called on other platforms when using native titlebars.
