1

I'm developing an app on OSX 10.7 and I'm trying and the goal is to open some images on a second screen while the app has to run normally on the first.

So the code is the following:

NSScreen *screen = [[NSScreen screens] objectAtIndex:1];

fullScreenWindow = [[NSWindow alloc] initWithContentRect:[screenFrame]
                                               styleMask:NSBorderlessWindowMask
                                                 backing:NSBackingStoreBuffered
                                                   defer:NO
                                                  screen:screen];
[fullScreenWindow setLevel: NSMainMenuWIndowLevel + 1];
[fullScreenWindow setOpaque: YES];
[fullScreenWindow setBackgroundColor:[NSColor yellowColor]];

fullScreenView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, fullScreenWindow.frame.size.width, fullScreenWindow.frame.size.height)];
// Adding a test button
NSButton *testButton = [[NSButton alloc] initWithFrame(50.0f, 50.0f, 100.0f, 50.0f)];
[testButton setTarget:self];
[testButton setAction:@selector(closeExternalWindow)];
[fullScreenView addSubview:testButton];

// Present the fullscreen window
[fullScreenWindow.contentView addSubview:fullScreenView];
[fullScreenWindow makeKeyAndOrderFront:self];

In this way, on the first screen the app is correctly shown, but on the second screen I just see a fullscreen black window.

What's the issue?

Thanks!

  • Just a guess but my feeling always was it's an all-or-nothing approach, at least there's not a single app I've ever seen doing that. So even if it may be possible (which I doubt) it will give users a very .. weird experience when using your app. – Jay Mar 16 '13 at 08:30
  • Hi Jay, thanks for your answer but why do you consider it a bad design? Think to keynote, for example, the idea is to use a second screen ( a projector) to show some images or a presentation, and use the main screen to read data or to run some other tasks. – Claudio Bellucci Mar 16 '13 at 15:25
  • Hmm, good point :-) Actually, iMovie does the same thinking about it. So not totally unheard of, just slightly unusual. – Jay Mar 17 '13 at 14:58
  • Yes, but my problem is that the fullscreen window (on the second screen) remains completely black :) – Claudio Bellucci Mar 17 '13 at 19:10
  • You sure that's your window and not just the screen default background? – Jay Mar 18 '13 at 09:15

2 Answers2

1

Reading Apple's docs for initWithContentRect:styleMask:backing:defer:screen: it states that the screen parameter..

Specifies where the window’s content rectangle is drawn if the window is to be drawn in a screen other than the main screen. The content rectangle is drawn relative to the bottom-left corner of screen.

So when using [screen frame] you're actually moving it off the second screen as the positioning is relative to that screen already.

In order to make it appear where expected you can change the code e.g. to

[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, [screen frame].size.width, [screen frame].size.height)
                            styleMask:NSBorderlessWindowMask
                              backing:NSBackingStoreBuffered
                                defer:NO
                               screen:screen];
Jay
  • 6,572
  • 3
  • 37
  • 65
0

After some days I have had the possibility to work again on this code and now it works:

NSScreen *screen = [[NSScreen screens] objectAtIndex:1];
NSRect mainDisplayRect = [screen frame];
fullScreenWindow = [[NSWindow alloc] initWithContentRect: mainDisplayRect styleMask:NSBorderlessWindowMask
                                                 backing:NSBackingStoreBuffered defer:YES];
[fullScreenWindow setLevel:NSMainMenuWindowLevel+1];
[fullScreenWindow setOpaque:YES];
[fullScreenWindow setHidesOnDeactivate:YES];
[fullScreenWindow setBackgroundColor:[NSColor redColor]];

NSRect viewRect = NSMakeRect(0.0, 0.0, mainDisplayRect.size.width, mainDisplayRect.size.height);
fullScreenView = [[PresenterView alloc] initWithFrame:viewRect];
[fullScreenWindow setContentView: fullScreenView];
[fullScreenWindow makeKeyAndOrderFront:self];

Jay thank you for the support ;)