Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import Foundationimport ParcelCore
struct StackGrip: Equatable, Sendable { let windows: [WindowID] let visible: WindowID let frame: CGRect let chips: [StackChip] let active: Bool let countFrame: CGRect var accessibilityLabel: String { StackText.stackedWindows(windows.count) }
static func observedGeometry(in state: State) -> State { var presentation = state presentation.frames = state.observedFrames return presentation }
static func groups(in state: State) -> [Self] { let presentation = observedGeometry(in: state) return StackChips.groups(in: presentation, compact: true).compactMap { group in guard state.visibleWindows.contains(group.visible), group.windows.allSatisfy({ state.observedFrames[$0] != nil }), let tile = state.observedFrames[group.visible]?.learningRect else { return nil } let countWidth = StackChips.countWidth(for: group.windows.count) let width = min(group.frame.width, Double(group.windows.count) * 22 + countWidth) let cell = (width - countWidth) / Double(group.windows.count) guard cell >= 12 else { return nil } let above = CGRect( x: tile.midX - width / 2, y: tile.minY - group.frame.height, width: width, height: group.frame.height) let display = state.workspace(containing: group.visible).flatMap { state.displays[$0.display]?.frame.learningRect } let aboveIsClear = display?.contains(above) == true && !state.visibleWindows.contains { state.observedFrames[$0]?.learningRect.intersects(above) == true } let frame = aboveIsClear ? above : CGRect( x: tile.midX - width / 2, y: group.frame.minY, width: width, height: group.frame.height) // The compact rail must remain clear even when its chip row fits elsewhere in the gap. guard !state.visibleWindows.contains(where: { state.observedFrames[$0]?.learningRect.intersects(frame) == true }) else { return nil } let active = state.focusedWindow.map(group.windows.contains) ?? false let chips = group.chips.enumerated().map { index, chip in let x = Double(index) * cell let segmentWidth = active ? (chip.selected ? min(cell - 4, 18) : min(cell - 6, 8)) : 6.0 let height = active ? 4.0 : 6.0 return StackChip( window: chip.window, title: chip.title, selected: chip.selected, frame: CGRect(x: x, y: 0, width: cell, height: frame.height), index: index, count: group.windows.count, indicatorFrame: CGRect( x: x + (cell - segmentWidth) / 2, y: (frame.height - height) / 2, width: segmentWidth, height: height), active: active) } return Self( windows: group.windows, visible: group.visible, frame: frame, chips: chips, active: active, countFrame: CGRect(x: width - countWidth, y: 0, width: countWidth, height: frame.height)) } }}