# TaskBar icon popup menu disappears if main app window is not in focus

**URL:** <https://forum.juce.com/t/taskbar-icon-popup-menu-disappears-if-main-app-window-is-not-in-focus/65472>\
**Category:** MacOSX and iOS\
**Created:** [March 12, 2025, 9:35pm UTC](https://forum.juce.com/t/taskbar-icon-popup-menu-disappears-if-main-app-window-is-not-in-focus/65472 "2025-03-12T21:35:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaughtiusMaximus](https://avatars.discourse-cdn.com/v4/letter/n/74df32/32.png) [@NaughtiusMaximus](https://forum.juce.com/u/NaughtiusMaximus)\
**Post date:** [March 12, 2025, 9:35pm UTC](https://forum.juce.com/t/taskbar-icon-popup-menu-disappears-if-main-app-window-is-not-in-focus/65472/1 "2025-03-12T21:35:00Z")

</div>

Hi,

I have an issue with displaying a popup menu for the taskbar icon (on macOS). One of the points of having a taskbar menu is that it allows me to hide the main application window, and I can still control it via this menu. But when the main app window is out of focus the menu closes immediately after opening. I have checked the hide() function, and it seems that the MouseSourceState::checkButtonState function is the culprit, it dismisses the menu if the app window is not in focus.  
I thought that this behaviour (hiding main app window while having a taskbar menu) is common on macOS, there are loads of applications working this way, so I’m not sure why this is not supported. Or am I doing something wrong?

Here is the function that causes me the trouble:

```auto
void checkButtonState (Point<int> localMousePos, const uint32 timeNow,
                           const bool wasDown, const bool overScrollArea, const bool isOverAny)
    {
        isDown = window.mouseHasBeenOver()
                    && (ModifierKeys::currentModifiers.isAnyMouseButtonDown()
                         || ComponentPeer::getCurrentModifiersRealtime().isAnyMouseButtonDown());

        const auto reallyContained = window.reallyContains (localMousePos, true);

        if (! window.doesAnyJuceCompHaveFocus() && ! reallyContained)
        {
            if (timeNow > window.lastFocusedTime + 10)
            {
                PopupMenuSettings::menuWasHiddenBecauseOfAppChange = true;
                window.dismissMenu (nullptr);
                // Note: This object may have been deleted by the previous call.
            }
        }
        else if (wasDown && timeNow > window.windowCreationTime + 250 && ! isDown && ! overScrollArea)
        {
            if (reallyContained && window.allowMouseUpToTriggerItem())
                window.triggerCurrentlyHighlightedItem();
            else if ((window.mouseHasBeenOver() || ! window.allowMouseUpToTriggerItem()) && ! isOverAny)
                window.dismissMenu (nullptr);

            // Note: This object may have been deleted by the previous call.
        }
        else
        {
            window.lastFocusedTime = timeNow;
        }
    }

```
