Bug with text input on macOS


#1

The code below demonstrates the problem. If you compile this application and simply run the binary directly, all the text output appears in the console. If you run it from inside a .app Bundle, the text appears in the TextEdit.

#define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED 1
#include "JuceHeader.h"
//==============================================================================
class testcaseApplication  : public JUCEApplication
{
public:
    //==============================================================================
    testcaseApplication() {}
    const String getApplicationName() override       { return ProjectInfo::projectName; }
    const String getApplicationVersion() override    { return ProjectInfo::versionString; }
    bool moreThanOneInstanceAllowed() override       { return true; }
    
    DocumentWindow *doc;
    //==============================================================================
    void initialise (const String& commandLine) override
    {
        // Add your application's initialisation code here..
        doc = new DocumentWindow("TestApp", Colour(0xFFFFFFFF), 7);
        doc->setUsingNativeTitleBar (true); 
        doc->setResizable (true, false); 
        doc->setBounds(0,0,400,400);
		TextEditor *text = new TextEditor();
		text->setColour(TextEditor::backgroundColourId, Colour(0xFFFFFFFF));
		text->setColour(TextEditor::textColourId, Colour(0xFF000000));
		doc->setContentOwned(text, true);
        doc->setVisible(true);
        doc->addToDesktop(ComponentPeer::windowHasTitleBar);
    }
    void shutdown() override
    {
        // Add your application's shutdown code here..
    }
    //==============================================================================
    void systemRequestedQuit() override
    {
        // This is called when the app is being asked to quit: you can ignore this
        // request and let the app carry on running, or call quit() to allow the app to close.
        quit();
    }
    void anotherInstanceStarted (const String& commandLine) override
    {
        // When another instance of the app is launched while this one is running,
        // this method is invoked, and the commandLine parameter tells you what
        // the other instance's command-line arguments were.
    }
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (testcaseApplication)

#2

Apparently none of y’all care, but the solution is to convert the app to a “foreground” one:

ProcessSerialNumber psn;
GetCurrentProcess( &psn );
TransformProcessType(&psn, kProcessTransformToForegroundApplication);

You’re welcome.


#3

What text do you refer to?

In your initialization code, you’re not assigning any text to your TextEditor, and the other methods are basically empty.


#4

Typing text into the TextEditor. That’s it.