Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import ParcelCoreimport Testing
@testable import ParcelEngine
@MainActorstruct PausedCommandTests { @Test func pausedRetileRevalidatesFramesWhenThePlatformNotificationWasMissed() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) try harness.finishMotion() let before = harness.world.frames harness.engine.setAutomaticTilingEnabled(false) harness.world.frames[WindowID(rawValue: 1)] = Rect(x: 100, y: 120, width: 400, height: 500) harness.engine.send(.commandIssued(.retile)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.frames == before) #expect(!harness.engine.isAutomaticTilingEnabled) await harness.engine.stop() }
@Test func retileRepairsObservedFramesWithoutResumingAutomaticTiling() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2, 3]) try harness.finishMotion() let balanced: [WindowID: Rect] = [ WindowID(rawValue: 1): Rect(x: 0, y: 0, width: 400, height: 800), WindowID(rawValue: 2): Rect(x: 400, y: 0, width: 400, height: 800), WindowID(rawValue: 3): Rect(x: 800, y: 0, width: 400, height: 800), ] let first = WindowID(rawValue: 1) harness.engine.setAutomaticTilingEnabled(false) let displaced = Rect(x: 70, y: 80, width: 300, height: 400) harness.world.userFrame(first, frame: displaced) try harness.scheduler.runReady() #expect(harness.world.frames[first] == displaced) harness.engine.send(.commandIssued(.retile)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.frames == balanced) #expect(!harness.engine.isAutomaticTilingEnabled) #expect(harness.engine.manualCommandFrames.isEmpty) let writes = harness.world.allWrites.count harness.world.userFrame(first, frame: displaced) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.allWrites.count == writes) #expect(harness.world.frames[first] == displaced) await harness.engine.stop() }
@Test func pausedLayoutCommandWritesOnlyItsWorkspace() async throws { let harness = try EngineHarness(initialState: engineInitialState(twoDisplays: true)) try await harness.start() try harness.add([1, 2]) let other = WorkspaceKey(display: secondEngineDisplay, space: SpaceID(rawValue: 2)) try harness.add([3], app: secondEngineApp, workspace: other) try harness.finishMotion() harness.engine.setAutomaticTilingEnabled(false) let displaced = Rect(x: 1300, y: 100, width: 300, height: 400) harness.world.userFrame(WindowID(rawValue: 3), frame: displaced) try harness.scheduler.runReady() harness.engine.send(.workspaceCommandIssued(.setLayout(.rows), workspace: engineWorkspace)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.frames[WindowID(rawValue: 3)] == displaced) #expect(harness.world.frames[WindowID(rawValue: 1)] == Rect(x: 0, y: 0, width: 1200, height: 400)) #expect(!harness.engine.isAutomaticTilingEnabled) await harness.engine.stop() }
@Test func automaticAppearanceCannotRetargetAPendingPausedCommand() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) try harness.finishMotion() harness.engine.setAutomaticTilingEnabled(false) harness.world.deferWrites = true harness.engine.send(.commandIssued(.setLayout(.rows))) try harness.scheduler.runReady() let commanded = harness.engine.snapshot.state.frames harness.world.appear(engineWindow(3)) try harness.scheduler.runReady() while harness.world.pendingWriteCount > 0 { try harness.world.completeNextWrite() try harness.finishMotion() } #expect(harness.world.frames[WindowID(rawValue: 1)] == commanded[WindowID(rawValue: 1)]) #expect(harness.world.frames[WindowID(rawValue: 2)] == commanded[WindowID(rawValue: 2)]) #expect(harness.world.writes(for: WindowID(rawValue: 3)).isEmpty) #expect(!harness.engine.isAutomaticTilingEnabled) await harness.engine.stop() }
@Test func stoppingDiscardsPendingExplicitWritePermission() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) try harness.finishMotion() harness.engine.setAutomaticTilingEnabled(false) harness.world.deferWrites = true harness.engine.send(.commandIssued(.setLayout(.rows))) try harness.scheduler.runReady() #expect(!harness.engine.manualCommandFrames.isEmpty) await harness.engine.stop() #expect(harness.engine.manualCommandFrames.isEmpty) }
@Test func focusCommandDoesNotRepairUnrelatedPausedFrames() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) try harness.finishMotion() harness.engine.setAutomaticTilingEnabled(false) let displaced = Rect(x: 70, y: 80, width: 300, height: 400) harness.world.userFrame(WindowID(rawValue: 1), frame: displaced) try harness.scheduler.runReady() let count = harness.world.allWrites.count harness.engine.send(.commandIssued(.focusNextWindow)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.allWrites.count == count) #expect(harness.world.frames[WindowID(rawValue: 1)] == displaced) #expect(harness.engine.manualCommandFrames.isEmpty) await harness.engine.stop() }}