Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import AppKitimport Foundation
struct RealityDisplay: Codable, Sendable { let frame: ScreenRect let visible: ScreenRect}
@MainActorenum RealityDisplays { static func read() throws -> [RealityDisplay] { guard let primary = NSScreen.screens.first else { throw RealityError("No display is connected") } let height = primary.frame.maxY return NSScreen.screens.map { screen in RealityDisplay( frame: ScreenRect( x: screen.frame.minX, y: height - screen.frame.maxY, width: screen.frame.width, height: screen.frame.height), visible: ScreenRect( x: screen.visibleFrame.minX, y: height - screen.visibleFrame.maxY, width: screen.visibleFrame.width, height: screen.visibleFrame.height)) } }
static func primaryFrame() throws -> ScreenRect { guard let frame = try read().first?.frame else { throw RealityError("No primary display is connected") } return frame }
static func checkRoundTrip(_ session: RealitySession) async throws { let displays = try read() guard displays.count >= 2 else { throw RealitySkip("Only one physical display is connected") } let source = displays[0] let destination = displays[1] try encodeJSON(displays, to: session.directory.appendingPathComponent("physical-displays.json")) try session.configure() let owned = try await session.startingWindows([.textEdit, .textEdit]) try await session.start() try await session.tiles(owned) let before = try session.readFrames(owned) try await session.apps.focus(owned[0]) let direction = direction(from: source.frame, to: destination.frame) try await session.command("move-to-display", direction) try await session.expect("Moved document fills destination usable frame; remaining source document expands") { let frames = try FrameOracle.frames($0, ids: owned.map(\.id)) return frames[0].matches(destination.visible.inset(16)) && frames[1].matches(source.visible.inset(16)) } try await session.apps.focus(owned[0]) try await session.command("move-to-display", self.direction(from: destination.frame, to: source.frame)) try await session.tiles(owned) try await session.expect("Display round trip restores the source tile set") { FrameOracle.matchesUnordered(try FrameOracle.frames($0, ids: owned.map(\.id)), before) } }
nonisolated static func direction(from source: ScreenRect, to destination: ScreenRect) -> String { let dx = destination.x + destination.width / 2 - source.x - source.width / 2 let dy = destination.y + destination.height / 2 - source.y - source.height / 2 return abs(dx) >= abs(dy) ? (dx >= 0 ? "right" : "left") : (dy >= 0 ? "down" : "up") }}