Preventing OS focus

I have a main app window that is “setAlwaysOnTop(true)” so it will always be visible even with other applications are opened/selected in the OS (alt+tab in OS X for example). It is also running in kiosk mode.

However, I’d like to be able to use keyboard shortcuts in other apps that are open when my JUCE app is running. I can do this by alt-tabbing to the other app, or simply opening the other application after my JUCE app. But, even with the series of other functions below, the JUCE app is… (not sure of the proper term) brought to the front/gains keyboard focus in the OS when clicking anywhere in the JUCE window.

setInterceptsMouseClicks(false, false);

So, basically, I have a JUCE app with sliders that is always visibly in front controlling another application, but I’d like to have the OS think the other app is always in front so I can use its keyboard shortcuts. In other terms, I don’t want the OS X menu bar to switch to my JUCE app when clicking on its window.

Is it possible to do what I’m after in JUCE? Will this require some OS level hacking?

In fact, you can probably do what you want by using Process::setDockIconVisible(). When you turn off the dock icon, OSX seems to prevent the app from taking focus, which is actually a problem for some things, but in your case it’s probably exactly what you need!

1 Like

setDockIconVisible is not working for me because [NSApp setActivationPolicy: isVisible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyProhibited] is returning false. Any idea why? I’m calling setDockIconVisible from the initialise method in my main.cpp.

However, this did lead me to a solution- adding a LSBackgroundOnly(“Application is background only”) field to my info.plist and setting it to YES worked… which is what NSApplicationActivationPolicyProhibited should do…strange, but at least it’s working, so thank you!

Sorry, no idea why that would fail… Are you on an old version of OSX, perhaps?

Running 10.6.8, so it should work.

Also, I’m curious- is there a way to achieve the same effect on Windows? (In case I want to make this app cross-platform in the future)


Ah, I think that function is only available in 10.7

Not sure about Windows TBH, that might need some special hackery.

When you turn off the dock icon, OSX seems to prevent the app from taking focus, which is actually a problem for some things

Don’t know what the problem you mention but I ran into a problem where my app with a menu bar icon, click the icon will appear a pop up menu. I don’t want the dock icon so I call Process::setDockIconVisable(false), after that, when menu pops up, it disappears when mouse over. Any suggestion?

  • JUCE v4.2.1
  • OS: Mac OSX 10.11.5 64-bit