Skip to content

Commit 20c5762

Browse files
Fix Control Center item discovery and activation
1 parent 3dd9dca commit 20c5762

7 files changed

Lines changed: 64 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable user-visible changes to OverflowBar are documented here.
44

55
## [Unreleased]
66

7+
## [1.0.9] - 2026-08-03
8+
9+
- Normalize Control Center window identities so generic items such as Feishu remain selected and hidden across WindowServer refreshes.
10+
- Persist explicit deselections and detect newly-created menu-bar windows without requiring a restart.
11+
- Route fallback activation through the WindowServer session event tap for more reliable Control Center clicks.
12+
713
## [1.0.8] - 2026-08-03
814

915
### Fixed
@@ -76,7 +82,8 @@ All notable user-visible changes to OverflowBar are documented here.
7682

7783
- Initial public release with item discovery, selection, managed hiding, second-row presentation, and hybrid activation.
7884

79-
[Unreleased]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.8...HEAD
85+
[Unreleased]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.9...HEAD
86+
[1.0.9]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.8...v1.0.9
8087
[1.0.8]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.7...v1.0.8
8188
[1.0.7]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.6...v1.0.7
8289
[1.0.6]: https://github.com/EvanProgramming/OverflowBar/compare/v1.0.5...v1.0.6

‎OverflowBar/Resources/Info.plist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
88
<key>CFBundleName</key><string>$(PRODUCT_NAME)</string>
99
<key>CFBundlePackageType</key><string>APPL</string>
10-
<key>CFBundleShortVersionString</key><string>1.0.8</string>
10+
<key>CFBundleShortVersionString</key><string>1.0.9</string>
1111
<key>CFBundleVersion</key><string>9</string>
1212
<key>LSUIElement</key><true/>
1313
<key>LSApplicationCategoryType</key><string>public.app-category.utilities</string>

‎OverflowBar/Services/MenuBarItemActivator.swift‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ final class MenuBarItemActivator {
1313
let source = CGEventSource(stateID: .privateState),
1414
let down = targetedEvent(type: .leftMouseDown, item: item, windowID: windowID, pid: ownerPID, source: source),
1515
let up = targetedEvent(type: .leftMouseUp, item: item, windowID: windowID, pid: ownerPID, source: source) {
16-
down.postToPid(ownerPID)
16+
// Control Center owns most status-item windows on recent macOS,
17+
// but it does not consistently consume events posted directly to
18+
// its PID. A session-tap click follows the same WindowServer path
19+
// as a real menu-bar click while leaving the physical cursor put.
20+
down.post(tap: .cgSessionEventTap)
1721
DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) {
18-
up.postToPid(ownerPID)
22+
up.post(tap: .cgSessionEventTap)
1923
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { completion(true) }
2024
}
2125
return

‎OverflowBar/Services/MenuBarItemStore.swift‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ final class MenuBarItemStore: ObservableObject {
8686
item.windowID.map { ($0, item) }
8787
})
8888
let knownBefore = preferences.knownItemIDs
89+
let knownWindowIDsBefore = preferences.knownWindowIDs
90+
let deselectedBefore = preferences.deselectedItemIDs
8991
let selectedBefore = preferences.selectedIDs
9092
let scanned = scanner.scan(selectedIDs: selectedBefore)
9193
let currentIDs = Set(scanned.filter { !$0.isProtectedSystemItem }.map(\.id))
94+
let currentWindowIDs = Set(scanned.compactMap(\.windowID))
95+
let newWindowIDs = currentWindowIDs.subtracting(knownWindowIDsBefore)
9296

9397
for item in scanned {
9498
let previous = previousByID[item.id] ?? item.windowID.flatMap { previousByWindowID[$0] }
@@ -103,14 +107,21 @@ final class MenuBarItemStore: ObservableObject {
103107
layoutManagementEnabled = false
104108
} else if !knownBefore.isEmpty, layoutManagementEnabled {
105109
let newIDs = currentIDs.subtracting(knownBefore)
106-
for item in scanned where newIDs.contains(item.id) { item.isSelected = true }
107-
if !newIDs.isEmpty {
108-
logger.info("Discovered and selected \(newIDs.count, privacy: .public) new menu bar item(s)")
110+
let newWindowItems = scanned.filter { item in
111+
!item.isProtectedSystemItem && item.windowID.map(newWindowIDs.contains) == true &&
112+
!deselectedBefore.contains(item.id)
113+
}
114+
for item in scanned where newIDs.contains(item.id) || newWindowItems.contains(where: { $0.id == item.id }) {
115+
if !deselectedBefore.contains(item.id) { item.isSelected = true }
116+
}
117+
if !newIDs.isEmpty || !newWindowItems.isEmpty {
118+
logger.info("Discovered and selected \(max(newIDs.count, newWindowItems.count), privacy: .public) new menu bar item(s)")
109119
}
110120
}
111121

112122
items = scanned
113123
preferences.saveKnownItems(knownBefore.union(currentIDs))
124+
preferences.saveKnownWindowIDs(knownWindowIDsBefore.union(currentWindowIDs))
114125
let selectedNow = Set(scanned.filter(\.isSelected).map(\.id))
115126
preferences.saveSelected(selectedBefore.subtracting(currentIDs).union(selectedNow))
116127
lastWindowSignature = scanner.windowSignature()
@@ -159,6 +170,9 @@ final class MenuBarItemStore: ObservableObject {
159170
guard !item.isProtectedSystemItem else { return }
160171
item.isSelected = selected
161172
objectWillChange.send()
173+
var deselected = preferences.deselectedItemIDs
174+
if selected { deselected.remove(item.id) } else { deselected.insert(item.id) }
175+
preferences.saveDeselectedItems(deselected)
162176
let currentIDs = Set(items.map(\.id))
163177
let retainedMissing = preferences.selectedIDs.subtracting(currentIDs)
164178
preferences.saveSelected(retainedMissing.union(items.filter(\.isSelected).map(\.id)))
@@ -168,6 +182,11 @@ final class MenuBarItemStore: ObservableObject {
168182

169183
func selectAll(_ selected: Bool) {
170184
for item in items where !item.isProtectedSystemItem { item.isSelected = selected }
185+
if selected {
186+
preferences.saveDeselectedItems([])
187+
} else {
188+
preferences.saveDeselectedItems(Set(items.filter { !$0.isProtectedSystemItem }.map(\.id)))
189+
}
171190
preferences.saveSelected(Set(items.filter(\.isSelected).map(\.id)))
172191
objectWillChange.send()
173192
if selected { applyLayout() } else { restoreLayout() }

‎OverflowBar/Services/MenuBarScanner.swift‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ final class MenuBarScanner {
6767
guard !excludedTitles.contains(title) else { return nil }
6868
let owner = (window[kCGWindowOwnerName as String] as? String) ?? "System Menu Bar"
6969
let runningApp = NSRunningApplication(processIdentifier: pid_t(ownerPID))
70-
let ownerKey = runningApp?.bundleIdentifier ?? owner
70+
// macOS can report the same Control Center status item with either
71+
// the localized owner name or its bundle identifier. Keep one
72+
// stable key so selections survive WindowServer refreshes.
73+
let rawOwnerKey = runningApp?.bundleIdentifier ?? owner
74+
let ownerKey = rawOwnerKey == "com.apple.controlcenter" || owner == "Control Center"
75+
? "Control Center"
76+
: rawOwnerKey
7177
let frame = CGRect(x: bounds["X"] ?? 0, y: bounds["Y"] ?? 0, width: bounds["Width"] ?? 0, height: bounds["Height"] ?? 0)
7278
guard isMenuBarWindowFrame(frame), frame.width > 4, frame.height > 4, frame.height <= 40 else { return nil }
7379
return (identifier, ownerPID, title, owner, ownerKey, runningApp?.icon, frame)
@@ -82,8 +88,11 @@ final class MenuBarScanner {
8288
legacyOccurrences[candidate.title] = legacyOccurrence + 1
8389
let isProtected = protectedSystemTitles.contains(candidate.title)
8490
let id = isProtected ? "system|\(candidate.title)" : "window|\(candidate.ownerKey)|\(candidate.title)|\(occurrence)"
91+
let alternateOwnerKey = candidate.ownerKey == "Control Center" ? "com.apple.controlcenter" : candidate.ownerKey
92+
let alternateID = "window|\(alternateOwnerKey)|\(candidate.title)|\(occurrence)"
8593
let legacyID = "window|\(candidate.title)|\(legacyOccurrence)"
86-
return MenuBarItem(id: id, title: candidate.title == "Item-0" ? "Menu Bar Item" : candidate.title, ownerName: isProtected ? "System Menu Bar" : candidate.owner, bundleIdentifier: candidate.ownerKey, frame: candidate.frame, axElement: nil, applicationIcon: candidate.appIcon, isSelected: !isProtected && (selectedIDs.contains(id) || selectedIDs.contains(legacyID)), supportsPressAction: false, windowID: CGWindowID(candidate.identifier), ownerPID: pid_t(candidate.ownerPID), isProtectedSystemItem: isProtected)
94+
let isSelected = !isProtected && (selectedIDs.contains(id) || selectedIDs.contains(alternateID) || selectedIDs.contains(legacyID))
95+
return MenuBarItem(id: id, title: candidate.title == "Item-0" ? "Menu Bar Item" : candidate.title, ownerName: isProtected ? "System Menu Bar" : candidate.owner, bundleIdentifier: candidate.ownerKey, frame: candidate.frame, axElement: nil, applicationIcon: candidate.appIcon, isSelected: isSelected, supportsPressAction: false, windowID: CGWindowID(candidate.identifier), ownerPID: pid_t(candidate.ownerPID), isProtectedSystemItem: isProtected)
8796
}
8897
}
8998

‎OverflowBar/Services/PreferencesStore.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import Foundation
2+
import CoreGraphics
23

34
final class PreferencesStore {
45
private let selectedKeys = "selectedMenuBarItems"
56
private let knownItemsKey = "knownMenuBarItemsV1"
7+
private let knownWindowIDsKey = "knownMenuBarWindowIDsV1"
8+
private let deselectedItemsKey = "deselectedMenuBarItemsV1"
69
private let layoutManagementKey = "layoutManagementEnabled"
710
private let defaultLayoutKey = "didApplyDefaultLayoutV4"
811
// UserDefaults survives replacing the application bundle. Keep completion
@@ -20,6 +23,10 @@ final class PreferencesStore {
2023

2124
var selectedIDs: Set<String> { Set(defaults.stringArray(forKey: selectedKeys) ?? []) }
2225
var knownItemIDs: Set<String> { Set(defaults.stringArray(forKey: knownItemsKey) ?? []) }
26+
var knownWindowIDs: Set<CGWindowID> {
27+
Set((defaults.array(forKey: knownWindowIDsKey) as? [NSNumber] ?? []).map { CGWindowID($0.uint32Value) })
28+
}
29+
var deselectedItemIDs: Set<String> { Set(defaults.stringArray(forKey: deselectedItemsKey) ?? []) }
2330
var layoutManagementEnabled: Bool {
2431
get { defaults.bool(forKey: layoutManagementKey) }
2532
set { defaults.set(newValue, forKey: layoutManagementKey) }
@@ -35,4 +42,8 @@ final class PreferencesStore {
3542

3643
func saveSelected(_ ids: Set<String>) { defaults.set(Array(ids), forKey: selectedKeys) }
3744
func saveKnownItems(_ ids: Set<String>) { defaults.set(Array(ids), forKey: knownItemsKey) }
45+
func saveKnownWindowIDs(_ ids: Set<CGWindowID>) {
46+
defaults.set(ids.map { NSNumber(value: $0) }, forKey: knownWindowIDsKey)
47+
}
48+
func saveDeselectedItems(_ ids: Set<String>) { defaults.set(Array(ids), forKey: deselectedItemsKey) }
3849
}

‎RELEASE_NOTES.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# OverflowBar 1.0.8
1+
# OverflowBar 1.0.9
22

3-
OverflowBar 1.0.8 makes menu-bar discovery and activation substantially faster and more resilient.
3+
OverflowBar 1.0.9 makes menu-bar discovery and activation substantially faster and more resilient.
4+
5+
This release keeps Control Center-backed items (including Feishu's generic status item) stable across refreshes, automatically detects newly-created items, and uses a WindowServer session event for fallback activation.
46

57
## Fixed
68

@@ -11,7 +13,7 @@ OverflowBar 1.0.8 makes menu-bar discovery and activation substantially faster a
1113

1214
## Install
1315

14-
1. Download `OverflowBar-1.0.8.dmg`.
16+
1. Download `OverflowBar-1.0.9.dmg`.
1517
2. Open the disk image and drag OverflowBar to Applications.
1618
3. Replace an older copy when prompted.
1719

0 commit comments

Comments
 (0)