Certain keys not passed to app


#1

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 defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
    if (peer != nullptr
         && peer->hasNativeTitleBar()
         && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
    {
        [peer->window performSelector: @selector (toggleFullScreen:)
                           withObject: [NSNumber numberWithBool: (BOOL) enableOrDisable]];
    }
    else
   #endif
    {
        if (enableOrDisable)
        {
            if (peer->hasNativeTitleBar())
                [peer->window setStyleMask: NSBorderlessWindowMask];

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

TO TEST:

Add the set kiosk mode in ApplicationStartup


       #if JUCE_IOS || JUCE_ANDROID
        theMainWindow.setVisible (true);
        theMainWindow.setFullScreen (true);
       #else
        theMainWindow.centreWithSize (700, 600);
        theMainWindow.setVisible (true);
	Desktop::getInstance().setKioskModeComponent (&theMainWindow,true);

Add native title bar and mac menu to MainDemoWindow constructor

setUsingNativeTitleBar(true);
    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);
       MenuBarModel::setMacMainMenu(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);
            break;

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


#2

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


#3

Awesome, thanks!