Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display macOS window full screen on secondary monitor using Cocoa

I'm working on a Cocoa Mac app where I need to display a window/view on a secondary monitor, full-screen.

I know how to create a window that could be dragged onto the secondary monitor, but I was wanting to programmatically create the window and make it full screen on the external monitor.

like image 640
Austin Avatar asked Dec 30 '08 19:12

Austin


2 Answers

First, determine which screen you want to use by iterating over [NSScreen screens].

Create a full screen window with:

NSScreen *screen = /* from [NSScreen screens] */
NSRect screenRect = [screen frame];
NSWindow *window = [[NSWindow alloc] initWithContentRect:screenRect
    styleMask:NSBorderlessWindowMask
    backing:NSBackingStoreBuffered
    defer:NO
    screen:screen];
[window setLevel: CGShieldingWindowLevel()];

You might want to google CGDisplayCapture() as well.

like image 53
sbooth Avatar answered Sep 20 '22 12:09

sbooth


You can call the enterFullScreenMode:withOptions: method of NSView to acheieve the desired behaviour.

See Apple's documentation.

Read here and here for the options that can be supplied to this method.

You can use [NSScreen screens] to get the list of available screens. See here for details.

like image 38
e.James Avatar answered Sep 19 '22 12:09

e.James