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
4 changes: 4 additions & 0 deletions Hidden Bar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
92C97B8D220058740007559C /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C97B8C220058740007559C /* NSView+Extension.swift */; };
92C97B8F220147FE0007559C /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C97B8E220147FE0007559C /* Constant.swift */; };
92C97B9122018C1F0007559C /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C97B9022018C1F0007559C /* StatusBarController.swift */; };
AA1234560001000000000001 /* MenuBarOverlayWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1234560001000000000002 /* MenuBarOverlayWindow.swift */; };
92D2122221FEE06600C92FF4 /* LauncherApplication.app in Sources */ = {isa = PBXBuildFile; fileRef = 92C5054E21FEC03B0084719A /* LauncherApplication.app */; };
967F4B2524169BC800F18D3C /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967F4B2424169BC800F18D3C /* String+Extension.swift */; };
967F4B2824169CAF00F18D3C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 967F4B2A24169CAF00F18D3C /* Localizable.strings */; };
Expand Down Expand Up @@ -103,6 +104,7 @@
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?

967F4B2424169BC800F18D3C /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
967F4B2924169CAF00F18D3C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
967F4B2B24169CB200F18D3C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,7 @@
isa = PBXGroup;
children = (
92C97B9022018C1F0007559C /* StatusBarController.swift */,
AA1234560001000000000002 /* MenuBarOverlayWindow.swift */,
);
path = StatusBar;
sourceTree = "<group>";
Expand Down Expand Up @@ -405,6 +408,7 @@
08A5F85C23AA013100981CA5 /* SelectedSecond.swift in Sources */,
08A5F86123AA085B00981CA5 /* Preferences.swift in Sources */,
92C97B9122018C1F0007559C /* StatusBarController.swift in Sources */,
AA1234560001000000000001 /* MenuBarOverlayWindow.swift in Sources */,
55F3F1192608923B0054B881 /* Date+Extension.swift in Sources */,
92D2122221FEE06600C92FF4 /* LauncherApplication.app in Sources */,
08B9F32C2411883300AA0551 /* NSWindow+Extension.swift in Sources */,
Expand Down
48 changes: 48 additions & 0 deletions hidden/Features/StatusBar/MenuBarOverlayWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// MenuBarOverlayWindow.swift
// Hidden Bar
//
// Created for ultra-wide monitor support.
// Covers menu bar items that macOS won't push off-screen.
//

import AppKit

class MenuBarOverlayWindow: NSPanel {

override var canBecomeKey: Bool { return false }
override var canBecomeMain: Bool { return false }

init() {
super.init(
contentRect: .zero,
styleMask: [.borderless, .nonactivatingPanel],
backing: .buffered,
defer: true
)

// Window configuration: sit just above status items so we cover them.
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?

hasShadow = false
ignoresMouseEvents = false // Block clicks on covered items when collapsed
isReleasedWhenClosed = false
}

/// Show the overlay covering the specified frame in screen coordinates.
func showOverlay(frame: NSRect) {
guard frame.width > 1 && frame.height > 0 else {
hideOverlay()
return
}
setFrame(frame, display: true)
orderFrontRegardless()
}

/// Hide the overlay.
func hideOverlay() {
orderOut(nil)
}
}
87 changes: 80 additions & 7 deletions hidden/Features/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StatusBarController {

//MARK: - Variables
private var timer:Timer? = nil
private lazy var overlayWindow = MenuBarOverlayWindow()

//MARK: - BarItems

Expand All @@ -28,7 +29,9 @@ class StatusBarController {
private let imgIconLine = NSImage(named:NSImage.Name("ic_line"))

private var isCollapsed: Bool {
return self.btnSeparate.length == self.btnHiddenCollapseLength
// Use a threshold instead of exact equality so that a screen-change
// recalculation of btnHiddenCollapseLength doesn't break state detection.
return self.btnSeparate.length > self.btnHiddenLength
}

private var isBtnSeparateValidPosition: Bool {
Expand Down Expand Up @@ -80,16 +83,31 @@ class StatusBarController {
}

@objc private func handleScreenParametersChanged() {
let wasCollapsed = isCollapsed
updateCollapsedLengths()
// If the bar was collapsed, re-apply the new collapse length and
// reposition the overlay for the new display configuration.
if wasCollapsed {
btnSeparate.length = btnHiddenCollapseLength
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.showOverlayIfNeeded()
}
}
}

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
// Determine the screen where status items live by checking the button's
// window. Fall back to NSScreen.main, then the first screen.
// macOS enforces a hard maximum of 10,000 for NSStatusItem length, so we
// cap at that value. On ultra-wide monitors where 10,000 isn't enough to
// push all items off-screen, the overlay window covers the remainder.
let screen = btnExpandCollapse.button?.window?.screen
?? NSScreen.main
?? NSScreen.screens.first
let screenWidth = screen?.frame.width ?? 1728
let collapseLength = max(500, min(screenWidth * 2, 10000))
btnHiddenCollapseLength = collapseLength
btnAlwaysHiddenEnableExpandCollapseLength = Preferences.alwaysHiddenSectionEnabled ? collapseLength : 0
}

private func setupUI() {
Expand Down Expand Up @@ -176,9 +194,16 @@ class StatusBarController {
NSApp.setActivationPolicy(.accessory)
NSApp.deactivate()
}

// After macOS finishes repositioning status items, show overlay to
// cover any items that couldn't be pushed off-screen (ultra-wide).
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.showOverlayIfNeeded()
}
}
private func expandMenubar() {
guard self.isCollapsed else {return}
overlayWindow.hideOverlay()
btnSeparate.length = btnHiddenLength
if let button = btnExpandCollapse.button {
button.image = Assets.collapseImage
Expand All @@ -199,6 +224,54 @@ class StatusBarController {
startTimerToAutoHide()
}

/// Calculate the overlay frame and show it to cover any hidden items that
/// macOS couldn't push off the left edge of the screen (ultra-wide monitors).
private func showOverlayIfNeeded() {
guard isCollapsed else {
overlayWindow.hideOverlay()
return
}

// Find the screen where the status items live (via the toggle button's window).
guard let buttonWindow = btnExpandCollapse.button?.window,
let screen = buttonWindow.screen else {
overlayWindow.hideOverlay()
return
}

// Menu bar height: on the primary screen we can derive it from the
// visible-frame inset; on secondary screens macOS often reports
// visibleFrame == frame, so fall back to NSStatusBar.system.thickness.
var menuBarHeight = screen.frame.maxY - screen.visibleFrame.maxY
if menuBarHeight < 1 {
menuBarHeight = NSStatusBar.system.thickness
}

// The overlay covers from just past the app menu zone up to the left
// 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?

let overlayLeft = screen.frame.origin.x + appMenuMargin
let rightEdge = buttonWindow.frame.origin.x
let overlayWidth = rightEdge - overlayLeft

// Only show the overlay if there's meaningful width to cover.
guard overlayWidth > 1 else {
overlayWindow.hideOverlay()
return
}

let overlayFrame = NSRect(
x: overlayLeft,
y: screen.frame.maxY - menuBarHeight,
width: overlayWidth,
height: menuBarHeight
)

overlayWindow.showOverlay(frame: overlayFrame)
}

private func startTimerToAutoHide() {
timer?.invalidate()
self.timer = Timer.scheduledTimer(withTimeInterval: Preferences.numberOfSecondForAutoHide, repeats: false) { [weak self] _ in
Expand Down