How to force a window to stay front, always?

We want to have a login window stay in front and key, until the user signs in. We want it to stay in front even if switching away from it. Now, this does seem possible, since zoom just did it to me while I was getting into a call to discuss this, but I can't figure out how.

In this particular case, I am instantiating an NSViewController subclass, and then creating an NSWindow for it to use. I have tried setting the NSWindow.level to all sorts of values, and they don't seem to work.

help?

Answered by kithrup in 717550022

AH HA! M'ACCUSE!

Don't use modal. Then

        self.passwordWindow.level = NSFloatingWindowLevel;
        self.passwordWindow.hidesOnDeactivate = NO;
        self.passwordWindow.floatingPanel = YES;

did in fact work.

My code is currently:

    if (self.pvc == nil) {
        self.pvc = [storyboard instantiateControllerWithIdentifier:@"passwordViewController"];
    }
    if (self.passwordWindow == nil) {
        self.pvc.errorLabel.stringValue = @"";
        self.passwordWindow = [NSPanel windowWithContentViewController:self.pvc];
    }
    self.pvc.passwordDelegate = (id<PasswordDelegate>)self;
    self.passwordWindow.title = @"Unlock Password";
    self.passwordWindow.level = NSFloatingWindowLevel;
    self.passwordWindow.canHide = NO;
    self.passwordWindow.hidesOnDeactivate = NO;
    self.passwordWindow.floatingPanel = YES;
    [self.passwordWindow orderWindow:NSWindowAbove relativeTo:0];
    [self.passwordWindow makeKeyWindow];
    [self.passwordWindow orderFrontRegardless];
    self.passwordWindow.collectionBehavior = (
                                              NSWindowCollectionBehaviorCanJoinAllSpaces |
                                              NSWindowCollectionBehaviorTransient |
                                              NSWindowCollectionBehaviorFullScreenAuxiliary
                                              );
    [self.pvc reset];
    NSModalResponse response = [NSApp runModalForWindow:self.passwordWindow];

which is a mishmash of various things I've been trying, and still no luck. 😩

Accepted Answer

AH HA! M'ACCUSE!

Don't use modal. Then

        self.passwordWindow.level = NSFloatingWindowLevel;
        self.passwordWindow.hidesOnDeactivate = NO;
        self.passwordWindow.floatingPanel = YES;

did in fact work.

How to force a window to stay front, always?
 
 
Q