Question

My application initially had a window (Def). Then it spawned a new window (New). All the two windows can be switched from the Window sub menu item or by the space control.

But if I tried to set the "New" window to a fake full screen mode on OSX 10.6.8, there would be a problem that if I switched to the "Def" window either by menu or space control. I cannot "fully" switch back to "New" window.

     // setting a fake full screen window on 10.6.8
     NSApplicationPresentationOptions prereqOptions =
        NSApplicationPresentationAutoHideDock |
        NSApplicationPresentationAutoHideMenuBar;
     [[NSApplication sharedApplication]
        setPresentationOptions:prereqOptions];

     [[self window] setToolbar:nil];
     [[self window] setStyleMask:NSBorderlessWindowMask];
     [[self window] setFrame:[[NSScreen mainScreen] frame]
                     display:YES];

The "fully" means I can see the "New" is brought to the top of screen, but the window controller cannot receive the notification "NSWindowDidBecomeKeyNotification". Furthermore, by [NSApp keyWindow], I can see the key window is always the "Def". And I can always see the "Def" is checked in the Window submenu.

Anyone had ever encountered this issue?

Was it helpful?

Solution

Finally after 2 days investigation, the answer goes back to the documentation of NSWindow.

There are two related methods.

  • (BOOL)canBecomeKeyWindow Return Value YES if the window can become the key window, otherwise, NO.

Discussion Attempts to make the window the key window are abandoned if this method returns NO. The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise.

And

canBecomeMainWindow Indicates whether the window can become the application’s main window.

  • (BOOL)canBecomeMainWindow Return Value YES when the window can become the main window; otherwise, NO.

Discussion Attempts to make the window the main window are abandoned if this method returns NO. The NSWindow implementation returns YES if the window is visible, is not an NSPanel object, and has a title bar or a resize mechanism. Otherwise it returns NO.

So the conclusion is that if the window doesn't have a title bar or resize bar, it by default cannot become a main and key window. When setting the window to the fake full screen on 10.6.8 by [NSWindow setStyleMask:NSBorderlessWindowMask], the title bar is gong.

To resolve this issue, one needs to override the above 2 methods with returning YES.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top