Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162public import AppKitpublic import ParcelCore
public enum DisplayNaming { public struct Screen: Equatable, Sendable { public let id: DisplayID public let frame: CGRect public let name: String
public init(id: DisplayID, frame: CGRect, name: String) { self.id = id self.frame = frame self.name = name } }
public enum Failure: LocalizedError { case missingIdentity
public var errorDescription: String? { MenuText.text("A connected display could not be identified. Reconnect it and reopen the menu.") } }
@MainActor public static func id(for screen: NSScreen) throws -> DisplayID { guard let number = screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? NSNumber, let uuid = CGDisplayCreateUUIDFromDisplayID(number.uint32Value)?.takeRetainedValue(), let text = CFUUIDCreateString(nil, uuid) else { throw Failure.missingIdentity } return DisplayID(rawValue: text as String) }
@MainActor public static func screens() throws -> [Screen] { try NSScreen.screens.map { Screen(id: try id(for: $0), frame: $0.frame, name: $0.localizedName) } }
@MainActor public static func name(for display: DisplayID, in state: State) throws -> String { name(for: display, screens: try screens(), state: state) }
public static func name(for display: DisplayID, screens: [Screen], state: State) -> String { if let name = screens.first(where: { $0.id == display })?.name, !name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { return name } let ordered = state.displays.values.sorted { if $0.frame.minX != $1.frame.minX { return $0.frame.minX < $1.frame.minX } if $0.frame.minY != $1.frame.minY { return $0.frame.minY < $1.frame.minY } return $0.id < $1.id } let number = ordered.firstIndex(where: { $0.id == display }).map { $0 + 1 } ?? screens.firstIndex(where: { $0.id == display }).map { $0 + 1 } guard let number else { return MenuText.text("Display unavailable") } return String(format: MenuText.text("Display %lld"), locale: .current, Int64(number)) }}