Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ DerivedData/

# Local agent/tooling layer (kept out of the repo)
/.claude/
/.codex/
/script/
/CLAUDE.local.md
/AGENTS.md
/CLAUDE.md
Expand Down
45 changes: 26 additions & 19 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

Hidden Bar is a single-process, sandboxed AppKit menubar utility (~1.5k lines of
Swift, one dependency: [HotKey](https://github.com/soffes/HotKey)). There is no
helper app, no daemon, no network. Everything happens inside three
`NSStatusItem`s and one window.
helper app, no daemon, no network. The menu-bar controls and one preferences
window contain the app's behavior.

## The core trick

macOS offers no API to hide other apps' menubar icons. Hidden Bar fakes it with
geometry: a separator status item whose **length is inflated to roughly the
width of the widest attached screen**, shoving every icon to its left off-screen.
Collapsing and expanding is just flipping that length between ~20pt and the
inflated value.
macOS offers no public API to hide other apps' menubar icons. Hidden Bar uses
status-item geometry to move icons left of its separator out of the visible bar.
On macOS 26 and earlier the separator grows to twice the widest screen width.
On macOS 27 each item must stay below roughly half the narrowest screen width;
additional status items supply the rest of the displacement on wide screens.
macOS 27 moves displaced icons into its native overflow. Expanding returns the
separator to 20pt and the extra items to zero requested width.

```mermaid
flowchart LR
subgraph menubar [menu bar, right to left]
direction RL
ARROW["arrow item\n(toggle, variable length)"]
SEP["separator item\n20pt expanded / ~2x screen width collapsed"]
SEP["separator item\n20pt expanded / inflated when collapsed"]
HIDDEN["other apps' icons\npushed off-screen when collapsed"]
ALWAYS["always-hidden separator\n(optional)"]
end
Expand All @@ -27,12 +29,15 @@ flowchart LR

Key consequences of this design:

- The menubar replicates on every display, so the collapse length derives from
the **widest** screen (`NSScreen.screens`), never `NSScreen.main`, and is
re-applied to the live item on `didChangeScreenParametersNotification`
(display hot-plug).
- The length is bounded: `max(500, min(widestFrameWidth * 2, 10_000))`. macOS
enforces a hard 10,000pt maximum on `NSStatusItem.length`.
- The menubar replicates on every display. Before macOS 27 the collapse length
derives from the **widest** screen and is bounded at 10,000pt. On macOS 27
each item's length derives from the **narrowest** screen so it stays below the
per-display rejection threshold. The live lengths are recomputed after display
changes.
- macOS 27's extra items are created only for wide screen layouts. They retain
their native slots at zero requested width when expanded; toggling
`isVisible` would reorder them on that system. The number is chosen at launch,
so a screen width change that needs more slots requires a restart.
- `isCollapsed` is derived state: `separator.length > 20`, deliberately not an
equality check, so it survives the length being recomputed while collapsed.
- Icons macOS inserts to the LEFT of the separator (where new status items
Expand All @@ -45,7 +50,7 @@ flowchart TD
AD[AppDelegate] -->|owns| SBC[StatusBarController]
AD -->|registers| SM["SMAppService.mainApp\n(login item, macOS 13+)"]
AD -->|global hotkey| HK[HotKey lib]
SBC -->|3 status items| NSB[NSStatusBar.system]
SBC -->|status items| NSB[NSStatusBar.system]
SBC -->|auto-hide| T["one-shot Timer\n(re-arms while pointer in menubar)"]
SBC -->|opt-in| HM["global mouseMoved monitor\n(hover-to-expand, only if pref on)"]
PREFS[Preferences facade] -->|UserDefaults| UD[(UserDefaults)]
Expand All @@ -57,7 +62,7 @@ flowchart TD

- **`AppDelegate`** (entry): registers default prefs, sets up the global hotkey,
runs the one-shot legacy login-item migration, owns the `StatusBarController`.
- **`StatusBarController`** (the product, ~370 lines): the three status items,
- **`StatusBarController`** (the product): the status items,
collapse/expand, auto-hide timer, interaction-awareness, hover-to-expand,
self-restore of dragged-off items.
- **`Preferences`** (facade enum): typed accessors over `UserDefaults`; setters
Expand Down Expand Up @@ -97,9 +102,11 @@ A full-tree audit (2026-06) scored 9/10 with hygiene-level findings only.
- **The notch**: hidden icons sit "under" the notch area on notched Macs; the
trick cannot reveal them there. The real fix is a spillover/second-bar design
(tracked in issues #357/#341/#148; candidate implementations in PRs #350/#358).
- **macOS 27**: the menu bar re-architecture in macOS 27 betas
(`NSMenuBarNavigationSceneExtension`) breaks length-inflation hiding entirely
(issue #360). A different mechanism may be required.
- **macOS 27**: a single oversized status item is discarded. The smaller-item
approach restores ordinary hiding on a 1728pt display, but wide, mixed-width,
notched and right-to-left layouts still need physical verification. The
optional always-hidden separator has no additional spacer group and may not
hide its section on a wide display while the ordinary section is expanded.
- **Other apps' open menus**: interaction-awareness is pointer-position-based;
a pointer deep inside another app's open dropdown is below the menubar band,
so the collapse can still fire there.
28 changes: 10 additions & 18 deletions docs/BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@ Source of the current state: the v1.11 issue-clearing pass (2026-06-12), branch
`fix/v1-11-batch` / draft PR #365, and SPEC-003. Core-model changes (separator length
math, collapse state machine) are HIGH RISK and require a mandatory review-team pass.

## Blocked on macOS 27 hardware (Han UAT)
## macOS 27 follow-up

- **macOS 27 hide-mechanism capture (#360).** Run the v1.11 build on real macOS 27,
trigger a collapse, capture the `HideMechanism:` NSLog (requested length / host-window
width / button width / actual length). This is the unblocker: it reveals which geometry
signal separates "honored" from "ignored" on 27. Diagnostic-only instrument already
shipped. See SPEC-003 + `StatusBarController.swift` (collapse path).
- **Redesign the detection signal, then ship Option B (detect-and-degrade).** Review-team
found `btnSeparate.button?.window?.frame.width` reads the full menu-bar window width
(~1728pt on 26.5), so `honored` is trivially true on every OS. Switch to a positional
signal (separator button X-coordinate before vs after collapse). Once the 27 capture
calibrates it: re-add the one-shot post-collapse check, a one-time context-menu notice
linking #360, and stop re-inflating on confirmed failure. Depends on the capture above.
- **Fix the 3 review bugs when re-enabling degrade.** (1) move the `hideMechanismChecked`
latch to AFTER `honored` is measured (a transient nil window currently burns the
one-shot check); (2) drop the `?? requested` nil-fallback that latches detection moot;
(3) `degradeHideUnavailable()` must restore the app activation policy under
"use full menu bar on expanding", or the bar shows while the app stays `.accessory`.
`StatusBarController.swift:316,318,329`.
- **Verify #360 across hardware.** The smaller-item fix hides three sample
icons on a 1728pt macOS 27.2 display with a single separator and no expanded
spacer gap. Check wide,
mixed-width, notched and RTL setups. The always-hidden section still uses one
separator, so it needs a separate wide-display fix.
- **Finish public release validation.** A complete local app was built and
ad hoc signed with the Command Line Tools, using unchanged v1.10 compiled
storyboard/assets. Public distribution still needs an Xcode archive,
Developer ID signing, notarization and the standard release checks.

## Blocked on external-display hardware

Expand Down
4 changes: 2 additions & 2 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Everything Hidden Bar can do, including the parts with no UI.
- **Self-repair**: if the arrow or separator was ⌘-dragged off the bar (which
used to make the app unreachable forever), they come back on next launch.
- **Display changes**: plugging in or removing monitors re-sizes the hidden zone
for the widest attached screen automatically.
for the attached screens automatically.

## Hidden settings (Terminal)

Expand All @@ -66,7 +66,7 @@ To undo any of them: `defaults delete com.dwarvesv.minimalbar <key>`.
| Login item missing after denying it once | System Settings > General > Login Items: re-enable Hidden Bar, then toggle the pref off/on |
| A ghost "LauncherApplication" login item from old versions | Launch the current version once; it deauthorizes the legacy item automatically |
| App language stuck | See the `AppleLanguages` command above, or System Settings > General > Language & Region > Applications |
| Nothing hides on a macOS 27 beta | Known (issue #360); the menu bar re-architecture broke the hiding mechanism, fix under investigation |
| Nothing hides after updating to macOS 27 | Run the current build, then ⌘-drag the icons you want hidden to the left of its new separator once. macOS 27 stores the new control positions separately. |
| A new or just-updated app's icon shows up already hidden | Expected, see "Why new icons start hidden" below; ⌘-drag it to the right of the separator once |

### Why new icons start hidden
Expand Down
8 changes: 6 additions & 2 deletions docs/RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ deprecated `SMLoginItemSetEnabled(false)` call that cleans up legacy installs.
The repo has no unit-test infrastructure; behavior is verified against the real
menu bar. Two building blocks make that scriptable:

1. **Truth signal**: the separator's AX size.
1. **Geometry signal**: the separator's AX size.
`osascript -e 'tell application "System Events" to tell process "Hidden Bar" to get size of menu bar item 2 of menu bar 2'`
reads ~20pt expanded vs ~2x-screen-width collapsed. Item 1 is the arrow.
reads ~20pt expanded vs ~2x-screen-width collapsed on macOS 26 and earlier.
On macOS 27 the separator stays below half the narrowest screen width and
any adjacent spacers grow with it. Geometry alone does not prove that other
apps' icons left the bar; inspect the visible menu bar before and after.
Item 1 is the arrow on older systems; macOS 27 may expose a different AX tree.
2. **Real clicks, not AXPress**: `AXPress` on the arrow is a no-op because the
action handler reads `NSApp.currentEvent` (nil under assistive synthesis;
known accessibility defect). Post real `CGEvent` mouse clicks at the arrow's
Expand Down
109 changes: 64 additions & 45 deletions hidden/Features/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,35 @@ class StatusBarController {

//MARK: - BarItems

private let btnExpandCollapse = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
private let btnSeparate = NSStatusBar.system.statusItem(withLength: 1)
// New names on macOS 27 establish the order arrow, spacers, separator in
// MenuBarAgent's layout. Existing names keep their saved positions on 26.
private static let autosaveSuffix: String = {
if #available(macOS 27.0, *) { return "_v27" }
return ""
}()
private static func makeItem(_ name: String, length: CGFloat) -> NSStatusItem {
let item = NSStatusBar.system.statusItem(withLength: length)
item.autosaveName = name + autosaveSuffix
return item
}
private let btnExpandCollapse = StatusBarController.makeItem("hiddenbar_expandcollapse", length: NSStatusItem.variableLength)
private let spacers: [NSStatusItem] = {
guard #available(macOS 27.0, *) else { return [] }
let widths = NSScreen.screens.map { $0.frame.width }
let narrowest = widths.min() ?? 1728
let widest = widths.max() ?? 1728
let unit = max(100, floor(narrowest / 2 - 64))
// A single item clears a normal laptop bar. Even a requested length of
// zero consumes 16pt per extra item on macOS 27, so only reserve slots
// when a wider display needs more displacement.
let count = min(6, max(0, Int(ceil((widest - 2056) / unit))))
return (0..<count).map { index in
let item = StatusBarController.makeItem("hiddenbar_spacer\(index)", length: 0)
item.button?.isEnabled = false
return item
}
}()
private let btnSeparate = StatusBarController.makeItem("hiddenbar_separate", length: 1)
private var btnAlwaysHidden:NSStatusItem? = nil

private var btnHiddenLength: CGFloat = 20
Expand Down Expand Up @@ -63,16 +90,6 @@ class StatusBarController {

private var isToggle = false

// SPEC-003 (macOS 27 hide-mechanism). macOS 27 re-architected the menu bar so
// inflating the separator length may no longer push items off-screen (#360).
// This is DIAGNOSTIC ONLY: on the first collapse with the menu-bar window
// ready, log the separator geometry so a macOS 27 run reveals which signal
// (if any) distinguishes "length honored" from "ignored". No behavior change.
// The degrade ACTION is deliberately NOT shipped: review found the trigger
// unverifiable without 27 hardware, and a false positive would disable hiding
// for a working user. The action lands once this log calibrates the signal.
private var hideMechanismChecked = false

private var hoverMonitor: Any?
private var hoverDwellTimer: Timer?

Expand Down Expand Up @@ -107,9 +124,7 @@ class StatusBarController {
setupAlwayHideStatusBar()
setupHoverToExpandIfEnabled()
NotificationCenter.default.addObserver(self, selector: #selector(handleScreenParametersChanged), name: NSApplication.didChangeScreenParametersNotification, object: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.collapseMenuBar()
}
collapseAtLaunch(attemptsRemaining: 20)

if Preferences.areSeparatorsHidden {hideSeparators()}
autoCollapseIfNeeded()
Expand Down Expand Up @@ -154,13 +169,24 @@ class StatusBarController {
updateCollapsedLengths()
if wasCollapsed {
btnSeparate.length = btnHiddenCollapseLength
setSpacersLength(btnHiddenCollapseLength)
if Preferences.areSeparatorsHidden {
btnAlwaysHidden?.length = btnAlwaysHiddenEnableExpandCollapseLength
}
}
}

private func updateCollapsedLengths() {
if #available(macOS 27.0, *) {
// MenuBarAgent drops a status item at roughly half a display's
// width. Every item appears on every display, so use the narrowest
// one's limit. Spacers provide the total width needed on wide bars.
let narrowest = NSScreen.screens.map { $0.frame.width }.min() ?? 1728
let unit = max(100, floor(narrowest / 2 - 64))
btnHiddenCollapseLength = unit
btnAlwaysHiddenEnableExpandCollapseLength = Preferences.alwaysHiddenSectionEnabled ? unit : 0
return
}
// The menubar replicates across every attached display, so the collapse
// length must cover the WIDEST screen, not NSScreen.main (the focused one);
// sizing from a narrower screen leaks hidden icons on wider displays.
Expand All @@ -179,6 +205,24 @@ class StatusBarController {
// the app's only UI, so they self-restore at launch.
btnExpandCollapse.isVisible = true
btnSeparate.isVisible = true
spacers.forEach { $0.isVisible = true }
}

private func setSpacersLength(_ length: CGFloat) {
// Keep the slots visible at zero width while expanded. Hiding and
// reshowing them with isVisible reorders the slots on macOS 27.
spacers.forEach { $0.length = length }
}

private func collapseAtLaunch(attemptsRemaining: Int) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
guard let self = self, !self.isCollapsed else { return }
if self.isBtnSeparateValidPosition {
self.collapseMenuBar()
} else if attemptsRemaining > 1 {
self.collapseAtLaunch(attemptsRemaining: attemptsRemaining - 1)
}
}
}

private func setupUI() {
Expand All @@ -198,8 +242,6 @@ class StatusBarController {
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
}

btnExpandCollapse.autosaveName = "hiddenbar_expandcollapse";
btnSeparate.autosaveName = "hiddenbar_separate";
}

@objc func btnExpandCollapsePressed(sender: NSStatusBarButton) {
Expand Down Expand Up @@ -268,19 +310,22 @@ class StatusBarController {
return
}

if #available(macOS 27.0, *) { btnSeparate.button?.image = nil }
btnSeparate.length = self.btnHiddenCollapseLength
setSpacersLength(btnHiddenCollapseLength)
if let button = btnExpandCollapse.button {
button.image = Assets.expandImage
}
if Preferences.useFullStatusBarOnExpandEnabled {
NSApp.setActivationPolicy(.accessory)
NSApp.deactivate()
}
verifyHideMechanismIfNeeded()
}
private func expandMenubar() {
guard self.isCollapsed else {return}
if #available(macOS 27.0, *) { btnSeparate.button?.image = imgIconLine }
btnSeparate.length = btnHiddenLength
setSpacersLength(0)
if let button = btnExpandCollapse.button {
button.image = Assets.collapseImage
}
Expand All @@ -300,32 +345,6 @@ class StatusBarController {
startTimerToAutoHide()
}

// After a collapse, confirm on the next runloop tick (so layout settles) that
// the separator actually claimed its inflated width. macOS <= 26 honors it;
// a macOS that ignores NSStatusItem.length leaves the slot narrow, meaning
// hiding did nothing. Checked once: cheap, and the OS behavior won't change
// mid-session.
private func verifyHideMechanismIfNeeded() {
guard !hideMechanismChecked else { return }
DispatchQueue.main.async { [weak self] in
guard let self = self, self.isCollapsed else { return }
// Need the separator's backing window to measure. If it is not up yet
// (early launch), do NOT burn the one-shot check: return and let a
// later collapse retry once the window exists.
guard let separatorButton = self.btnSeparate.button,
let window = separatorButton.window else { return }
self.hideMechanismChecked = true
// Log several geometry signals. On macOS <= 26 the inflation is
// honored; on macOS 27 it may be ignored. Which of these tracks the
// requested length is exactly what a 27 capture must reveal before any
// degrade action can trigger on a sound signal.
let requested = self.btnHiddenCollapseLength
let windowWidth = window.frame.width
let buttonWidth = separatorButton.frame.width
NSLog("HideMechanism: requested=\(requested) windowWidth=\(windowWidth) buttonWidth=\(buttonWidth) length=\(self.btnSeparate.length)")
}
}

private func startTimerToAutoHide() {
timer?.invalidate()
self.timer = Timer.scheduledTimer(withTimeInterval: Preferences.numberOfSecondForAutoHide, repeats: false) { [weak self] _ in
Expand Down Expand Up @@ -403,7 +422,7 @@ extension StatusBarController {
button.image = self.imgIconLine
button.appearsDisabled = true
}
self.btnAlwaysHidden?.autosaveName = "hiddenbar_terminate"
self.btnAlwaysHidden?.autosaveName = "hiddenbar_terminate" + StatusBarController.autosaveSuffix
self.btnAlwaysHidden?.isVisible = true
} else {
if let existing = self.btnAlwaysHidden {
Expand Down