Mouse issue with setFullScreen() at initialization


I encounter an issue with the mouse position when using setFullScreen() on the main window at initialization on macOS. It seems that if another app grabs the focus (with a mouse click) between the JUCE app initialization and the window creation, the mouse events are not well passed to JUCE app. So if the user launches the JUCE app, and clicks on another app while the JUCE app is initializing, when the JUCE window appears in fullscreen, then the mouse events are not valid and consistent with the graphical component (there is an offset).

It can be a bit tricky to test because the initialization should be long enough to let the user click on another app so an easy way to test it is simply to add a breakpoint in the JUCEApplication::initialise() method before the window creation so the IDE (Xcode) grabs the focus before the window initialization.

I made a very basic project to demonstrate the bug in this Github repository JuceTest - branch test/macos-fullscreen-bug. The main component contains a text button and the text changes from red to green when the mouse is over. Here is a quick video that shows the bug, the first time I run the app everything works fine, the second, the color of the text doesn’t change when I move the mouse over.

I tested on macOS 12.3 (21E230) - MacBook Pro (16-inch, 2021) / M1 with Xcode Version 13.3 (13E113).

Edit: With JUCE develop branch (14ab027)

The bug also occurs on macOS 12.2.1 (21D62) MacBook Pro (15-inch, 2018) with Xcode Version 13.2.1 (13C100).

It seems that using bool addToDesktop = false in the window constructor and addToDesktop() after the window allocation fixes the issue, it’s ugly but it might help to find a proper solution…

void initialise(const juce::String& commandLine) override
        mainWindow.reset(new MainWindow(getApplicationName()));
        if(mainWindow != nullptr)
            // Fix the mouse issue on macOS

As there is no answer, am I doing something wrong, or is it a bug in Juce?

This is on our backlog, but we’re quite busy with JUCE 7 preparation at the moment so I’m not sure when we’ll actually be able to investigate properly.

1 Like

Ok, thanks! My ugly fix seems to work for the moment so there is no hurry, just good to know that I didn’t do an obvious mistake :slight_smile:

A fix for this issue is now out on develop