SystemTrayIconComponent, dock icon hidden, PopupMenu


#1

I would like to show an icon in the task bar instead of an icon in the dock. But if I hide the dock icon, show a task bar icon using the SystemTrayIconComponent and show a PopupMenu as soon as the mouse moves the PopupMenu is automatically closed.

Reproducable easily with the JUCE demo, just hide the dock in the MainWindow constructor:

Process::setDockIconVisible(false);

Then show the popup menu by command clicking the tray icon of the demo app.

Having both a dock icon and a tray icon at the same time isn't what most apps that have a tray icon do. Most hide their dock icon.

Does anyone have an idea for a workaround for this issue?


#2

On OS X it is possible that a window is shown and interacted with even if the corresponding process is not the foreground process. This affects PopupMenu but also CallOutBox.

For PopupMenu changing doesAnyJuceCompHaveFocus() in the following way fixes the issue:

        // bool anyFocused = Process::isForegroundProcess();
        bool anyFocused = [[NSApp orderedWindows] count] > 0;

Jules, do think PopupMenu can use the changed statement above on the Mac?

I'll take a look at CalloutBox as well. Maybe it also needs a small tweak.


#3

The code above does not work. It no longer detects when the user clicks into a window of a different application and the PopupMenu stays open.


#4

Callouts have the same problem. If the active window belongs to a window that is not the foreground process the calloutbox will close immediately in the timer callback:

    void timerCallback() override
    {
        if (! Process::isForegroundProcess())
            callout.dismiss();
    }

I am not sure at the moment how to correctly track if the user leaves a JUCE app.


#5

Hm. This is not working either:

bool anyFocused = [NSApp keyWindow] != nil;

It seems it is not possible with JUCE to show a menu icon instead of a dock icon and show a PopupMenu when the user clicks the icon.

Any help would be very much appreciated.


#6

I am in similar situation - show a task bar icon using the SystemTrayIconComponent and show a PopupMenu as soon as the mouse moves the PopupMenu is automatically closed.:

 

i can display a popup when my osx extras menu icon is clicked but unless my app window is in the foreground, moving the mouse over the popup items merely makes the popup go away.