Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import Foundation
struct SettingsColumnLimit: Codable, Sendable { let window: UInt32 let requested: ScreenRect let first: ScreenRect let second: ScreenRect
func clipping(_ slot: ScreenRect) -> ScreenRect { ScreenRect( x: slot.x, y: slot.y, width: min(slot.width, second.width), height: min(slot.height, second.height)) }}
@MainActorfunc measureSettingsColumnLimits(_ session: RealitySession, owned: [OwnedWindow]) async throws -> [SettingsColumnLimit]{ let requested = session.visible.inset(try session.configuredLayout().gaps.outer) let original = try session.readFrames(owned) var limits: [SettingsColumnLimit] = [] for (window, frame) in zip(owned, original) { do { try await session.apps.arrange(window, frame: requested, exactSize: false) let first = try session.readFrames([window])[0] try await session.apps.arrange(window, frame: requested, exactSize: false) let second = try session.readFrames([window])[0] guard first.matches(second, tolerance: 1), requested.contains(second, tolerance: 1), abs(second.x - requested.x) <= 1, abs(second.y - requested.y) <= 1 else { throw RealityError("Owned app did not expose stable native growth bounds before tiling") } limits.append(SettingsColumnLimit(window: window.id, requested: requested, first: first, second: second)) try await session.apps.arrange(window, frame: frame, exactSize: false) } catch let failure { do { try await session.apps.arrange(window, frame: frame, exactSize: false) } catch { throw RealityError("\(failure); native growth probe restoration failed: \(error)") } throw failure } } try encodeJSON(limits, to: session.directory.appendingPathComponent("settings-native-growth-bounds.json")) return limits}
@MainActorfunc expectSettingsColumns( _ session: RealitySession, owned: [OwnedWindow], limits: [SettingsColumnLimit]) async throws { guard owned.count == 2, limits.map(\.window) == owned.map(\.id) else { throw RealityError("Settings column evidence must cover both owned windows") } let gaps = try session.configuredLayout().gaps let slots = FrameOracle.stripes(count: 2, visible: session.visible, vertical: true, gaps: gaps) try encodeJSON(slots, to: session.directory.appendingPathComponent("settings-independent-column-slots.json")) try await session.expect("Two native windows fill equal column slots up to their independently measured maxima") { let frames = try FrameOracle.frames($0, ids: owned.map(\.id)) var remaining = Set(slots.indices) for (frame, limit) in zip(frames, limits) { guard let index = remaining.first(where: { frame.matches(limit.clipping(slots[$0]), tolerance: 1) }), slots[index].contains(frame, tolerance: 1) else { return false } remaining.remove(index) } return remaining.isEmpty && frames[0].separated(from: frames[1], gap: gaps.inner, tolerance: 1) }}