From 5a4e2fbda2fd1cd72d423e0de26fabc443949082 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 27 Sep 2026 00:39:00 +0800 Subject: [PATCH] Keep Wi-Fi visible when hiding other menu bar icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hiding pushed Wi-Fi off along with the third-party app icons. Tune the spacer boundary to sit just left of Wi-Fi so apps disappear while the Apple Wi-Fi, Spotlight, Clock, Battery and Control Center icons remain. 💘 Generated with Crush Assisted-by: Crush:deepseek-v4.1-flash --- AGENTS.md | 19 ++++++++++++------- README.md | 18 +++++++++++------- Sources/SimpleTopBar/MenuBarItems.swift | 11 +++++++---- Sources/SimpleTopBar/TopBarView.swift | 2 +- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1912677..be386c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -115,14 +115,19 @@ no control over this, so the app creates its own `NSStatusItem` and: ## Hiding other menu bar items `MenuBarHider` creates a zero-width spacer `NSStatusItem` at launch and grows its -length to `hiddenLength` (10_000) to push the icons on its left off-screen. -Verified with `--diag-hide`: +length to `hiddenLength` (10_000) to push the icons on its left off-screen. Its +preferred position controls where the hidden/kept boundary lands: -- All third-party apps' icons go to x < 0 (cmux, Kapture, moomoo, WireGuard, - TextInputMenuAgent, Now Playing) and so does Wi-Fi. -- **Spotlight, Clock, Battery and Control Center stay**: macOS pins them to the - far right, and a third-party item can never be inserted to their right, so the - spacer has nothing to push them with. Do not try to "fix" this; it is a macOS +- Seed **250** (default) puts the boundary just left of Wi-Fi, so every + third-party app icon goes to x < 0 (cmux, Kapture, moomoo, WireGuard, + TextInputMenuAgent, Now Playing) while **Wi-Fi (x≈1173), Spotlight, Clock, + Battery, Control Center and our hamburger stay visible**. +- Verified with `--diag-hide` across positions 100–400. Below ~200 Wi-Fi gets + hidden too; above ~300 app icons (Now Playing, TextInput) leak back. +- `debug.spacerPos` (Double) overrides the seed for tuning without rebuilding. +- **Wi-Fi/Spotlight/Clock/Battery/Control Center cannot be hidden**: macOS pins + them to the far right and a third-party item can never be inserted to their + right, so the spacer has nothing to push them with. This is a macOS constraint, not a bug. ## Gotchas diff --git a/README.md b/README.md index 722f37c..3e83c45 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,19 @@ the app dies, macOS removes the spacer automatically. What it can and cannot hide: -- It hides **other third-party apps' icons** (and can also catch some Apple - items such as Wi-Fi). -- It **cannot** hide **Spotlight, Clock, Battery, or Control Center**. macOS - reserves the far right of the menu bar for those, and a third-party app cannot - place its item to their right, so there is nothing to push them with. (This is - the same limit Bartender and Ice hit; they cover the area with their own - overlay bar instead.) +- It hides **other third-party apps' icons** (cmux, Kapture, WireGuard, input + source, Now Playing, …) so only your apps' icons leave the bar. +- It **keeps Wi-Fi, Spotlight, Clock, Battery and Control Center**. The spacer's + boundary is tuned (preferred position 250) to fall just left of Wi-Fi, so the + Apple items on the right stay visible. macOS reserves that far-right area: a + third-party item can never be placed to the right of it, so those icons cannot + be pushed away even in principle. (Bartender and Ice hit the same wall and + cover the area with their own overlay bar instead.) - Newly launched apps are placed to the left of the spacer, so they are hidden automatically. +- Advanced: set `defaults write dev.tzgyn.simpletopbar debug.spacerPos -float ` + to move the boundary (larger = keep more icons; > ~400 starts leaking app + icons back into the bar). ## Install with Homebrew diff --git a/Sources/SimpleTopBar/MenuBarItems.swift b/Sources/SimpleTopBar/MenuBarItems.swift index df7aae5..f6b11c4 100644 --- a/Sources/SimpleTopBar/MenuBarItems.swift +++ b/Sources/SimpleTopBar/MenuBarItems.swift @@ -167,10 +167,13 @@ final class MenuBarHider: ObservableObject { guard spacer == nil else { return } let name = "SimpleTopBarHider" let key = "NSStatusItem Preferred Position \(name)" - // Seed just left of the hamburger so growing the spacer pushes the - // third-party icons on its left off-screen while ours stays put. - if UserDefaults.standard.object(forKey: key) == nil { - UserDefaults.standard.set(150.0, forKey: key) + // The boundary between "hidden" and "kept" falls just left of Wi-Fi at + // ~250, so the other apps hide while Apple's Wi-Fi/Clock/Battery/Control + // Center/Spotlight stay visible. `debug.spacerPos` overrides the seed. + if let override = UserDefaults.standard.object(forKey: "debug.spacerPos") as? Double { + UserDefaults.standard.set(override, forKey: key) + } else if UserDefaults.standard.object(forKey: key) == nil { + UserDefaults.standard.set(250.0, forKey: key) } let item = NSStatusBar.system.statusItem(withLength: 0) item.autosaveName = name diff --git a/Sources/SimpleTopBar/TopBarView.swift b/Sources/SimpleTopBar/TopBarView.swift index 1e4e5c7..241a0fb 100644 --- a/Sources/SimpleTopBar/TopBarView.swift +++ b/Sources/SimpleTopBar/TopBarView.swift @@ -115,7 +115,7 @@ struct TopBarView: View { .controlSize(.mini) .padding(.horizontal, 12) .padding(.top, 6) - .help("Best-effort: pushes other apps' icons off the menu bar so they only live here. Apple's Spotlight, Clock, Battery and Control Center stay pinned on the right and cannot be moved by any third-party app.") + .help("Best-effort: pushes other apps' icons off the menu bar so they only live here. Apple's Wi-Fi, Spotlight, Clock, Battery and Control Center stay visible; macOS won't let any third-party app move them.") } } }