Skip navigation.
 
mlRe: Fullscreen on secondary displays
FROM : Ricky Sharp
DATE : Tue May 13 22:23:12 2008

On May 13, 2008, at 12:11 PM, Dennis Munsie wrote:

> I have an app right now that I've added a fullscreen mode to.  RIght
> now it works for fullscreen when I go to fullscreen on the main
> display.  If I attempt to do this on the secondary display, I get a
> blank screen.
>
> I think one problem is probably the way I am identifying which screen
> to use -- I use [NSWindow screen] to find where my current window is
> and use that to capture the screen and place a new fullscreen window
> over it.  One potential problem I see is when the window spans across
> two displays -- how do I reasonably choose which screen to display it
> on?  What screen does [NSWindow screen] return?
>
> So to recap -- this code currently works correctly in the case when
> the _mainWindow is on the primary display.  The code does not work
> correctly when it is on a secondary display.  And I haven't tested the
> case where the code spans displays -- I am assuming that it just flat
> out doesn't work :)
>
> here is the code from my enterFullscreen method -- mostly pulled from
> sample code off developer.apple.com:
>
> -(void)enterFullscreen
> {
>     NSScreen *windowScreen = [_mainWindow screen];
>     NSDictionary *screenInfo = [windowScreen deviceDescription];
>     NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
>     
>     // capture the screen
>     CGDirectDisplayID displayID = (CGDirectDisplayID)[screenID 
> longValue];
>     CGDisplayErr err = CGDisplayCapture(displayID);
>     if(err == CGDisplayNoErr) {
>         if(!_fullscreenWindow) {
>            // Create the full-screen window.
>            NSRect winRect = [windowScreen frame];
>            _fullscreenWindow = [[NSWindow alloc]
> initWithContentRect:winRect styleMask:NSBorderlessWindowMask
> backing:NSBackingStoreBuffered defer:NO screen:windowScreen];
>             
>            // Establish the window attributes.
>            [_fullscreenWindow setReleasedWhenClosed:NO];
>            [_fullscreenWindow 
> setDisplaysWhenScreenProfileChanges:YES];
>            [_fullscreenWindow setDelegate:self];            
>        }
>
>         // move our view over to the fullscreen window
>         [_mainWindow setContentView:nil];
>         [_fullscreenWindow setContentView:_mainView];
>         [_mainWindow setNeedsDisplay:YES];
>         
>        // The window has to be above the level of the shield window.
>        int32_t    shieldLevel = CGShieldingWindowLevel();
>        [_fullscreenWindow setLevel:shieldLevel];
>         
>        // Show the window.
>        [_fullscreenWindow makeKeyAndOrderFront:self];
>         
>         _fullscreenFlag = YES;
>     }
> }



Ack.  Do not expect to use AppKit with a captured display.  I really 
wish all those archived code examples out there would just vanish; 
just leads to more folks doing this.

Anyhow, if you really must capture the display using the CG APIs, 
please note that there's different mechanisms for getting data onto 
the screen.  Search cocoa-dev and quartz-dev for the details on why 
you cannot use AppKit with captured displays.

If you must use AppKit, you can always use a call to SetSystemUIMode 
(to hide menu bar and dock).  Then, enumerate all screens and put up 
"blanking" windows on each one.  Then, put up your "content" window 
over a particular blanking one.  See the child window APIs for how you 
can ensure that the content window is never brought forward over the 
blanking one.

This latter approach is what I've done for the past few years and has 
worked great.

___________________________________________________________
Ricky A. Sharp        mailto:<email_removed>
Instant Interactive(tm)  http://www.instantinteractive.com

Related mailsAuthorDate
mlFullscreen on secondary displays Dennis Munsie May 13, 19:11
mlRe: Fullscreen on secondary displays Ricky Sharp May 13, 22:23
mlRe: Fullscreen on secondary displays Dennis Munsie May 13, 22:40
mlRe: Fullscreen on secondary displays John Stiles May 13, 23:00
mlRe: Fullscreen on secondary displays dan sinclair May 13, 23:02
mlRe: Fullscreen on secondary displays Dennis Munsie May 13, 23:47
mlRe: Fullscreen on secondary displays Jean-Daniel Dupas May 14, 00:30
mlRe: Fullscreen on secondary displays Dennis Munsie May 14, 05:30
mlRe: Fullscreen on secondary displays Jean-Daniel Dupas May 14, 09:56
mlRe: Fullscreen on secondary displays Sean McBride May 14, 18:54
mlRe: Fullscreen on secondary displays Mike Fischer May 16, 18:18