I am trying to make my NSWindow always show up on top in my application but I don't want it to float over other apps that have become active. I have tired the following code but this makes the window float over other applications:
NSRect frame = NSMakeRect(100, 100, 800, 800);
myWindow = [[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[myWindow setLevel:NSFloatingWindowLevel ];
[myWindow setBackgroundColor:[NSColor blueColor]];
[myWindow makeKeyAndOrderFront:NSApp];
I have also tried all of the constants listed in the NSWindow documentation and did not find one that would make the NSWindow float over other windows in my but not other windows of other active apps. Is this not possible?
There's no built-in support for that. You might consider setting your window to hide on deactivate.
Alternatively, you can have the window controller observe the NSApplicationWillResignActiveNotification
and NSApplicationDidBecomeActiveNotification
notifications and adjust the window level. When your app is about to resign active status, you set the window level back to normal. When it becomes active again, you set it to float. (If the window is controlled by the app delegate, then you can do this in the -applicationWillResignActive:
and -applicationDidBecomeActive:
delegate methods.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With