Skip to content

fix: properly hide menu bar items on ultra-wide monitors - #347

Closed
lucataco wants to merge 1 commit into
consolelabs:masterfrom
lucataco:fix/ultrawide-monitor-support
Closed

lucataco wants to merge 1 commit into
consolelabs:masterfrom
lucataco:fix/ultrawide-monitor-support

Conversation

@lucataco

Copy link
Copy Markdown

Summary

  • Fix menu bar items remaining visible on ultra-wide monitors (5120px+) when collapsed
  • On ultra-wide screens, macOS enforces a hard 10,000pt max for NSStatusItem.length and prevents status items from crossing the app-menu boundary, causing hidden items to pile up visibly in the middle of the menu bar

Problem

Hidden Bar works by expanding btnSeparate to a large width to push hidden status items off the left edge of the screen. On standard monitors this works fine, but on ultra-wide monitors (e.g. 5120px wide):

  1. macOS caps NSStatusItem.length at 10,000pt
  2. macOS divides the menu bar into app-menu (left) and status-item (right) zones — status items cannot cross into the app-menu zone
  3. Hidden items pile up at the app-menu boundary and remain visible

Solution

Added a MenuBarOverlayWindow — a solid-black NSPanel positioned just above the status bar level — that covers any hidden items macOS couldn't push off-screen.

Changes

New file: MenuBarOverlayWindow.swift

  • Borderless, non-activating NSPanel with solid black background
  • Window level set just above statusWindow to cover stuck items
  • Blocks clicks on covered items (ignoresMouseEvents = false)
  • Joins all spaces and stays stationary

Modified: StatusBarController.swift

  • Dynamically calculate collapse length using the screen where status items actually live (via btnExpandCollapse.button?.window?.screen), with fallbacks to NSScreen.main and NSScreen.screens.first
  • Cap collapse length at macOS's hard 10,000pt maximum
  • Show overlay 0.5s after collapsing (gives macOS time to finish repositioning items)
  • Hide overlay immediately on expand
  • Use NSStatusBar.system.thickness as fallback for menu bar height on secondary screens (where visibleFrame == frame)
  • Leave 600px margin on the left so Apple menu and app menus remain visible and clickable
  • Change isCollapsed to use threshold comparison (> btnHiddenLength) instead of exact equality, so screen-change recalculations don't break state detection
  • Re-apply collapse length and reposition overlay on screen parameter changes

Modified: project.pbxproj

  • Added MenuBarOverlayWindow.swift to build sources

Testing

Tested on a 5120x1440 ultra-wide monitor as a secondary display alongside a MacBook screen. Hidden items are properly concealed when collapsed, and the Apple menu + app menus remain fully visible and functional.

On ultra-wide monitors (5120px+), macOS enforces a hard 10,000pt max for
NSStatusItem.length and prevents status items from crossing the app-menu
boundary. This causes hidden items to pile up visibly in the middle of
the menu bar instead of being pushed off-screen.

- Add MenuBarOverlayWindow (solid-black NSPanel) to cover hidden items
  that macOS cannot push off-screen on ultra-wide displays
- Update collapse length calculation to use the screen where status items
  live (via button window) with fallback chain, capped at 10,000pt
- Show overlay after collapsing with 0.5s delay for macOS to finish
  repositioning; hide overlay immediately on expand
- Use NSStatusBar.system.thickness as fallback menu bar height for
  secondary screens where visibleFrame == frame
- Leave 600px left margin so Apple menu and app menus stay visible
- Change isCollapsed to threshold comparison instead of exact equality
// edge of the expand/collapse button's window. We leave a 600pt
// margin on the left so the Apple logo and application menus (e.g.
// Chrome File Edit View …) remain visible and clickable.
let appMenuMargin: CGFloat = 600

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if hardcoded 600px is enough for all cases. Is there a possibility to get a real frame width or using some other dynamic approach?

92C97B8C220058740007559C /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = "<group>"; };
92C97B8E220147FE0007559C /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
92C97B9022018C1F0007559C /* StatusBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
AA1234560001000000000002 /* MenuBarOverlayWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarOverlayWindow.swift; sourceTree = "<group>"; };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this AA1234560001000000000002 an actual generated UUID?

level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.statusWindow)) + 1)
collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle]
isOpaque = true
backgroundColor = .black

@laveez laveez Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this color ever visible or just a fallback? Could we use something like NSVisualEffectView with .menuBar material?

@lucataco lucataco closed this by deleting the head repository Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants