Changing the mouse cursor on OS X

Hi,

I recently got my JUCE application running on OS X. I have some components which should change the mouse cursor, but on OS X the cursor doesn’t change - it remains as the standard pointer. This problem does not occur in Windows 7.

I saw that there was a commit to git on 2nd June 2011 that contained a “Mouse cursor update fix”, but sadly this didn’t solve the problem (I’m using juce_amalgamated, which was updated in the same commit). Does anyone know what might be causing the cursor problem?

Here’s some info about my system state:

Here’s a minimal repro case (I can supply an XCode project if needed).

#include "juce/juce_amalgamated.h"

class MainComponent  : public Component
{
public:
    MainComponent()
    {
        setSize(600, 300);
        setMouseCursor(MouseCursor::CrosshairCursor);
    }

private:
};

//==============================================================================
class MainWindow  : public DocumentWindow
{
public:
    MainWindow()
        : DocumentWindow (T("JUCE Test"),
                          Colours::lightgrey,
                          DocumentWindow::allButtons,
                          true)
    {
        MainComponent* const contentComponent = new MainComponent();
        setContentOwned(contentComponent, true);
        centreWithSize(getWidth(), getHeight());
        setVisible(true);
    }

    void closeButtonPressed()                { JUCEApplication::quit(); }
};

//==============================================================================
class JUCETestApplication : public JUCEApplication
{
public:
    JUCETestApplication()
        : mainWindow(NULL)
    {}

    void initialise(const String& commandLine) { mainWindow = new MainWindow(); }
    void shutdown()                            { mainWindow = NULL; }

    const String getApplicationName()        { return "JUCE test"; }
    const String getApplicationVersion()    { return "0.1"; }

private:
    ScopedPointer<MainWindow> mainWindow;
};

//==============================================================================
START_JUCE_APPLICATION (JUCETestApplication)

Thanks!

I tried your code snippet, but it does work for me in OSX…

Hmm… I wonder what could possibly cause this? I’ve just updated to OSX 10.6.7 (just in case), but that hasn’t fixed it.

I’ve attached the XCode project for my repro case (minus the JUCE amalgamated files, as that creates a zip which seems to be too big for the forum software, and you’ve got those files anyway). Please could you try that? This is the first time that I’ve built a JUCE program on OSX, so perhaps I’m not setting things up correctly? (BTW, the xcode file was originally generated by CMake, but I’ve stripped out the CMake stuff from the project for simplicity).

Thanks

[Edit - updated repro case]

Did you actually click in your window to focus it? On OSX you won’t get any mouse cursors unless your app is the foreground window.

Yes, I’m definitely clicking the window to focus it. Did the XCode repro case work for you?

I’ve noticed that if I launch my app from the command line and use command-tab to cycle through the open apps, my app doesn’t appear in the list of apps. Perhaps this is related?

(I noticed that the project build directory was set to something strange in my original XCode project. Apologies for that. It was due to the original file being generated by CMake and hence containing absolute paths. I’ve corrected this and attached a new XCode project to my first post).

Thanks.

I didn’t try your test case - too busy right now - but cursors definitely work in OSX, I use them every day! (And you wouldn’t be the only person complaining if they didn’t!)

What about the demo app? Surely cursors work ok in there for you? (e.g. every TextEditor will have an i-beam cursor)

I’d reached a similar conclusion :wink: (i.e. I must be doing something wrong, otherwise everyone else would be complaining!).

I’ve found the cause of the problem: my project didn’t contain an Info.plist file. Once I’d added this, the cursor behaved exactly as expected. Also, my application now appears in the dock and in the command-tab application list. It looks like without this config file, the application cannot properly receive focus, so you were on the right track with your focus-related suggestion. Thanks for your help with that.

For any other readers who are using CMake to generate their project files, you need to set the MACOSX_BUNDLE property on your target in order to have the Info.plist file created. See the CMake manual here http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:MACOSX_BUNDLE

Thanks again.