Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import Foundationimport ParcelPlatformimport RealityDriverSupport
@MainActorfunc checkShortcutsOff(_ session: RealitySession) async throws { try requireUncontestedDefaultShortcuts(voiceOverEnabled: VoiceOverStatus.isRunning) try session.configure(shortcutsEnabled: false) var owned = try await session.startingWindows([.fixture, .fixture]) try await session.apps.focus(owned[0]) let nativeBaseline = try session.readFrames(owned) let commands = [ RealityInputDefaults.rows, RealityInputDefaults.swapRight, RealityInputDefaults.float, RealityInputDefaults.binding(.toggleAutomaticTiling), ]
func proveDisabled(stage: String, baseline: [ScreenRect]) async throws { let fixture = try session.apps.fixture(for: owned[0]) for command in commands { try requireUncontestedDefaultShortcuts(voiceOverEnabled: VoiceOverStatus.isRunning) _ = try await fixture.control("input-record-start") let response: DriverResponse do { response = try await session.driver.send( .key( virtualKey: command.virtualKey, flags: command.flags.rawValue, expectation: .fixturePassThrough) ) } catch let error as RealityFixturePassThroughInterception { guard stage == "before-parcel", session.parcel == nil else { throw error } try encodeJSON( [ "requirement": "default-shortcut-delivery", "command": command.name, "virtualKey": String(command.virtualKey), "flags": String(command.flags.rawValue), "proof": error.description, "parcelStarted": "false", ], to: session.directory.appendingPathComponent("unsupported-host-requirement.json")) throw RealityUnsupportedHostRequirement( requirement: .defaultShortcutDelivery, detail: "\(command.name) lacks exact owned FixtureApp key delivery before Parcel starts; native interception evidence retained" ) } try requireFixturePassThrough(response, window: owned[0], virtualKey: command.virtualKey) var native = try await fixture.control("snapshot") let deadline = ContinuousClock.now.advanced(by: .seconds(3)) while try !native.received(command.virtualKey, windowID: owned[0].id), ContinuousClock.now < deadline { try await Task.sleep(for: .milliseconds(30)) native = try await fixture.control("snapshot") } try encodeJSON( native, to: session.directory.appendingPathComponent("shortcuts-off-\(stage)-\(command.name).json")) guard try native.received(command.virtualKey, windowID: owned[0].id) else { throw RealityError("Shortcuts off lacked native owned fixture key-down/up receipts") } try await requireCoverageFramesStay( session, owned: owned, baseline: baseline, evidence: "shortcuts-off-\(stage)-\(command.name)-frames") } }
do { try await proveDisabled(stage: "before-parcel", baseline: nativeBaseline) } catch let error as RealityUnsupportedHostRequirement { throw error } catch { throw RealityError( "Owned default-chord pass-through prerequisite failed before Parcel started; upstream native routing, not a product shortcut failure: \(error)" ) } try await session.start() try await session.tiles(owned) owned = zip(owned, try session.readFrames(owned)).sorted { $0.1.x < $1.1.x }.map(\.0) try await session.apps.focus(owned[0]) let before = try session.readFrames(owned) try await proveDisabled(stage: "startup", baseline: before) try session.configure(shortcutsEnabled: true) try await reloadCoverageConfiguration(session) try await session.driver.key(RealityInputDefaults.swapRight) try await session.expect( "Enabling shortcuts through config reload registers swap and exchanges the real fixture frames" ) { let frames = try FrameOracle.frames($0, ids: owned.map(\.id)) return frames[0].matches(before[1]) && frames[1].matches(before[0]) } let swapped = try session.readFrames(owned) try session.configure(shortcutsEnabled: false) try await reloadCoverageConfiguration(session) try await proveDisabled(stage: "reload", baseline: swapped) try await session.command("layout", "rows") try await session.expect("Shortcuts off leaves explicit CLI commands available to move real windows") { FrameOracle.stripeShape( try FrameOracle.frames($0, ids: owned.map(\.id)), visible: session.visible, vertical: false) }}
func requireFixturePassThrough(_ response: DriverResponse, window: OwnedWindow, virtualKey: UInt16) throws { guard response.error == nil, let receipts = response.input, receipts.count == 1, let receipt = receipts.first, receipt.virtualKey == virtualKey, receipt.delivery == .fixture, receipt.target.pid == window.pid, receipt.target.windowID == window.id, receipt.target.fixture, !receipt.target.panel else { throw RealityError("Safety stop: shortcuts off lacks an exact owned fixture pass-through receipt") }}
@MainActorfunc reloadCoverageConfiguration(_ session: RealitySession) async throws { let result = try await session.cli(["reload", "--json"]) guard result.status == 0 else { throw RealityError("Isolated coverage config reload failed: \(result.errors)") } let queried = try await session.cli(["query", "--json", "config"]) guard queried.status == 0 else { throw RealityError("Coverage runtime query failed: \(queried.errors)") } let runtime = try JSONDecoder().decode(ActivityRuntimeReceipt.self, from: Data(queried.output.utf8)) try runtime.requireStarted(config: session.config)}