| | |
| | | appCountsBySpace: [UInt64: Int], |
| | | appNamesBySpace: [UInt64: [String]] |
| | | ) -> [QuickSwitchDisplayViewModel] { |
| | | displays |
| | | let sortedDisplays = displays |
| | | .sorted { $0.uuid.localizedStandardCompare($1.uuid) == .orderedAscending } |
| | | let displayCount = sortedDisplays.count |
| | | |
| | | return sortedDisplays |
| | | .enumerated() |
| | | .map { displayIndex, display in |
| | | let displayLabel = displayLabel(for: displayIndex) |
| | |
| | | id: space.id, |
| | | displayUUID: space.displayUUID, |
| | | index: space.index, |
| | | label: "\(displayLabel)\(space.index)", |
| | | label: spaceLabel(for: space, displayIndex: displayIndex, displayCount: displayCount), |
| | | type: space.type, |
| | | isCurrent: currentSpaceIDs.contains(space.id), |
| | | windowCount: windowCountsBySpace[space.id] ?? 0, |
| | |
| | | |
| | | private static func labelsBySpaceID(from displays: [AlignerDisplay]) -> [UInt64: String] { |
| | | var labels: [UInt64: String] = [:] |
| | | |
| | | for (displayIndex, display) in displays |
| | | let sortedDisplays = displays |
| | | .sorted(by: { $0.uuid.localizedStandardCompare($1.uuid) == .orderedAscending }) |
| | | .enumerated() |
| | | { |
| | | let displayLabel = displayLabel(for: displayIndex) |
| | | let displayCount = sortedDisplays.count |
| | | |
| | | for (displayIndex, display) in sortedDisplays.enumerated() { |
| | | for space in display.spaces { |
| | | labels[space.id] = "\(displayLabel)\(space.index)" |
| | | labels[space.id] = spaceLabel(for: space, displayIndex: displayIndex, displayCount: displayCount) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return String(String.UnicodeScalarView(scalars)) |
| | | } |
| | | |
| | | private static func spaceLabel(for space: AlignerSpace, displayIndex: Int, displayCount: Int) -> String { |
| | | if displayCount <= 1 { |
| | | return String(format: "%02d", space.index) |
| | | } |
| | | |
| | | return "\(displayLabel(for: displayIndex))\(space.index)" |
| | | } |
| | | } |