Ad

Our DNA is written in Swift
Jump

The Lion’s Full Screen Mode

Native Mac apps can and should support full screen mode. Apple calls it providing users “with a more immersive, cinematic experience”. While there a a few apps that would not reap any benefit for the user taking over the entire monitor, there are some apps that can benefit from it greatly. In my case a productivity app like iCatalog Editor.

I was afraid that implementing Full Screen would take lots of work, but luckily Apple has created a standard method of doing Full Screen as of 10.7, they even encourage vendors of legacy apps to change to the new APIs.

Mission Control, accessible from the trackpad with a three finger upward swipe, supports this new full screen mode such that apps in full screen appear as their own dynamic desktops and you can quickly switch between these swiping sideways.

Implementing this was so quick I almost thought that it would be too little meat for an actual article. But there are a few things that I want to document here because they might not be obvious.

The ability to go full screen is a property of NSWindow. There are three options for each window.

  • Unsupported (Default)
  • Primary Window
  • Auxiliary Window

The frontmost window that has the Primary Window attribute will be the one that is enlarged to full screen and also gets the full screen button attached in the top right corner of the window bar.

The best example for when to use Auxiliary Window was given to me by Andreas Monitzer:

“Xcode’s organizer window (CMD+Shift+2). That’s the only way to use multiple windows with 10.7+ fullscreen mode. That’s Apple’s poor excuse for lack of multi-monitor support on fullscreen mode.”

To set this attribute I went into my window controller xib which contains the instantiation of my document window. If you create a new document-based app this is confusingly named like the NSDocument subclass, even though it is owned by the NSWindowController. This is because you usually don’t need to customize the window controller.

There you find the Full Screen setting on the tab with the shield.

The second step is now to also add a menu item to toggle between full and non-full screen mode. The First Responder offers the toggleFullScreen: action to wire this up with the new menu item. The usual keyboard shortcut for this seems to be Ctrl+Cmd+F.

I know from my previous research that there would probably be some object in the responder chain that would act on this action. So when we launch this app we now can toggle Full Screen either via the automatically added button in the top right corner as well as the menu option or by the key equivalent.

I was quite surprised to see that the system did also automatically rename the menu option for me. This is what I call awesome code: the one I didn’t have to write.

In fact it doesn’t matter in the least what text you put there in your MainMenu, Apple also tacitly had replaced our text with the system standard “Enter Full Screen”.

Now there are a few other options to affect automatically hiding a toolbar your window might have, but in our case we’ll leave the toolbar in place because it contains often used tools for the user.

Conclusion

Never before did I implement an Apple API that quickly. Set a setting, add a menu item and be done with it.

Media-oriented applications can greatly benefit from a Full Screen viewing mode, productivity apps allow for maximum screen space for the document that’s being worked on.

If your app can offer a benefit to the user then there is no excuse for not supporting the new full screen option which Apple has made exceptionally simple to implement.


Categories: Recipes

3 Comments »

  1. This helped me to understand the initial steps of making an app with Full screen. Thanks a lot, author!!!