From 8d795d0a287e53153290b83a46ece0096f3194e7 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 27 Sep 2026 10:30:20 +0800 Subject: [PATCH] Give up focus when opening a tray menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closing the panel was not enough: SimpleTopBar stayed frontmost, so Spotlight's search field never appeared. Deactivate the app when a tray item is selected so transient panels can take focus, and allow a little more time before the bar re-hides. 💘 Generated with Crush Assisted-by: Crush:deepseek-v4.1-flash --- AGENTS.md | 4 ++-- Sources/SimpleTopBar/App.swift | 9 +++++++-- Sources/SimpleTopBar/MenuBarItems.swift | 6 +++--- build-app.sh | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8ae0baf..ad57dc3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -142,8 +142,8 @@ preferred position controls where the hidden/kept boundary lands: menu is its own window anchored at the item's on-screen spot, so it survives re-hiding. - `press` first calls `onWillPress`, which `AppDelegate` wires to close the - popover. Without it the panel stays open on top of the menu that opens and can - leave menus (e.g. Spotlight) stranded behind it. + popover **and** `NSApp.deactivate()`. Closing alone left our app frontmost, so + transient items (Spotlight's search field) still would not appear. - **Cannot reveal a single icon.** The spacer hides a contiguous block to its left, so a press can only reveal the whole block. Isolating one item would need either per-item ordering control (not available) or covering the icons diff --git a/Sources/SimpleTopBar/App.swift b/Sources/SimpleTopBar/App.swift index 97a5f50..bc9bc82 100644 --- a/Sources/SimpleTopBar/App.swift +++ b/Sources/SimpleTopBar/App.swift @@ -133,11 +133,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate { ) self.popover = popover - // Selecting a tray item must dismiss our panel, otherwise it stays on - // top of the menu that opens (and can strand menus behind it). + // Selecting a tray item must dismiss our panel and give up focus, + // otherwise the panel stays on top of the menu and our app stays + // frontmost, which stops transient items (Spotlight's search field) + // from appearing at all. Task { @MainActor [weak self] in MenuBarItemManager.shared.onWillPress = { self?.popover?.performClose(nil) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { + NSApp.deactivate() + } } } } diff --git a/Sources/SimpleTopBar/MenuBarItems.swift b/Sources/SimpleTopBar/MenuBarItems.swift index 8ba4450..de7f7b6 100644 --- a/Sources/SimpleTopBar/MenuBarItems.swift +++ b/Sources/SimpleTopBar/MenuBarItems.swift @@ -127,11 +127,11 @@ final class MenuBarItemManager: ObservableObject { return } hider.suspend() - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { _ = self.performPress(item) // The menu is its own window, positioned at the item's on-screen - // spot, so the bar can be re-hidden almost immediately. - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + // spot, so the bar can be re-hidden shortly after. + DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { hider.resume() } } diff --git a/build-app.sh b/build-app.sh index 82a81a9..28f2c52 100755 --- a/build-app.sh +++ b/build-app.sh @@ -2,7 +2,7 @@ set -euo pipefail cd "$(dirname "$0")" -VERSION="${1:-0.4.3}" +VERSION="${1:-0.4.4}" swift build -c release