Showing a modal NSWindow, without activating the other application windows

后端 未结 4 1035
误落风尘
误落风尘 2020-12-15 12:53

I have an NSStatusItem that is properly displaying in the MenuBar. One of the items (when clicked) displays a modal NSWindow from my application, which is meant

相关标签:
4条回答
  • 2020-12-15 13:14

    A solution by Ken Thomases on the cocoa-dev list a couple years ago looks applicable here too:

    [[NSApplication sharedApplication] hide:self];
    [[NSApplication sharedApplication] performSelector:@selector(unhideWithoutActivation) 
                                            withObject:nil 
                                            afterDelay:0.05];
    

    Which in theory tells the application to hide itself and unhide at the bottom of the window stack.

    You could also intercept the mouse click event and use [NSApp preventWindowOrdering]

    0 讨论(0)
  • 2020-12-15 13:26

    Instead of creating an NSWindow, create an NSPanel with the style NSNonactivatingPanelMask. You can then do the usual makeKeyAndOrderFront: and orderOut: to show/hide panel as needed.

    0 讨论(0)
  • 2020-12-15 13:32

    You can try something like:

    ...
    if ([NSApp isHidden])
        [myWindow makeKeyAndOrderFront:self];
    else
        [NSApp runModalForWindow:myWindow];
    ... 
    

    and when finish:

    ...
    if ([NSApp isHidden])
        [myWindow orderOut:self];
    else
        [NSApp stopModal];
    ... 
    
    0 讨论(0)
  • 2020-12-15 13:34

    NSApp's beginModalSessionForWindow, runModalSession, endModalSession are methods you need.

    Have a look here for example how to use it: Creating a fully customized NSAlert

    0 讨论(0)
提交回复
热议问题