diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f350fdb..c0c3ed5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Settings › Advanced: the switch "Show all icons while macOS hides one right of the arrow" is now "Pause hiding while macOS shows Now Playing, Focus and similar items", with a note that Hidden Bar hides nothing while one of them shows. Same stored setting, same behavior ([#446](https://github.com/dwarvesf/hidden/issues/446)). ### Fixed +- macOS 27 (direct build): clicking the clock while the bar is collapsed opens Notification Center again when a notification is still on screen. A notification that stays up across a collapse (such as macOS's "App Background Activity" at login) uses the same window as the panel, so Hidden Bar took it for an open panel and ignored the click. Hidden Bar now checks that the panel itself is open (it has Edit Widgets) before treating a click as one that closes it. - macOS 14 and later: "Use the full menu bar on expanding" now takes focus. Hidden Bar became a regular app but never the active one, so the front app's menus kept the bar and the option did nothing, in full screen too. It now takes the active state from the front app, and collapsing hands focus back ([#142](https://github.com/dwarvesf/hidden/issues/142)). - Test runs no longer read or write Hidden Bar's real preferences or act on the installed app. A test host uses its own preferences suite, and skips the "Move to Applications" offer, the App Store migration prompts, Sparkle and the saved arrow positions, so a test run cannot trash or move the installed copy. - macOS 27 (direct build): Little Snitch's icon no longer hides on every collapse. Little Snitch turns Accessibility off for its apps, so Hidden Bar could not see its icon, left it off the list of apps to keep, and macOS hid it wherever it sat. Hidden Bar now keeps an app it cannot see visible, as it does for an app that does not answer. Its position stays unknown, so to hide it, set it to Hidden in Settings › Icons. This likely also covers [#514](https://github.com/dwarvesf/hidden/issues/514), whose app was not identified ([#502](https://github.com/dwarvesf/hidden/issues/502)). diff --git a/HiddenBarTests/MenuBarEngineTests.swift b/HiddenBarTests/MenuBarEngineTests.swift index 319fa81c..2548142f 100644 --- a/HiddenBarTests/MenuBarEngineTests.swift +++ b/HiddenBarTests/MenuBarEngineTests.swift @@ -2550,6 +2550,45 @@ final class ClockReplayTests: XCTestCase { } } +// Notification Center's windows as Accessibility listed them on 27.0.1 (AXIdentifier +// values, tree order). A notification left on screen at a collapse keeps a window +// as tall as the screen up, the same window the panel uses. +final class NotificationCenterPanelTests: XCTestCase { + private let desktopWidgets = [ + "widget-local:com.apple.Photos:com.apple.Photos.PhotosReliveWidget:com.apple.Photos.PhotosReliveWidget", + "widget-local:com.apple.weather:com.apple.weather.widget:com.apple.weather", + "widget-local:com.apple.iCal:com.apple.iCal.CalendarWidgetExtension:com.apple.CalendarWidget.CalendarMonthWidget", + "month-view-current-date" + ] + + func testANotificationOnScreenIsNotThePanel() { + let banner = ["C4E395C9-425E-4EF6-AD7D-EA02632B947C", "title", "body", "widgets-overlay-view"] + XCTAssertFalse(NotificationCenterPanel.isOpen(windowUp: true, identifiers: { banner + self.desktopWidgets }), + "a click on the clock must still open the panel while a notification shows") + } + + func testThePanelWithNotificationsIsOpen() { + let panel = ["AXNotificationListItems", "C4E395C9-425E-4EF6-AD7D-EA02632B947C", "title", "body", + "3287DC28-A6A6-4184-A7C0-F493275D9DD9", "title", "body", + "widget-editor-button", "xmark", "widgets-overlay-view"] + XCTAssertTrue(NotificationCenterPanel.isOpen(windowUp: true, identifiers: { panel + self.desktopWidgets })) + } + + func testTheEmptyPanelIsOpen() { + XCTAssertTrue(NotificationCenterPanel.isOpen(windowUp: true, identifiers: { ["widget-editor-button", "widgets-overlay-view"] })) + } + + func testNoWindowIsClosedWithoutAskingAccessibility() { + var asked = false + XCTAssertFalse(NotificationCenterPanel.isOpen(windowUp: false, identifiers: { asked = true; return ["widget-editor-button"] })) + XCTAssertFalse(asked, "the window list alone answers while no window is up") + } + + func testUnreadableAccessibilityFallsBackToTheWindow() { + XCTAssertTrue(NotificationCenterPanel.isOpen(windowUp: true, identifiers: { nil })) + } +} + // The clock-click state machine on its own, with a manual clock and a fake panel. final class NotificationCenterSessionTests: XCTestCase { private var time: ManualTime! diff --git a/docs/verification/notification-center/after-clock-click-fix.png b/docs/verification/notification-center/after-clock-click-fix.png new file mode 100644 index 00000000..6226d082 Binary files /dev/null and b/docs/verification/notification-center/after-clock-click-fix.png differ diff --git a/docs/verification/notification-center/after-panel-closed-collapses.png b/docs/verification/notification-center/after-panel-closed-collapses.png new file mode 100644 index 00000000..6268f664 Binary files /dev/null and b/docs/verification/notification-center/after-panel-closed-collapses.png differ diff --git a/docs/verification/notification-center/before-clock-click-1.13.0.png b/docs/verification/notification-center/before-clock-click-1.13.0.png new file mode 100644 index 00000000..ce4f90aa Binary files /dev/null and b/docs/verification/notification-center/before-clock-click-1.13.0.png differ diff --git a/hidden/Features/StatusBar/Engine/Native/MenuBarClock.swift b/hidden/Features/StatusBar/Engine/Native/MenuBarClock.swift index 95fc3b27..44c45c42 100644 --- a/hidden/Features/StatusBar/Engine/Native/MenuBarClock.swift +++ b/hidden/Features/StatusBar/Engine/Native/MenuBarClock.swift @@ -25,7 +25,8 @@ protocol MenuBarClockProviding: AnyObject { func press(at location: CGPoint, mode: ClockPressMode, restore: @escaping () -> Void, finished: @escaping (ClockPressOutcome) -> Void) - // Whether the Notification Center panel is on screen (one window-list read). + // Whether the Notification Center panel is on screen (one window-list read, and + // an Accessibility read while one of its windows is up). var isNotificationCenterOpen: Bool { get } } @@ -259,6 +260,24 @@ final class ClockReplay { } } +// Whether Notification Center's panel is open. A notification on screen keeps a +// window up that the window list cannot tell from the panel: same owner, layer and +// screen-tall bounds (27.0.1). One left on screen when the bar collapses stays +// there, and taking it for the panel dropped every click on the clock (the click +// was not replayed, or the replay reported the panel shown without pressing). +// `identifiers` lists the AXIdentifiers in Notification Center's windows, nil when +// Accessibility cannot read them; it is asked only while a window is up. +enum NotificationCenterPanel { + // Only the panel shows Edit Widgets; a notification on its own never does. + static let panelControlIdentifier = "widget-editor-button" + + static func isOpen(windowUp: Bool, identifiers: () -> [String]?) -> Bool { + guard windowUp else { return false } + guard let identifiers = identifiers() else { return true } + return identifiers.contains(panelControlIdentifier) + } +} + // Finds the clock through public Accessibility API: MenuBarAgent's menu extra // `com.apple.menuextra.clock`, which has an AXPress action. Locations are global // display coordinates with a top-left origin, as CGEvent and Accessibility use. @@ -448,13 +467,39 @@ final class SystemMenuBarClock: MenuBarClockProviding { // .excludeDesktopElements costs about 5 ms more per read; layer >= 0 // already leaves the desktop out. let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: Any]] else { return false } - return windows.contains { window in + let windowUp = windows.contains { window in guard let pid = window[kCGWindowOwnerPID as String] as? pid_t, owners.contains(pid), let layer = window[kCGWindowLayer as String] as? Int, layer >= 0, let bounds = window[kCGWindowBounds as String] as? NSDictionary, let frame = CGRect(dictionaryRepresentation: bounds) else { return false } return frame.height >= minimumHeight } + return NotificationCenterPanel.isOpen(windowUp: windowUp, identifiers: { identifiers(in: owners) }) + } + + // The AXIdentifiers in Notification Center's windows, nil when Accessibility cannot read them. + private static func identifiers(in owners: Set) -> [String]? { + var found: [String] = [] + for pid in owners { + let app = AXUIElementCreateApplication(pid) + AXUIElementSetMessagingTimeout(app, messagingTimeout) + guard let windows = value(of: app, kAXWindowsAttribute) as? [AXUIElement] else { return nil } + for window in windows { + collectIdentifiers(of: window, depth: 0, into: &found) + } + } + return found + } + + // The panel's controls sit four levels below its window; deeper levels hold notification text. + private static func collectIdentifiers(of element: AXUIElement, depth: Int, into found: inout [String]) { + if let identifier = value(of: element, "AXIdentifier") as? String { + found.append(identifier) + } + guard depth < 5 else { return } + for child in children(of: element) { + collectIdentifiers(of: child, depth: depth + 1, into: &found) + } } private static func value(of element: AXUIElement, _ attribute: String) -> CFTypeRef? {