Some JUCE apps don't get keyboard focus on start-up


#1

Hi,

Some JUCE applications don’t get keyboard focus on start-up. When double-clicking in explorer, the JUCE window will pop up behind the explorer window, and the taskbar icon will flash, but the window will not be focused. This is reproducible with the JUCE demo, but not with ProJucer.

It can be reproduced with the Hello World example by modifying the constructor of the HelloWorldWindow as follows:

// And show it!
setUsingNativeTitleBar(true);
setResizable(true, true);
setVisible(true);

It will no longer happen if you change the order:

// And show it!
setUsingNativeTitleBar(true);
setVisible(true);
setResizable(true, true);  // ← move down

But this will cause the window to appear twice (which gives a very noticeable stutter in the “fade in” animation, if you have those enabled).

Finally, this order works as expected

// And show it!
setResizable(true, true);  // ← move up
setUsingNativeTitleBar(true);
setVisible(true);

With the Demo app, moving those calls in that order in MainAppWindow::MainAppWindow() solves the problem. As to why, I have no idea. Anyone knows what’s happening here?


Roeland


Application always starts minimized or behind all other windows
JUCE applications start on second plane in windows
#2

setUsingNativeTitleBar will actually cause the Window to be recreated. Best to do that call before all other calls on the Window.


#3

Also, in Xcode and VS2015, running a juce application in the debugger will sometimes not focus the app correctly on launch. Try launching it by hand and see if the problem goes away.


#4

I’m double-clicking the executable in Windows explorer.