Search code examples
cocoafullscreenmultiple-monitorsmission-control

Mac/Cocoa: how to determine if a window's screen has menubar and Dock?


Something apparently went wrong with my 1st attempt to ask the question below:

I'm trying to write a legacy fullscreen toggling function that should put a window in or out of fullscreen mode on its current screen (monitor) while leaving the contents of other screens unaffected - regardless of how Spaces are configured.

I've got it working for the "legacy" Spaces mode where each Space spans all attached screens. In that case there's only 1 menubar and Dock, both on the primary screen which can be obtained with [[NSScreen screens] firstObject]. Thus, I can do something like

        if ([nsWin screen] == [[NSScreen screens] firstObject]) {
            m_normalPresOpts = [nsApp presentationOptions];
            [nsApp setPresentationOptions:m_normalPresOpts | NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock];
        }

to get the Dock and Menubar to auto-hide only when the fullscreen window is on the primary screen.

Apple made it impossible to toggle the Spaces setting without restarting the login session so I do not even know at this point how the above code works when screens have individual Spaces. I suspect though that [[NSScreen screens] firstObject] will then still contain the screen that has its upper-left corner at (0,0) and thus fullscreen windows on other screens will continue to have the menubar and Dock visible. Also, I'm still running 10.9 and would just as well prefer to get this right at once for later versions too.

Is there a way to determine programmatically how Spaces are configured or to know whether a given screen contains the menubar/Dock? Googling didn't give me any results relevant to doing this from code. Somehow I missed [NSScreen +screensHaveSeparateSpaces] in my on-disk documentation, is that the definitive answer to my question?


Solution

  • Is there a way to determine programmatically how Spaces are configured or to know whether a given screen contains the menubar/Dock? Googling didn't give me any results relevant to doing this from code. Somehow I missed [NSScreen +screensHaveSeparateSpaces] in my on-disk documentation, is that the definitive answer to my question?

    Yes.

    BTW you might have missed it in the documentation if your docs were out of date as this method was introduced as part of the new spaces model without being documented - it only existed in the header file. At some point between then and now the documentation caught up.