Repository navigation
feat: native menu-bar hiding on macOS 27 (direct build) - #403
Merged
phucledien merged 5 commits intoSep 18, 2026
Merged
Conversation
macOS 27 ejects an inflated separator from the menu bar, so length-based hiding stops working there (#360). Add NativeVisibilityEngine: it reads which apps the user placed in each section (Accessibility, relative to the separators) and asks macOS to keep only the allowed apps visible through the menu-bar visibility restriction behind assessment mode. macOS hides the rest and reflows the bar, independent of display width, the notch and the frontmost app's menus. That restriction lives in MenuBarClientCore, a private framework. All use of it sits in HBNativeVisibilityShim (Objective-C, runtime-resolved, exceptions caught) and compiles only with HIDDENBAR_NATIVE_VISIBILITY, which the new Debug-Direct / Release-Direct configurations set. Those configurations sign with Hidden-Direct.entitlements (no App Sandbox): on macOS 27 the sandbox denies the mach-lookup Accessibility needs (com.apple.axserver) even with the permission granted, so the App Store build cannot read the sections and keeps LegacyLengthEngine. Measured on 27.0 before building this: - activation works sandboxed and unsandboxed; invalidate, or process exit, restores the bar - the configuration takes NSArrays; an NSSet raises - system items are numeric ids (2 clock, 5 sound, 6 wifi, 8 control center on the test Mac); unknown ids up to 63 are ignored - while a restriction is active, hidden items report stale positions, so sections are read only from an unrestricted bar Behavior: collapse allows Hidden Bar plus the visible section; expand drops the restriction, or keeps the always-hidden section hidden while "hide separators" is on. A new restriction is activated before the old one is dropped. Every failure (API missing, no Accessibility, activation error) leaves the bar expanded and reports .unavailable; the controller shows it as expanded. Separators stay at their normal width. Limits: hiding is per app (an app's icons move together, most visible wins); macOS's own items stay visible; an app launched while collapsed stays hidden until the next collapse re-reads the sections. Adds an unhosted HiddenBarTests target: layout resolver (LTR/RTL, grouping, exclusions) and engine transitions against fake inventory and visibility. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Found testing the direct build on 27.0: - The Accessibility walk blocked the collapse for up to ~18s: every running process was queried with the default timeout, and dozens of WebKit/XPC helpers never answer. Query only app bundles (the only status-item owners seen), with a 0.1s timeout, off the main thread (~1s total). - The separators sat idle beside the arrow while collapsed. They drop to zero width once hiding succeeds and return on expand (zero width rather than isVisible, which would forget their position). - Log the resolved sections, and every distinct reason hiding is unavailable, instead of only the first. Also measured: the allow-list matches an app's own items only for the copy LaunchServices resolves for its bundle id, which for an installed app is the one in /Applications. Other copies of Hidden Bar (build products, archives) have their items hidden. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
With native hiding the separator no longer has to widen, so it only duplicated the arrow. The native engine now reads sections relative to the arrow (apps on its left are hidden) and keeps the regular separator at zero width, not removed, so macOS keeps its saved position for the legacy engine. The always-hidden separator still marks the third section while expanded. The "is the arrangement usable" checks move from the controller into the engines, since they depend on which item is the boundary: the legacy engine keeps the separator-left-of-arrow rule, the native engine accepts any arrangement and checks the always-hidden separator against the arrow. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Zero width still left a gap beside the arrow, since macOS pads every status item. The native engine hides the regular separator outright, and the controller creates the engine at launch so it never flashes on screen. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 19, 2026
7 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #402 (review that first; this diff is against its branch). Part of #360, related #366.
Important
This uses private Apple API (
MenuBarClientCore), compiled only into a new non-sandboxed direct-download build. The App Store build is unchanged and contains none of it.Why
On macOS 27 an over-wide status item is ejected from the menu bar, so widening the separator hides nothing (#360). Measured on 27.0: the widest separator macOS 27 still lays out (~939pt on a 1920pt display) displaces icons but doesn't hide them, and the bar reorders itself between collapses. Width-based fixes (#382, #392, #396, #397) pick a fraction of the display width, sometimes with spacer items. They still depend on display width, the notch and the frontmost app's menus.
macOS 27 can hide menu-bar items itself. Its assessment (exam lockdown) mode restricts the bar to an allow-list of apps and reflows it. This PR drives that directly, the same mechanism Pelmet uses (behavior only; no code taken from it, it's GPL).
What's this PR do?
NativeVisibilityEngine(macOS 27+, direct build only). On collapse it reads which apps sit left of the arrow (Accessibility), then activates a restriction that keeps only Hidden Bar, the visible apps and macOS's own items. Expand drops the restriction, or keeps the always-hidden section hidden while "hide separators" is on. A new restriction is activated before the old one is dropped, so there's no flash.HBNativeVisibilityShim(Objective-C) is the only file that touches the private framework. It resolvesMBAssessmentModeConfiguration/MBAssessmentModeAssertionat runtime, checks every selector and catches exceptions. It compiles only withHIDDENBAR_NATIVE_VISIBILITY.Debug-Direct/Release-Directconfigurations set that flag and sign withHidden-Direct.entitlements(no App Sandbox).MenuBarLayoutResolveris a pure function that maps item frames to visible / hidden / always-hidden. When one app has several icons, the most visible section wins.AccessibilityMenuBarInventorylists other apps' status items. It queries only app bundles, with a 0.1s timeout per app, off the main thread. The first version blocked the main thread for ~18s on WebKit helpers.HiddenBarTeststarget with 17 tests. They cover the resolver (LTR/RTL, grouping, exclusions) and the engine's state transitions against fake inventory and visibility, including late activations after an expand, not re-reading while hidden, and failure paths.Measured on macOS 27.0 before relying on it
mach-lookup com.apple.axservereven with Accessibility granted, so a sandboxed app can't read other apps' items. That's why this is direct-build only.NSArrays (anNSSetraises). System items are numeric IDs (2 clock, 5 sound, 6 Wi-Fi, 8 Control Center); unknown IDs up to 63 are ignored./Applications. A copy run from elsewhere hides its own arrow.Limits
docs/BACKLOG.md.Open decisions
com.dwarvesv.minimalbar.direct; the project still usescom.dwarvesv.minimalbar.|separator, which the direct build on 27 no longer uses.Validation
xcodebuild ... -configuration Debug test: 17 tests passMenuBarClientCore/MBAssessmentModestrings/Applicationswith Accessibility:🤖 Generated with Claude Code