Skip to content

Menu bar icon does not recover after unplugging the external display that hosts it #997

@Llldmiao

Description

@Llldmiao

Summary

CodexBar can leave its menu bar icon unavailable after the external display that currently hosts the status item is unplugged.

This looks distinct from the existing startup recovery fixes. The app process keeps running, but the NSStatusItem appears to remain tied to the removed display's menu bar instead of being rematerialized on the remaining built-in display.

Steps to Reproduce

  1. Connect an external display to a Mac.
  2. Launch CodexBar.
  3. Have the CodexBar menu bar item visible on the external display's menu bar.
  4. Unplug the external display while CodexBar is still running.

Actual Behavior

The CodexBar process keeps running, but the menu bar icon does not appear on the built-in display. In my local reproduction, relaunching CodexBar also did not immediately make the icon visible on the built-in menu bar.

Expected Behavior

When macOS screen parameters change and the display hosting the menu bar item disappears, CodexBar should recover the status item on one of the currently active screens, ideally after a short debounce to let AppKit settle.

Related Work

Those fixes are valuable, but I do not see runtime display topology changes being handled today. StatusItemController schedules a startup visibility check, but it does not currently observe NSApplication.didChangeScreenParametersNotification.

Root Cause Hypothesis

NSStatusItem can report as present while its backing button/window is associated with a screen that is no longer part of NSScreen.screens. Because CodexBar only checks visibility at startup, a hot-unplug event can leave the app running with an inaccessible status item.

Proposed Fix

Observe NSApplication.didChangeScreenParametersNotification, debounce the recovery check, and recreate status items when:

  • the screen count decreases while any status item is expected to be visible, or
  • a visible status item snapshot is blocked/missing/detached from the current NSScreen.screens.

I have a local patch for this and will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions