SystemTrayIconComponent support using NSStatusBar

Thanks - I’ll see what I can do with that!

Ok, thanks guys - I can check in an updated version, but as someone mentioned, handling mouse-drag behaviour isn’t correct yet.

Not sure about adding a “setHighlight” method though… Is there really a reason why that’s needed?

The highlighting should be shown as long as a component is shown in response to an icon click. If only some action is invoked it needs to be disabled right away. It depends on what is done / shown in mouseUp.

With the setHighlighting method we can give access to the SystemTrayIconComponent to the component that is shown in mouseUp:

[code]void SWTrayIconComponent::mouseUp (const MouseEvent& event)
{
SystemTrayIconComponent trayComponent = dynamic_cast<SystemTrayIconComponent>(event.originalComponent);

if(m_left || m_popup)
{
	MiniPlayerPanel miniPlayer(m_coreView, trayComponent);
	miniPlayer.setSize(TrackActionPanel::PanelWidth, 52);
	juce::Rectangle<int> area = event.eventComponent->getScreenBounds();
	CallOutBox calloutBox(miniPlayer, area, nullptr);
	calloutBox.toFront(true);
	calloutBox.enterModalState (true);
	ModalComponentManager::getInstance()->runEventLoopForCurrentComponent();
}

}[/code]
And once the shown component is closed and destroyed the highlighting can explicitly turned off:

MiniPlayerPanel::~MiniPlayerPanel() { m_owner->setHighlighting(false); }
If there is a different way that does not need the setHighlighting method it would be better of course.

The Pimpl destructor is missing a call to remove the status bar item. At the moment the icon will not be removed from the status bar if the SystemTrayIconComponent is deleted. ~Pimpl() should be changed to the following code to correctly remove the status bar item:

~Pimpl() { [[NSStatusBar systemStatusBar] removeStatusItem:statusItem]; [statusItem release]; [view release]; [statusIcon release]; }

Thanks!

Just checking in on this. Has anyone gotten this to work reliably without requiring the application’s main window to be on the foreground? I have a new app that could really benefit for this.

It seems the open issues remain:

The tip does not (yet?) contain the setHighlighting method which is needed to manually handle the highlighting of the NSStatusBarItem depending on what you are doing in response to a click on the NSStatusBarItem.

Jules also mentioned that handling mouse-drag behaviour isn’t correct yet.

The hardest part will probably be what’s discussed here: http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=11365. Here is the summary:

[quote]It seems the solution is to make the window a NSPanel which don’t show up in the Window menu, disappear when the app becomes inactive, and shows up in the responder chain before the main window does. For the look of an utility window the NSUtilityWindowMask is needed.

Also the NSNonActivatingPanelMask is needed in the styleMask. That makes it a non activating panel that can become key without activating the application that owns it.

While browsing through the JUCE code I found the NSViewComponent. This is used to show a NSView as a component. What I would need is pretty much the oposite. Show an component within a NSPanel that has the appropriate style flags as described in my previous post.
[/quote]

And Jules said in response

I did not give it another try yet though.

Any progress with Gbevins'   "Really strange ... when I move the mouse around without moving over the popup menu, it stays active. It's when I actually move over the popup menu that it automatically disappears when the application isn't in the foreground." 

 

I have the same problem.