Tip : Make a window float above application but not system


#1

I needed this myself, so here’s a little helper…

Typically when you use setAlwaysOnTop on mac in a Juce App, it floats it above all windows in the system… Got some complaints about that(user’s wanted the window to disappear when the app doesn’t have focus)…

#if JUCE_MAC
	MacHelpers::makeWindowFloatingPanel(this);
#else

MacHelpers is the namespace…
and then in a .mm file

void MacHelpers::makeWindowFloatingPanel(Component *aComponent)
{
	jassert(aComponent);
	
	ComponentPeer *componentPeer=aComponent->getPeer();
	jassert(componentPeer);
	componentPeer->setAlwaysOnTop(true);
	NSView* const peer = (NSView*) (componentPeer->getNativeHandle());
	jassert(peer);
	NSWindow *window=[peer window];
	jassert(window);
	[window setHidesOnDeactivate:YES];
}

#2

Interesting tip, thanks!


#3

Nice… is there a similar way to do this on Win? (sorry, I know this is the Mac forum…)


#4

Thanks a lot for this! I was having a ton of trouble trying to get this behavior for a window in a Reaper extension plugin. 


#5

We emulate this behaviour with the Tracktion plugin windows by using a timer and checking Process::isForegroundProcess. If the state changes you can hide/show the relevant windows.


#6

It’s a horrible hack, but it’s better than no hack :wink: