Skip to content
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Unreleased

### Fixed
- Auto-hide no longer waits on a screen-edge window one or two points wide, such as the hot border a KVM switch draws, and it now sees a menu bar popup that starts a few points above the bar ([#548](https://github.com/dwarvesf/hidden/issues/548)).
- macOS 27 (direct build): clicking the clock while the bar is collapsed no longer moves the pointer to the middle of the clock. Hidden Bar now repeats the click where the pointer already is ([#547](https://github.com/dwarvesf/hidden/issues/547)).
- Auto-hide works while the Settings window is open. It used to wait for the window to close even with "Make room for icons while they are shown" off, and Settings opens at every launch by default, so the bar could stay expanded for good. With the option on, auto-hide still waits for the window, as the collapse would close it mid-edit.

### Changed
- When auto-hide holds back because of the Settings window, the new-apps prompt, Notification Center, the palette or the pointer sitting in the menu bar, the log now says which, once per expansion. Look for "AutoCollapse: holding for" in Console.

## v1.13.1 (2026-11-18)

### Added
Expand Down
17 changes: 17 additions & 0 deletions HiddenBarTests/AutoCollapsePopupGuardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ final class AutoCollapsePopupGuardTests: XCTestCase {
XCTAssertEqual(ownerReads, 1, "item owners are asked for only when a candidate window needs them")
}

// KVM hot borders and similar tools keep a 1 pt window on the screen edge.
func testThinEdgeWindowsDoNotDefer() {
let popupGuard = makeGuard()
list.windows = [
window(netMonitor, layer: 0, CGRect(x: 0, y: 0, width: 1, height: 900)),
window(99, layer: status, CGRect(x: 1599, y: 0, width: 1, height: 900)),
window(99, layer: status, CGRect(x: 0, y: 24, width: 1600, height: 4)),
]
XCTAssertFalse(popupGuard.defersCollapse())
}

func testPopupStartingAboveTheBarDefers() {
let popupGuard = makeGuard()
list.windows = [window(netMonitor, layer: popUpMenu, CGRect(x: 1200, y: -6, width: 300, height: 400))]
XCTAssertTrue(popupGuard.defersCollapse())
}

func testPopupUnderASecondDisplaysMenuBarDefers() {
let popupGuard = makeGuard()
list.windows = [window(netMonitor, layer: popUpMenu, CGRect(x: 2100, y: -334, width: 280, height: 300))]
Expand Down
15 changes: 15 additions & 0 deletions HiddenBarTests/MenuBarEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,21 @@ final class NativeVisibilityEngineTests: XCTestCase {
}
}

// The replay clicks where the pointer already is, so it does not jump to the
// clock's centre.
func testClockReplayClicksAtThePointerInsideTheClock() {
let clock = CGRect(x: 1880, y: 0, width: 60, height: 24)
let pointer = CGPoint(x: 1895, y: 6)
XCTAssertEqual(SystemMenuBarClock.replayPoint(pointer: pointer, clockFrame: clock), pointer)
}

func testClockReplayFallsBackToTheCentreWhenThePointerIsOutsideOrUnknown() {
let clock = CGRect(x: 1880, y: 0, width: 60, height: 24)
let centre = CGPoint(x: 1910, y: 12)
XCTAssertEqual(SystemMenuBarClock.replayPoint(pointer: CGPoint(x: 600, y: 400), clockFrame: clock), centre)
XCTAssertEqual(SystemMenuBarClock.replayPoint(pointer: nil, clockFrame: clock), centre)
}

func testClockIsWatchedOnlyWhileARestrictionIsHeld() {
let engine = makeEngine()
XCTAssertNil(clock.onClick)
Expand Down
9 changes: 7 additions & 2 deletions hidden/Features/StatusBar/AutoCollapsePopupGuard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ final class AutoCollapsePopupGuard {
}

// Touches the band (or sits just under it) and reaches below it, so the
// menu bar's own windows and its items are not popups.
// menu bar's own windows and its items are not popups. A popup may start
// above the band, and a window thinner than a popup can be is a screen-edge
// hot border (KVM switches draw one 1 pt wide).
static let minPopupThickness: CGFloat = 8

static func hangs(_ frame: CGRect, from band: CGRect) -> Bool {
guard frame.width >= minPopupThickness, frame.height >= minPopupThickness else { return false }
let reach = CGRect(x: band.minX, y: band.minY, width: band.width, height: band.height + bandTolerance)
return frame.intersects(reach) && frame.maxY > band.maxY + 1 && frame.minY >= band.minY - 1
return frame.intersects(reach) && frame.maxY > band.maxY + 1
}

// Same band as the clock's menu-bar hit test.
Expand Down
13 changes: 12 additions & 1 deletion hidden/Features/StatusBar/Engine/Native/MenuBarClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ final class SystemMenuBarClock: MenuBarClockProviding {
static var debugPressWithAX = false
#endif

// Where the pointer is now, in the same global top-left space as the clock's frame.
var pointerLocation: () -> CGPoint? = { CGEvent(source: nil)?.location }

private var monitor: Any?
// The clock's frame when a click on it began with Notification Center closed.
private var clickedClockFrame: CGRect?
Expand All @@ -330,11 +333,12 @@ final class SystemMenuBarClock: MenuBarClockProviding {
let onMain = { (outcome: ClockPressOutcome) in
DispatchQueue.main.async { restore(); finished(outcome) }
}
let pointerLocation = self.pointerLocation
queue.asyncAfter(deadline: .now() + Self.liftDelay) {
let clocks = Self.clocks()
// Never replay on a different display if its clock cannot be found.
guard let clock = clocks.first(where: { $0.frame.contains(location) }),
let events = Self.clickEvents(at: CGPoint(x: clock.frame.midX, y: clock.frame.midY)) else {
let events = Self.clickEvents(at: Self.replayPoint(pointer: pointerLocation(), clockFrame: clock.frame)) else {
return onMain(.noClock)
}
#if DEBUG
Expand Down Expand Up @@ -368,6 +372,13 @@ final class SystemMenuBarClock: MenuBarClockProviding {
}
}

// The replayed click lands on the pointer when it is already on the clock, so
// the pointer stays put; otherwise on the clock's centre.
static func replayPoint(pointer: CGPoint?, clockFrame: CGRect) -> CGPoint {
if let pointer, clockFrame.contains(pointer) { return pointer }
return CGPoint(x: clockFrame.midX, y: clockFrame.midY)
}

static func clickEvents(at point: CGPoint) -> [CGEvent]? {
// Build both before posting either, so allocation failure cannot leave a
// mouse-down without its matching mouse-up. Do not inherit modifiers.
Expand Down
28 changes: 24 additions & 4 deletions hidden/Features/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ class StatusBarController: MenuBarItemProvider {
// expanding" on, an auto-collapse deactivates the app and dismisses this
// window mid-edit (#170, same family as #66/#151). Defer the collapse while
// it is on screen, without creating the controller or loading its window
// when preferences were never opened.
// when preferences were never opened. With the option off nothing is
// dismissed, so the window must not hold auto-hide.
private var isPreferencesWindowVisible: Bool {
return PreferencesWindowController.isVisible
return wantsFullBar && PreferencesWindowController.isVisible
}

//MARK: - Methods
Expand Down Expand Up @@ -498,6 +499,7 @@ class StatusBarController: MenuBarItemProvider {
button.image = Assets.collapseImage
}
popupGuard.reset()
loggedCollapseHolds.removeAll()
autoCollapseIfNeeded()

if activatingApp && wantsFullBar {
Expand Down Expand Up @@ -539,7 +541,25 @@ class StatusBarController: MenuBarItemProvider {
// A popup hanging from the menu bar (#319) defers for up to 10 minutes; the
// window list is read last, only when nothing else defers.
private var defersCollapseApartFromPointer: Bool {
return isPreferencesWindowVisible || arrivalsPromptIsShown || menuBarEngine.defersAutoCollapse || isRevealingForPalette || popupGuard.defersCollapse()
return holdsCollapse(for: "the Settings window", if: isPreferencesWindowVisible)
|| holdsCollapse(for: "the new-apps prompt", if: arrivalsPromptIsShown)
|| holdsCollapse(for: "Notification Center", if: menuBarEngine.defersAutoCollapse)
|| holdsCollapse(for: "the palette", if: isRevealingForPalette)
|| popupGuard.defersCollapse()
}

// Reasons already logged since the bar last expanded, so a hold that lasts
// many timer fires logs once. Only the reason is logged, never window titles.
private var loggedCollapseHolds = Set<String>()

// The condition is evaluated lazily, so the order and short-circuit of the
// callers do not change.
private func holdsCollapse(for reason: String, if condition: @autoclosure () -> Bool) -> Bool {
guard condition() else { return false }
if loggedCollapseHolds.insert(reason).inserted {
NSLog("AutoCollapse: holding for %@", reason)
}
return true
}

// The palette has an app's menu open that it allowed for a moment.
Expand All @@ -562,7 +582,7 @@ class StatusBarController: MenuBarItemProvider {
// from the clock collapses the bar itself once it closes. A popup
// hanging from the menu bar (#319) defers too, for up to 10 minutes;
// the window list is read last, only when nothing else defers.
if self.isMouseInMenuBar || self.defersCollapseApartFromPointer {
if self.holdsCollapse(for: "the pointer in the menu bar", if: self.isMouseInMenuBar) || self.defersCollapseApartFromPointer {
self.startTimerToAutoHide()
} else {
self.collapseMenuBar()
Expand Down