import AppKit // StripPositioner finds the Dock screen and computes the strip frame. // See spec section 7.8. The core math takes plain values so a unit test can // check the logic without a real screen. enum StripPositioner { // ScreenFrames holds the two frames of one screen. struct ScreenFrames: Equatable { let frame: CGRect let visibleFrame: CGRect } // dockScreenIndex returns the index of the Dock screen. The Dock screen has // a visibleFrame.minY above the frame.minY. macOS reserves this space for // the Dock at the bottom. If no screen matches, the function returns the // main index. static func dockScreenIndex(screens: [ScreenFrames], mainIndex: Int) -> Int { for (index, screen) in screens.enumerated() { if screen.visibleFrame.minY > screen.frame.minY { return index } } return mainIndex } // stripFrame returns the strip frame for a visible frame and a height. // The strip sits at the bottom of the visible frame, full width. static func stripFrame(visibleFrame: CGRect, height: CGFloat) -> CGRect { return CGRect(x: visibleFrame.minX, y: visibleFrame.minY, width: visibleFrame.width, height: height) } // dockScreen returns the Dock NSScreen. The function uses the same rule as // dockScreenIndex. If no screen matches, the function returns the main // screen, or the first screen. static func dockScreen(_ screens: [NSScreen], main: NSScreen?) -> NSScreen? { for screen in screens { if screen.visibleFrame.minY > screen.frame.minY { return screen } } return main ?? screens.first } // stripFrame returns the strip frame for an NSScreen and a height. static func stripFrame(for screen: NSScreen, height: CGFloat) -> NSRect { return stripFrame(visibleFrame: screen.visibleFrame, height: height) } }