From bf66066aa004aefb63bdd136c4b6ad94dea70c2a Mon Sep 17 00:00:00 2001 From: Laveez Date: Tue, 14 Apr 2026 15:59:09 +0300 Subject: [PATCH] fix: properly hide menu bar items on ultra-wide and multi-monitor setups - Fix collapse calculation to use the widest connected display instead of the currently focused screen - Raise the collapse width cap from 4,000 to 10,000 (macOS hard limit) - Keep the bar collapsed when displays are connected or disconnected - Fix collapsed state detection to be resilient to width recalculations Fixes #314, fixes #345, fixes #353 --- .../StatusBar/StatusBarController.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hidden/Features/StatusBar/StatusBarController.swift b/hidden/Features/StatusBar/StatusBarController.swift index 1d17718..fff373b 100644 --- a/hidden/Features/StatusBar/StatusBarController.swift +++ b/hidden/Features/StatusBar/StatusBarController.swift @@ -28,7 +28,7 @@ class StatusBarController { private let imgIconLine = NSImage(named:NSImage.Name("ic_line")) private var isCollapsed: Bool { - return self.btnSeparate.length == self.btnHiddenCollapseLength + return self.btnSeparate.length > self.btnHiddenLength } private var isBtnSeparateValidPosition: Bool { @@ -80,16 +80,24 @@ class StatusBarController { } @objc private func handleScreenParametersChanged() { + let wasCollapsed = isCollapsed updateCollapsedLengths() + if wasCollapsed { + btnSeparate.length = btnHiddenCollapseLength + if Preferences.areSeparatorsHidden { + btnAlwaysHidden?.length = btnAlwaysHiddenEnableExpandCollapseLength + } + } } private func updateCollapsedLengths() { - let screenWidth = NSScreen.main?.visibleFrame.width ?? 1728 - // Keep collapse length bounded to avoid pathological layout/memory behavior - // on newer macOS versions while still fully hiding the trailing section. - let boundedCollapseLength = max(500, min(screenWidth + 200, 4000)) - btnHiddenCollapseLength = boundedCollapseLength - btnAlwaysHiddenEnableExpandCollapseLength = Preferences.alwaysHiddenSectionEnabled ? boundedCollapseLength : 0 + // Use the widest screen across all displays so the collapse length is always + // large enough, regardless of which display has focus. + // macOS enforces a hard 10,000pt maximum for NSStatusItem.length. + let screenWidth = NSScreen.screens.map { $0.frame.width }.max() ?? 1728 + let collapseLength = max(500, min(screenWidth * 2, 10_000)) + btnHiddenCollapseLength = collapseLength + btnAlwaysHiddenEnableExpandCollapseLength = Preferences.alwaysHiddenSectionEnabled ? collapseLength : 0 } private func setupUI() {