Reputation: 776
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?
Upvotes: 0
Views: 1193
Reputation: 966
NSScreen has two properties
frame
This is the full screen rectangle at the current resolution. This rectangle includes any space currently occupied by the menu bar and dock.
visibleFrame
This is the rectangle defining the portion of the screen in which it is currently safe to draw your application content.
The returned rectangle is always based on the current user-interface settings and does not include the area currently occupied by the dock and menu bar. Because it is based on the current user-interface settings, the returned rectangle can change between calls and should not be cached.
Even when dock hiding is enabled, the rectangle returned by this method may be smaller than the full screen. The system uses a small boundary area to determine when it should display the dock.
So, if they are different, than the screen has menubar and/or dock
Upvotes: 3
Reputation: 53000
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.
Upvotes: 1