PDA

View Full Version : Cocoa window focus


Dan Potter
2005.04.30, 02:26 AM
Ok, this is probably going to sound like the dumbest question anyone's asked on here yet. :D But here goes...

I've got a single OpenGL view window that's created via the my project's NIB. I just size the contents to 640x480, put an NSView inside it, and attach to that at start time to make the GL context. It all works just great, except that the window is never focused when the app starts.

I've tried messing around with IB properties, I've tried all sorts of different methods I found in the Xcode docs for manually raising and focusing windows... nothing seems to work. I get key input just fine, and once the window is up you can click on it to focus it. It just won't focus by default, which looks goofy.

To add insult to injury, I wrote an OpenVPN Cocoa front end that works just fine. So it's not like I'm tainted with the window non-focus in general :)

Is there something I'm missing here? :wacko:

The only thing I can think of that I'm doing weirdly is I've got my own event loop... but it passes all events it doesn't understand onwards using [NSApp sendEvent:].

codemattic
2005.04.30, 08:35 AM
well after you awake from NIB you can:
[myWindow makeKeyAndOrderFront:nil];
[myWindow makeFirstResponder:myView];

obviously myWindow and myView are outlets you need to connect to the window and view. Does that work?

Dan Potter
2005.04.30, 11:57 AM
I'm about 90% sure I tried both of those before, but now it seems to work. :blink: Maybe I was doing something silly like trying to use them on the view...

Anyway, thanks!