//usr/bin/env SRC=$0 DST=$TMPDIR/${app=`basename ${0%.mm}`}.app/Contents/MacOS/$app ARGS="$*" /bin/bash -c ' \
    mkdir -p $(dirname $DST) && \
    plutil -create xml1 ${plist=`dirname $DST`/../Info.plist} && \
        plutil -insert CFBundleIdentifier -string com.yourcompany.$app $plist && \
    clang++ $SRC -o $DST -fmodules -fcxx-modules && \
    echo $DST && exec $DST $ARGS '; exit

// 1. Launch, click window to launch modal panel, click again to launch nested modal panel
// 2. Swipe to activate mission control, click app window
// 3. Observe nested modal panel behind first modal panel, not possible to bring forward
// 4. Swipe to activate mission control, click app window
// 5. Observe nested modal on top
// 6. Goto 2

#include <AppKit/AppKit.h>

@interface View : NSView
@end

@implementation View
- (void)mouseUp:(NSEvent *)event
{
    NSWindow *panel = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 300, 300)
            styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable
            backing:NSBackingStoreBuffered defer:YES];
    panel.contentView = [View new];
    [NSApp runModalForWindow:panel];
}
@end

int main()
{
    @autoreleasepool {
        [NSApplication sharedApplication];
        [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

        id appMenu = [[NSMenu new] autorelease];
        [appMenu addItem:[[[NSMenuItem alloc] initWithTitle:@"Quit"
            action:@selector(terminate:) keyEquivalent:@"q"] autorelease]];
        id appMenuItem = [[NSMenuItem new] autorelease];
        [appMenuItem setSubmenu:appMenu];
        NSApp.mainMenu = [[NSMenu new] autorelease];
        [NSApp.mainMenu addItem:appMenuItem];

        NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 600, 300)
            styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
            backing:NSBackingStoreBuffered defer:YES];
        window.contentView = [View new];
        [window center];
        [window makeKeyAndOrderFront:nil];

        [NSApp activateIgnoringOtherApps:YES];
        [NSApp run];
        return 0;
    }
}
