Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow makeKeyAndOrderFront makes window appear, but not Key or Front

Tags:

makeKeyAndOrderFront is not making my NSWindow key or front.

My app does not have a main window or menubar, which may be part of the problem?

IBOutlet NSWindow *loginWindow;
//(connected in Interface Builder to the NSWindow)

The NSWindow has "visible at launch" and "release when closed" both unchecked.

Then:

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [loginWindow makeKeyAndOrderFront:self];
}

This does open the window. (commenting it out results in no window being opened).

However:

  • It appears behind the Xcode window (not front).

  • It appears to recieve mouse focus, but will not take keypresses in the textfields the window contains. The keypresses are sent to Xcode.

  • It appears in the Expose grid when Expose is activated. But I cannot click the window to select it in Expose... it won't come to the front.

Why isn't my Window working?

like image 510
ck_ Avatar asked Sep 18 '11 07:09

ck_


2 Answers

Try calling this method [NSApp activateIgnoringOtherApps:YES];. This should make it the active application.

like image 91
ms83 Avatar answered Oct 02 '22 20:10

ms83


Stab in the dark: You have LSBackgroundOnly set in your Info.plist. That's what makes this not work: A background-only application cannot come to the foreground, which is why your window does not come to the foreground.

If you want your app to not show up in the Dock, set LSUIElement instead. This suppresses your app's Dock tile and keeps it from showing its own main menu in the menu bar, but preserves its ability to bring a window frontmost and make it key.

like image 24
Peter Hosey Avatar answered Oct 02 '22 19:10

Peter Hosey