0

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?

RJVB
  • 698
  • 8
  • 18
  • Even with "legacy" Spaces mode, the Dock is not necessarily on the primary screen. It can be configured to show on the left or right side of the desktop, which can put it on another screen. – Ken Thomases May 23 '17 at 13:19
  • Hmm, you're right. Same thing for putting it on the bottom if the secondary screen is put under the "main" screen. In that case you'd have to use Hofi's approach below, OR put the Dock into auto-hiding mode (temporarily, if that's possible). – RJVB May 24 '17 at 14:00
  • I wonder though if this is a common set-up. I'd find it annoying not to have both elements on the same screen, and to have their relative positions change when I need to work with only a single screen for a while (think laptop). That doesn't apply to a bottom-Dock and vertically stacked screens, but how many people would do *that* :) – RJVB May 24 '17 at 14:04
  • I have dual monitors with the primary on the left and the Dock on the right. So, it's common for me. ;) – Ken Thomases May 24 '17 at 14:47
  • Hah, that explains why you thought of it :P Would you mind personally if your Dock auto-hides when a fullscreen application is active on the left screen, knowing that you can still get at it by "touching" the right screen border with the mouse cursor? – RJVB May 25 '17 at 15:20
  • It would strike me as a bit strange, but not very annoying. – Ken Thomases May 25 '17 at 16:30

2 Answers2

3

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
Hofi
  • 945
  • 1
  • 6
  • 18
  • I should have thought of this; it would provide a solution on pre-10.9 systems that lack `[NSScreen +screensHaveSeparateSpaces]`. But wait, those don't have 2 inconsistent fullscreen modes :) Thanks anyway. – RJVB May 19 '17 at 11:33
  • 1
    Note that this method doesn't work when the dock is hidden. – George May 16 '20 at 05:28
1

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.

CRD
  • 52,522
  • 5
  • 70
  • 86
  • Thanks. It seemed to be "teh answer" but it's good to have confirmation:) And yeah, I'm running 10.9 and am not really sure the documentation available through Xcode is really up-to-date. And I avoid running that IDE when I can, using a Dash clone to browse my local API docs most of the time. (I really enjoyed using Xcode 3.2.x but the later, monolithic versions ... not so much.) – RJVB Apr 24 '17 at 10:20