Skip to content

Commit

Permalink
Revert "Update menu bar item getters"
Browse files Browse the repository at this point in the history
This reverts commit 9c01743.
  • Loading branch information
jordanbaird committed Jul 22, 2024
1 parent f36177d commit 8743c62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Ice/Events/EventManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ extension EventManager {
else {
return false
}
let menuBarItems = MenuBarItem.getMenuBarItems(on: screen.displayID, using: .privateAPI, onScreenOnly: true)
let menuBarItems = MenuBarItem.getMenuBarItemsPrivateAPI(for: screen.displayID, onScreenOnly: true)
return menuBarItems.contains { $0.frame.contains(mouseLocation) }
}

Expand Down
32 changes: 9 additions & 23 deletions Ice/MenuBar/MenuBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,8 @@ struct MenuBarItem {

// MARK: MenuBarItem Getters
extension MenuBarItem {
/// The method to use to get the menu bar items.
enum GetterMethod {
case coreGraphics
case privateAPI
}

private static func getMenuBarItemsCoreGraphics(on display: CGDirectDisplayID, onScreenOnly: Bool) -> [MenuBarItem] {
/// Returns an array of menu bar items in the menu bar for the given display.
static func getMenuBarItemsCoreGraphics(for display: CGDirectDisplayID, onScreenOnly: Bool) -> [MenuBarItem] {
let windows = if onScreenOnly {
WindowInfo.getOnScreenWindows(excludeDesktopWindows: true)
} else {
Expand All @@ -193,7 +188,12 @@ extension MenuBarItem {
.sortedByOrderInMenuBar()
}

private static func getMenuBarItemsPrivateAPI(on display: CGDirectDisplayID, onScreenOnly: Bool) -> [MenuBarItem] {
/// Returns an array of menu bar items using private APIs to retrieve the
/// windows.
///
/// - Parameter onScreenOnly: A Boolean value that indicates whether only
/// the items that are on screen should be returned.
static func getMenuBarItemsPrivateAPI(for display: CGDirectDisplayID, onScreenOnly: Bool) -> [MenuBarItem] {
var option: Bridging.WindowListOption = [.menuBarItems]
if onScreenOnly {
option.insert(.onScreen)
Expand All @@ -212,21 +212,7 @@ extension MenuBarItem {
.sortedByOrderInMenuBar()
}

/// Returns an array of menu bar items in the menu bar on the given display.
///
/// - Parameters:
/// - display: The display to retrieve the menu bar items on.
/// - method: The method to use to get the items.
/// - onScreenOnly: A Boolean value that indicates whether only the items
/// that are on screen should be returned.
static func getMenuBarItems(on display: CGDirectDisplayID, using method: GetterMethod, onScreenOnly: Bool) -> [MenuBarItem] {
switch method {
case .coreGraphics: getMenuBarItemsCoreGraphics(on: display, onScreenOnly: onScreenOnly)
case .privateAPI: getMenuBarItemsPrivateAPI(on: display, onScreenOnly: onScreenOnly)
}
}

/// Returns an array of menu bar items using a private API to retrieve
/// Returns an array of menu bar items using private APIs to retrieve
/// the windows.
///
/// - Parameters:
Expand Down
2 changes: 1 addition & 1 deletion Ice/MenuBar/MenuBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ final class MenuBarManager: ObservableObject {
return
}

let items = MenuBarItem.getMenuBarItems(on: displayID, using: .coreGraphics, onScreenOnly: true)
let items = MenuBarItem.getMenuBarItemsCoreGraphics(for: displayID, onScreenOnly: true)

// get the leftmost item on the screen; the application menu should
// be hidden if the item's minX is close to the maxX of the menu
Expand Down
2 changes: 1 addition & 1 deletion Ice/MenuBarAppearance/MenuBarOverlayPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private class MenuBarOverlayPanelContentView: NSView {
return CGRect(x: rect.minX, y: rect.minY, width: maxX, height: rect.height)
}()
let trailingPathBounds: CGRect = {
let items = MenuBarItem.getMenuBarItems(on: screen.displayID, using: .privateAPI, onScreenOnly: true)
let items = MenuBarItem.getMenuBarItemsPrivateAPI(for: screen.displayID, onScreenOnly: true)
guard !items.isEmpty else {
return .zero
}
Expand Down

0 comments on commit 8743c62

Please sign in to comment.