NSWindow styleMask and full screen

  • I have an application where sometimes I need to go full screen. While in full screen mode, I need to change the presentation mode so that sometimes the menubar and toolbar are autohiding, and sometimes just not shown. Then when I exit full screen, I reset the values to what they were before I started.

    This works fine, except that when I return from full screen, the minimize button is disabled on the window.

    So I thought I would record the styleMask of the window before going full screen, and then restore it afterwards.

    When I ask for the window's styleMask, I get a value of 4111 which according to the documentation would be an impossible value. If I just use that value for setStyleMask: later in my program, my minimize button is still disabled.

    I'm suspecting that Apple must be using the value for other things too, so I thought I would use:

        oldStyleMask = [window styleMask];

        oldStyleMask = oldStyleMask & (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSTexturedBackgroundWindowMask);

    … do stuff …

        [window setStyleMask:oldStyleMask];

    Now when I use the & statement, I get a value of 15, which matches how the window looks, but setting the style mask back to that value still doesn't enable the minimize button.

    I looked around and found a suggestion on stack overflow http://stackoverflow.com/questions/7888308/nswindow-loses-miniaturize-butto
    n-on-lion
    , but the idea there would only be applicable if I was keeping the same application presentation options for the whole time I'm in full screen, which is not the case.

    I have the same problem on 10.6, and the proposed workaround linked off stack overflow doesn't work - presumably because I change the application presentation options.

    I even thought I would try to be smart and override styleMask with the following:

    - (NSUInteger)styleMask {
        return [super styleMask]|NSMiniaturizableWindowMask;
    }

    But even that wouldn't enable the miniaturize button!

    Does anyone know of a workaround for this?

    TIA

    Gideon
  • It's an Apple bug - I meant to file it but apparently didn't; I should do that. It's nothing to do with the styleMask; sometimes the window sets the buttonCell's temporarilyDisabled flag and doesn't restore it.

    From a comment in my code:
    * temporarilyDisabled should only be YES when the menubar is hidden, but sometimes
    * the window code gets confused and doesn't reset it for windows that
    * were changing state at the same time as the menu.

    ----- Original Message -----
    From: "Gideon King" <gideon...>
    To: "Cocoa-Dev List" <cocoa-dev...>
    Sent: Thursday, July 19, 2012 6:54:22 PM
    Subject: NSWindow styleMask and full screen

    I have an application where sometimes I need to go full screen. While in full screen mode, I need to change the presentation mode so that sometimes the menubar and toolbar are autohiding, and sometimes just not shown. Then when I exit full screen, I reset the values to what they were before I started.

    This works fine, except that when I return from full screen, the minimize button is disabled on the window.

    So I thought I would record the styleMask of the window before going full screen, and then restore it afterwards.

    When I ask for the window's styleMask, I get a value of 4111 which according to the documentation would be an impossible value. If I just use that value for setStyleMask: later in my program, my minimize button is still disabled.

    I'm suspecting that Apple must be using the value for other things too, so I thought I would use:

        oldStyleMask = [window styleMask];

        oldStyleMask = oldStyleMask & (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSTexturedBackgroundWindowMask);

    … do stuff …

        [window setStyleMask:oldStyleMask];

    Now when I use the & statement, I get a value of 15, which matches how the window looks, but setting the style mask back to that value still doesn't enable the minimize button.

    I looked around and found a suggestion on stack overflow http://stackoverflow.com/questions/7888308/nswindow-loses-miniaturize-butto
    n-on-lion
    , but the idea there would only be applicable if I was keeping the same application presentation options for the whole time I'm in full screen, which is not the case.

    I have the same problem on 10.6, and the proposed workaround linked off stack overflow doesn't work - presumably because I change the application presentation options.

    I even thought I would try to be smart and override styleMask with the following:

    - (NSUInteger)styleMask {
        return [super styleMask]|NSMiniaturizableWindowMask;
    }

    But even that wouldn't enable the miniaturize button!

    Does anyone know of a workaround for this?

    TIA

    Gideon
  • It turns out that on 10.6+ at least, just setting the button cell to enabled does the trick:

        NSButton *button = [window standardWindowButton:NSWindowMiniaturizeButton];
        NSButtonCell *buttonCell = [button cell];
        [buttonCell setEnabled:YES];

    Still, it's definitely an Apple bug, and I'll file a bug report.

    Regards

    Gideon

    On 20/07/2012, at 12:16 PM, Lee Ann Rucker <lrucker...> wrote:

    > It's an Apple bug - I meant to file it but apparently didn't; I should do that. It's nothing to do with the styleMask; sometimes the window sets the buttonCell's temporarilyDisabled flag and doesn't restore it.
    >
    > From a comment in my code:
    > * temporarilyDisabled should only be YES when the menubar is hidden, but sometimes
    > * the window code gets confused and doesn't reset it for windows that
    > * were changing state at the same time as the menu.
    >
    >
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today