Certain keys not passed to app

Hi Jules, there appears to be a bug with Escape and Delete (possibly other special keys) when starting an app into kiosk mode with native title bar.

I modified the demo app to verify. This is on 10.6.8 with the latest tip. If you click the app with the mouse, or switch apps and go back then the problem goes away, so to test correctly you must load straight into the app and only issue key commands. It seems obvious that this is a focus issue of some sort and I have found that adding peer->becomeKeyWindow() to setKioskComponent in NSViewComponentPeer to be a work around.

Adding becomeKeyWindow

    if (peer != nullptr
         && peer->hasNativeTitleBar()
         && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
        [peer->window performSelector: @selector (toggleFullScreen:)
                           withObject: [NSNumber numberWithBool: (BOOL) enableOrDisable]];
        if (enableOrDisable)
            if (peer->hasNativeTitleBar())
                [peer->window setStyleMask: NSBorderlessWindowMask];

            [NSApp setPresentationOptions: (allowMenusAndBars ? (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)
                                                              : (NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar))];
            kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));


Add the set kiosk mode in ApplicationStartup

        theMainWindow.setVisible (true);
        theMainWindow.setFullScreen (true);
        theMainWindow.centreWithSize (700, 600);
        theMainWindow.setVisible (true);
	Desktop::getInstance().setKioskModeComponent (&theMainWindow,true);

Add native title bar and mac menu to MainDemoWindow constructor

    setResizable (true, false); // resizability is a property of ResizableWindow
    setResizeLimits (400, 300, 8192, 8192);

    ContentComp* contentComp = new ContentComp (*this);

    commandManager.registerAllCommandsForTarget (contentComp);
    commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());

    // this lets the command manager use keypresses that arrive in our window to send
    // out commands
    addKeyListener (commandManager.getKeyMappings());

    // sets the main content component for the window to be this tabbed
    // panel. This will be deleted when the window is deleted.
    setContentOwned (contentComp, false);

    // this tells the DocumentWindow to automatically create and manage a MenuBarComponent
    // which uses our contentComp as its MenuBarModel
    //setMenuBar (contentComp);

Set one of the commands to use the escape key

        case showFontsAndText:
            result.setInfo ("Fonts and Text", "Shows the fonts & text demo", demosCategory, 0);
            result.setTicked (currentDemoId == showFontsAndText);
				result.addDefaultKeypress (KeyPress::escapeKey, ModifierKeys::noModifiers);

You should see that the key commands for switching demos work, but the escape key doesn’t.

Thanks! It seems pretty reasonable to make it become the key window when it gets made full-screen, I’ll add that!

Awesome, thanks!